Mail Archives: djgpp-workers/2002/02/19/23:45:39
> If sbrk alignment is controlled malloc alignment is controlled.
> Pick a size.
sbrk() alignment is NOT controlled - it is up to malloc to to do
the alignment. Alignment should be on an 8 byte boundary to
maximize performance with floating point arrays. The overhead per
block must be a multiple of 8 bytes (at a minimum) to keep the
blocks aligned. Larger alignments might add value but not proven.
Two potential patches vs 2.03 (not yet committed to CVS):
First version (probably faster but bigger, extra code only if new
sbrk is not aligned, the reactive patch):
*** malloc.c_ Wed Dec 5 14:52:52 2001
--- malloc.c Mon Feb 11 22:22:32 2002
*************** malloc(size_t size)
*** 208,215 ****
--- 208,222 ----
rv = (BLOCK *)((char *)rv - 4);
}
else
{
+ int align_bytes = (int)rv & (ALIGN-1);
+ if(align_bytes)
+ {
+ align_bytes = ALIGN - align_bytes;
+ if(sbrk(align_bytes) == (void *)((char *)rv + chunk_size) )
+ rv = (BLOCK *)((char *)rv + align_bytes);
+ }
expected_sbrk = (BLOCK *)((char *)rv + chunk_size);
#if DEBUG
printf(" disconnected sbrk\n");
#endif
Second version (slower - extra sbrk and brk called for each sbrk but only
execute about 20 assembly lines, smaller code, the proactive patch):
*** malloc.c_ Wed Dec 5 14:52:52 2001
--- malloc.c Tue Feb 12 10:52:20 2002
*************** malloc(size_t size)
*** 192,195 ****
--- 192,196 ----
}
+ brk((void *)( ((int)sbrk(0)+(ALIGN-1)) & ~(ALIGN-1) )); /* Align next sbrk */
chunk_size = size+16; /* two ends plus two placeholders */
rv = (BLOCK *)sbrk(chunk_size);
I posted both; little feedback on which should be committed. But it's
important that the block overhead be a factor of the alignment or you
will almost never merge blocks.
- Raw text -