summaryrefslogtreecommitdiff
path: root/src/malloc
AgeCommit message (Collapse)AuthorFilesLines
2012-04-24ditch the priority inheritance locks; use malloc's version of lockRich Felker1-4/+4
i did some testing trying to switch malloc to use the new internal lock with priority inheritance, and my malloc contention test got 20-100 times slower. if priority inheritance futexes are this slow, it's simply too high a price to pay for avoiding priority inversion. maybe we can consider them somewhere down the road once the kernel folks get their act together on this (and perferably don't link it to glibc's inefficient lock API)... as such, i've switch __lock to use malloc's implementation of lightweight locks, and updated all the users of the code to use an array with a waiter count for their locks. this should give optimal performance in the vast majority of cases, and it's simple. malloc is still using its own internal copy of the lock code because it seems to yield measurably better performance with -O3 when it's inlined (20% or more difference in the contention stress test).
2011-11-16fix issue with excessive mremap syscalls on reallocRich Felker1-4/+2
CHUNK_SIZE macro was defined incorrectly and shaving off at least one significant bit in the size of mmapped chunks, resulting in the test for oldlen==newlen always failing and incurring a syscall. fortunately i don't think this issue caused any other observable behavior; the definition worked correctly for all non-mmapped chunks where its correctness matters more, since their lengths are always multiples of the alignment.
2011-08-23use new a_crash() asm to optimize double-free handler.Rich Felker1-2/+2
gcc generates extremely bad code (7 byte immediate mov) for the old null pointer write approach. it should be generating something like "xor %eax,%eax ; mov %al,(%eax)". in any case, using a dedicated crashing opcode accomplishes the same thing in one byte.
2011-08-15simplify and improve double-free checkRich Felker1-2/+2
a valid mmapped block will have an even (actually aligned) "extra" field, whereas a freed chunk on the heap will always have an in-use neighbor. this fixes a potential bug if mmap ever allocated memory below the main program/brk (in which case it would be wrongly-detected as a double-free by the old code) and allows the double-free check to work for donated memory outside of the brk area (or, in the future, secondary heap zones if support for their creation is added).
2011-06-29posix_memalign should fail if size is not a multiple of sizeof(void *)Rich Felker1-1/+1
2011-06-26eliminate OOB array hacks in mallocRich Felker1-46/+45
2011-06-12malloc: cast size down to int in bin_index functionsRich Felker1-2/+2
even if size_t was 32-bit already, the fact that the value was unsigned and that gcc is too stupid to figure out it would be positive as a signed quantity (due to the immediately-prior arithmetic and conditionals) results in gcc compiling the integer-to-float conversion as zero extension to 64 bits followed by an "fildll" (64 bit) instruction rather than a simple "fildl" (32 bit) instruction on x86. reportedly fildll is very slow on certain p4-class machines; even if not, the new code is slightly smaller.
2011-06-06use volatile pointers for intentional-crash code.Rich Felker1-2/+2
2011-04-20namespace fixes for sys/mman.hRich Felker1-0/+1
2011-04-04fix rare but nasty under-allocation bug in malloc with large requestsRich Felker1-1/+1
the bug appeared only with requests roughly 2*sizeof(size_t) to 4*sizeof(size_t) bytes smaller than a multiple of the page size, and only for requests large enough to be serviced by mmap instead of the normal heap. it was only ever observed on 64-bit machines but presumably could also affect 32-bit (albeit with a smaller window of opportunity).
2011-04-01avoid over-allocation of brk on first mallocRich Felker1-4/+4
if init_malloc returns positive (successful first init), malloc will retry getting a chunk from the free bins rather than expanding the heap again. also pass init_malloc a hint for the size of the initial allocation.
2011-03-30rename __simple_malloc.c to lite_malloc.c - yes this affects behavior!Rich Felker1-0/+0
why does this affect behavior? well, the linker seems to traverse archive files starting from its current position when resolving symbols. since calloc.c comes alphabetically (and thus in sequence in the archive file) between __simple_malloc.c and malloc.c, attempts to resolve the "malloc" symbol for use by calloc.c were pulling in the full malloc.c implementation rather than the __simple_malloc.c implementation. as of now, lite_malloc.c and malloc.c are adjacent in the archive and in the correct order, so malloc.c should never be used to resolve "malloc" unless it's already needed to resolve another symbol ("free" or "realloc").
2011-03-23very cheap double-free checks in mallocRich Felker1-0/+4
2011-03-20global cleanup to use the new syscall interfaceRich Felker1-1/+1
2011-02-20make malloc(0) return unique pointers rather than NULLRich Felker2-6/+10
this change is made with some reluctance, but i think it's for the best. correct programs must handle either behavior, so there is little advantage to having malloc(0) return NULL. and i managed to actually make the malloc code slightly smaller with this change.
2011-02-20fix simple_malloc malloc(0) behavior not to return non-unique pointersRich Felker1-0/+1
2011-02-20fix simple_malloc size restrictionsRich Felker1-5/+6
do not allow allocations that overflow ptrdiff_t; fix some overflow checks that were not quite right but didn't matter due to address layout implementation.
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker7-0/+671