summaryrefslogtreecommitdiffstats
path: root/src/jemalloc.c
Commit message (Collapse)AuthorAgeFilesLines
* Use arena dss prec instead of default for huge allocs.Max Wang2014-03-281-1/+1
| | | | | Pass a dss_prec_t parameter to huge_{m,p,r}alloc instead of defaulting to the chunk dss prec.
* Fix unused variable warnings.Jason Evans2014-01-211-4/+2
|
* Extract profiling code from [re]allocation functions.Jason Evans2014-01-121-354/+449
| | | | | | | | | | | | | | | | | | | Extract profiling code from malloc(), imemalign(), calloc(), realloc(), mallocx(), rallocx(), and xallocx(). This slightly reduces the amount of code compiled into the fast paths, but the primary benefit is the combinatorial complexity reduction. Simplify iralloc[t]() by creating a separate ixalloc() that handles the no-move cases. Further simplify [mrxn]allocx() (and by implication [mrn]allocm()) to make request size overflows due to size class and/or alignment constraints trigger undefined behavior (detected by debug-only assertions). Report ENOMEM rather than EINVAL if an OOM occurs during heap profiling backtrace creation in imemalign(). This bug impacted posix_memalign() and aligned_alloc().
* Fix an uninitialized variable read in xallocx().Jason Evans2013-12-201-0/+3
|
* Optimize arena_prof_ctx_set().Jason Evans2013-12-161-43/+58
| | | | | | Refactor such that arena_prof_ctx_set() receives usize as an argument, and use it to determine whether to handle ptr as a small region, rather than reading the chunk page map.
* Implement the *allocx() API.Jason Evans2013-12-131-162/+294
| | | | | | | | | | | | | | | | | | | | | | | Implement the *allocx() API, which is a successor to the *allocm() API. The *allocx() functions are slightly simpler to use because they have fewer parameters, they directly return the results of primary interest, and mallocx()/rallocx() avoid the strict aliasing pitfall that allocm()/rallocx() share with posix_memalign(). The following code violates strict aliasing rules: foo_t *foo; allocm((void **)&foo, NULL, 42, 0); whereas the following is safe: foo_t *foo; void *p; allocm(&p, NULL, 42, 0); foo = (foo_t *)p; mallocx() does not have this problem: foo_t *foo = (foo_t *)mallocx(42, 0);
* Silence some unused variable warnings.Jason Evans2013-12-101-4/+4
|
* Remove unused variable.Jason Evans2013-12-021-1/+0
|
* Clean up malloc_ncpus().Jason Evans2013-11-301-8/+1
| | | | | | | Clean up malloc_ncpus() by replacing incorrectly indented if..else branches with a ?: expression. Submitted by Igor Podlesny.
* Fix ALLOCM_ARENA(a) handling in rallocm().Jason Evans2013-11-261-1/+1
| | | | | | | Fix rallocm() to use the specified arena for allocation, not just deallocation. Clarify ALLOCM_ARENA(a) documentation.
* Delay pthread_atfork registering.Leonard Crestez2013-10-241-12/+18
| | | | | | This function causes recursive allocation on LinuxThreads. Signed-off-by: Crestez Dan Leonard <lcrestez@ixiacom.com>
* Add a missing mutex unlock in malloc_init_hard() error path.Jason Evans2013-10-211-1/+3
| | | | | | | | Add a missing mutex unlock in a malloc_init_hard() error path (failed mutex initialization). In practice this bug was very unlikely to ever trigger, but if it did, application deadlock would likely result. Reported by Pat Lynch.
* Avoid (x < 0) comparison for unsigned x.Jason Evans2013-10-211-2/+3
| | | | | | | Avoid (min < 0) comparison for unsigned min in malloc_conf_init(). This bug had no practical consequences. Reported by Pat Lynch.
* Prefer not_reached() over assert(false) where appropriate.Jason Evans2013-10-211-2/+1
|
* Fix inlining warning.Jason Evans2013-10-201-3/+3
| | | | | | | | | Add the JEMALLOC_ALWAYS_INLINE_C macro and use it for always-inlined functions declared in .c files. This fixes a function attribute inconsistency for debug builds that resulted in (harmless) compiler warnings about functions not being inlinable. Reported by Ricardo Nabinger Sanchez.
* malloc_conf_init: revert errno value when readlink(2) fail.Alexandre Perrin2013-10-131-14/+14
|
* Fix a prof-related locking order bug.Jason Evans2013-02-061-3/+3
| | | | | Fix a locking order bug that could cause deadlock during fork if heap profiling were enabled.
* Fix potential TLS-related memory corruption.Jason Evans2013-01-311-2/+25
| | | | | | | | | | Avoid writing to uninitialized TLS as a side effect of deallocation. Initializing TLS during deallocation is unsafe because it is possible that a thread never did any allocation, and that TLS has already been deallocated by the threads library, resulting in write-after-free corruption. These fixes affect prof_tdata and quarantine; all other uses of TLS are already safe, whether intentionally (as for tcache) or unintentionally (as for arenas).
* Revert opt_abort and opt_junk refactoring.Jason Evans2013-01-231-2/+14
| | | | | | | | Revert refactoring of opt_abort and opt_junk declarations. clang accepts the config_*-based declarations (and generates correct code), but gcc complains with: error: initializer element is not constant
* Use config_* instead of JEMALLOC_*.Jason Evans2013-01-221-11/+2
| | | | Convert a couple of stragglers from JEMALLOC_* to use config_*.
* Add and use JEMALLOC_ALWAYS_INLINE.Jason Evans2013-01-221-3/+3
| | | | | Add JEMALLOC_ALWAYS_INLINE and use it to guarantee that the entire fast paths of the primary allocation/deallocation functions are inlined.
* Don't mangle errno with free(3) if utrace(2) failsGarrett Cooper2012-12-241-0/+2
| | | | | | | This ensures POLA on FreeBSD (at least) as free(3) is generally assumed to not fiddle around with errno. Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
* Add clipping support to lg_chunk option processing.Jason Evans2012-12-231-19/+23
| | | | | | | | | Modify processing of the lg_chunk option so that it clips an out-of-range input to the edge of the valid range. This makes it possible to request the minimum possible chunk size without intimate knowledge of allocator internals. Submitted by Ian Lepore (see FreeBSD PR bin/174641).
* Add arena-specific and selective dss allocation.Jason Evans2012-10-131-31/+99
| | | | | | | | | | | | | | | | | | | Add the "arenas.extend" mallctl, so that it is possible to create new arenas that are outside the set that jemalloc automatically multiplexes threads onto. Add the ALLOCM_ARENA() flag for {,r,d}allocm(), so that it is possible to explicitly allocate from a particular arena. Add the "opt.dss" mallctl, which controls the default precedence of dss allocation relative to mmap allocation. Add the "arena.<i>.dss" mallctl, which makes it possible to set the default dss precedence on a per arena or global basis. Add the "arena.<i>.purge" mallctl, which obsoletes "arenas.purge". Add the "stats.arenas.<i>.dss" mallctl.
* Make malloc_usable_size() implementation consistent with prototype.Jason Evans2012-10-091-1/+1
| | | | | Use JEMALLOC_USABLE_SIZE_CONST for the malloc_usable_size() implementation as well as the prototype, for consistency's sake.
* Fix fork(2)-related mutex acquisition order.Jason Evans2012-10-091-3/+3
| | | | | | Fix mutex acquisition order inversion for the chunks rtree and the base mutex. Chunks rtree acquisition was introduced by the previous commit, so this bug was short-lived.
* Fix fork(2)-related deadlocks.Jason Evans2012-10-091-3/+30
| | | | | | | | | | | | | | | | | Add a library constructor for jemalloc that initializes the allocator. This fixes a race that could occur if threads were created by the main thread prior to any memory allocation, followed by fork(2), and then memory allocation in the child process. Fix the prefork/postfork functions to acquire/release the ctl, prof, and rtree mutexes. This fixes various fork() child process deadlocks, but one possible deadlock remains (intentionally) unaddressed: prof backtracing can acquire runtime library mutexes, so deadlock is still possible if heap profiling is enabled during fork(). This deadlock is known to be a real issue in at least the case of libgcc-based backtracing. Reported by tfengjun.
* If sysconf() fails, the number of CPUs is reported as UINT_MAX, not 1 as it ↵Corey Richardson2012-10-081-3/+4
| | | | should be
* Remove const from __*_hook variable declarations.Jason Evans2012-05-231-5/+4
| | | | | Remove const from __*_hook variable declarations, so that glibc can modify them during process forking.
* Disable tcache by default if running inside Valgrind.Jason Evans2012-05-161-0/+2
| | | | | Disable tcache by default if running inside Valgrind, in order to avoid making unallocated objects appear reachable to Valgrind.
* Auto-detect whether running inside Valgrind.Jason Evans2012-05-151-14/+15
| | | | | Auto-detect whether running inside Valgrind, thus removing the need to manually specify MALLOC_CONF=valgrind:true.
* Return early in _malloc_{pre,post}fork() if uninitialized.Jason Evans2012-05-121-0/+14
| | | | | | | Avoid mutex operations in _malloc_{pre,post}fork() unless jemalloc has been initialized. Reported by David Xu.
* Add support for MSVCMike Hommey2012-05-011-2/+9
| | | | Tested with MSVC 8 32 and 64 bits.
* Replace JEMALLOC_ATTR with various different macros when it makes senseMike Hommey2012-05-011-44/+9
| | | | | | Theses newly added macros will be used to implement the equivalent under MSVC. Also, move the definitions to headers, where they make more sense, and for some, are even more useful there (e.g. malloc).
* Use Get/SetLastError on Win32Mike Hommey2012-04-301-9/+9
| | | | | | | | | Using errno on win32 doesn't quite work, because the value set in a shared library can't be read from e.g. an executable calling the function setting errno. At the same time, since buferror always uses errno/GetLastError, don't pass it.
* Fix a PROF_ALLOC_PREP() error path.Jason Evans2012-04-251-2/+4
| | | | | Fix a PROF_ALLOC_PREP() error path to initialize the return value to NULL.
* Silence compiler warnings.Jason Evans2012-04-231-3/+3
|
* Add support for MingwMike Hommey2012-04-221-5/+27
|
* Remove mmap_unaligned.Jason Evans2012-04-221-6/+1
| | | | | | | | | | | | | Remove mmap_unaligned, which was used to heuristically decide whether to optimistically call mmap() in such a way that could reduce the total number of system calls. If I remember correctly, the intention of mmap_unaligned was to avoid always executing the slow path in the presence of ASLR. However, that reasoning seems to have been based on a flawed understanding of how ASLR actually works. Although ASLR apparently causes mmap() to ignore address requests, it does not cause total placement randomness, so there is a reasonable expectation that iterative mmap() calls will start returning chunk-aligned mappings once the first chunk has been properly aligned.
* Put CONF_HANDLE_*() keys in quotes.Jason Evans2012-04-211-28/+29
| | | | | Put CONF_HANDLE_*() keys in quotes, so that they aren't mangled when --with-private-namespace is used.
* Make special FreeBSD function overrides visible.Jason Evans2012-04-191-0/+2
| | | | | | Make special FreeBSD libc/libthr function overrides for _malloc_prefork(), _malloc_postfork(), and _malloc_thread_cleanup() visible.
* Update prof defaults to match common usage.Jason Evans2012-04-171-0/+1
| | | | | | | | | Change the "opt.lg_prof_sample" default from 0 to 19 (1 B to 512 KiB). Change the "opt.prof_accum" default from true to false. Add the "opt.prof_final" mallctl, so that "opt.prof_prefix" need not be abused to disable final profile dumping.
* Disable munmap() if it causes VM map holes.Jason Evans2012-04-131-4/+7
| | | | | | | | | | | Add a configure test to determine whether common mmap()/munmap() patterns cause VM map holes, and only use munmap() to discard unused chunks if the problem does not exist. Unify the chunk caching for mmap and dss. Fix options processing to limit lg_chunk to be large enough that redzones will always fit.
* Always disable redzone by default.Jason Evans2012-04-131-3/+1
| | | | | | Always disable redzone by default, even when --enable-debug is specified. The memory overhead for redzones can be substantial, which makes this feature something that should only be opted into.
* Call base_boot before chunk_boot0Mike Hommey2012-04-121-2/+2
| | | | | Chunk_boot0 calls rtree_new, which calls base_alloc, which locks the base_mtx mutex. That mutex is initialized in base_boot.
* Normalize aligned allocation algorithms.Jason Evans2012-04-121-11/+11
| | | | | | | | | | | | | | | Normalize arena_palloc(), chunk_alloc_mmap_slow(), and chunk_recycle_dss() to use the same algorithm for trimming over-allocation. Add the ALIGNMENT_ADDR2BASE(), ALIGNMENT_ADDR2OFFSET(), and ALIGNMENT_CEILING() macros, and use them where appropriate. Remove the run_size_p parameter from sa2u(). Fix a potential deadlock in chunk_recycle_dss() that was introduced by eae269036c9f702d9fa9be497a1a2aa1be13a29e (Add alignment support to chunk_alloc()).
* Implement Valgrind support, redzones, and quarantine.Jason Evans2012-04-111-40/+125
| | | | | | | | | | | | | Implement Valgrind support, as well as the redzone and quarantine features, which help Valgrind detect memory errors. Redzones are only implemented for small objects because the changes necessary to support redzones around large and huge objects are complicated by in-place reallocation, to the point that it isn't clear that the maintenance burden is worth the incremental improvement to Valgrind support. Merge arena_salloc() and arena_salloc_demote(). Refactor i[v]salloc() to expose the 'demote' option.
* Rename labels.Jason Evans2012-04-101-29/+29
| | | | | | | Rename labels from FOO to label_foo in order to avoid system macro definitions, in particular OUT and ERROR on mingw. Reported by Mike Hommey.
* Add utrace(2)-based tracing (--enable-utrace).Jason Evans2012-04-051-1/+37
|
* Fix threaded initialization and enable it on Linux.Jason Evans2012-04-051-3/+5
| | | | Reported by Mike Hommey.