summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Add ctl_mutex proection to arena_i_dss_ctl().Jason Evans2012-10-151-0/+2
| | | | | Add ctl_mutex proection to arena_i_dss_ctl(), since ctl_stats.narenas is accessed.
* Add arena-specific and selective dss allocation.Jason Evans2012-10-139-189/+603
| | | | | | | | | | | | | | | | | | | 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.
* mark _pthread_mutex_init_calloc_cb as public explicitlyJan Beich2012-10-101-1/+1
| | | | | | | Mozilla build hides everything by default using visibility pragma and unhides only explicitly listed headers. But this doesn't work on FreeBSD because _pthread_mutex_init_calloc_cb is neither documented nor exposed via any header.
* 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-095-3/+144
| | | | | | | | | | | | | | | | | 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.
* Fix mlockall()/madvise() interaction.Jason Evans2012-10-093-40/+44
| | | | | | | | mlockall(2) can cause purging via madvise(2) to fail. Fix purging code to check whether madvise() succeeded, and base zeroed page metadata on the result. Reported by Olivier Lecomte.
* Fix error return value in thread_tcache_enabled_ctl().Jason Evans2012-10-081-1/+1
| | | | Reported by Corey Richardson.
* 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 unused variable and branch (reported by clang-analzyer)Corey Richardson2012-10-081-5/+0
|
* 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.
* Update a comment.Jason Evans2012-05-161-1/+1
|
* 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.
* Fix large calloc() zeroing bugs.Jason Evans2012-05-111-25/+18
| | | | | | | | | Refactor code such that arena_mapbits_{large,small}_set() always preserves the unzeroed flag, and manually manipulate the unzeroed flag in the one case where it actually gets reset (in arena_chunk_purge()). This fixes unzeroed preservation bugs in arena_run_split() and arena_ralloc_large_grow(). These bugs caused large calloc() to return non-zeroed memory under some circumstances.
* Add arena chunk map assertions.Jason Evans2012-05-111-15/+30
|
* Refactor arena_run_alloc().Jason Evans2012-05-111-34/+24
| | | | | Refactor duplicated arena_run_alloc() code into arena_run_alloc_helper().
* Add the --enable-mremap option.Jason Evans2012-05-092-1/+4
| | | | | | Add the --enable-mremap option, and disable the use of mremap(2) by default, for the same reason that freeing chunks via munmap(2) is disabled by default on Linux: semi-permanent VM map fragmentation.
* Fix chunk_recycle() to stop leaking trailing chunks.Jason Evans2012-05-091-40/+38
| | | | | | | Fix chunk_recycle() to correctly compute trailsize and re-insert trailing chunks. This fixes a major virtual memory leak. Simplify chunk_record() to avoid dropping/re-acquiring chunks_mtx.
* Fix chunk_alloc_mmap() bugs.Jason Evans2012-05-092-35/+11
| | | | | | | | | | | | | | | | Simplify chunk_alloc_mmap() to no longer attempt map extension. The extra complexity isn't warranted, because although in the success case it saves one system call as compared to immediately falling back to chunk_alloc_mmap_slow(), it also makes the failure case even more expensive. This simplification removes two bugs: - For Windows platforms, pages_unmap() wasn't being called for unaligned mappings prior to falling back to chunk_alloc_mmap_slow(). This caused permanent virtual memory leaks. - For non-Windows platforms, alignment greater than chunksize caused pages_map() to be called with size 0 when attempting map extension. This always resulted in an mmap() error, and subsequent fallback to chunk_alloc_mmap_slow().
* Fix a base allocator deadlock.Jason Evans2012-05-031-3/+14
| | | | | Fix a base allocator deadlock due to chunk_recycle() calling back into the base allocator.
* Don't use sizeof() on a VARIABLE_ARRAYMike Hommey2012-05-021-2/+2
| | | | In the alloca() case, this fails to be the right size.
* Allow je_malloc_message to be overridden when linking staticallyMike Hommey2012-05-022-19/+14
| | | | | | | | | | | | | If an application wants to override je_malloc_message, it is better to define the symbol locally than to change its value in main(), which might be too late for various reasons. Due to je_malloc_message being initialized in util.c, statically linking jemalloc with an application defining je_malloc_message fails due to "multiple definition of" the symbol. Defining it without a value (like je_malloc_conf) makes it more easily overridable.
* Further optimize and harden arena_salloc().Jason Evans2012-05-021-4/+5
| | | | | | | | | Further optimize arena_salloc() to only look at the binind chunk map bits in the common case. Add more sanity checks to arena_salloc() that detect chunk map inconsistencies for large allocations (whether due to allocator bugs or application bugs).
* Make malloc_write() non-inline.Jason Evans2012-05-021-0/+11
| | | | | Make malloc_write() non-inline, in order to resolve its dependency on je_malloc_write().
* Optimize malloc() and free() fast paths.Jason Evans2012-05-023-254/+294
| | | | | | | | | | Embed the bin index for small page runs into the chunk page map, in order to omit [...] in the following dependent load sequence: ptr-->mapelm-->[run-->bin-->]bin_info Move various non-critcal code out of the inlined function chain into helper functions (tcache_event_hard(), arena_dalloc_small(), and locking).
* Add support for MSVCMike Hommey2012-05-012-2/+17
| | | | Tested with MSVC 8 32 and 64 bits.
* Replace JEMALLOC_ATTR with various different macros when it makes senseMike Hommey2012-05-015-54/+19
| | | | | | 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-304-19/+20
| | | | | | | | | 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.
* Remove the VOID macroMike Hommey2012-04-301-6/+2
| | | | Windows headers define a VOID macro.
* Avoid variable length arrays and remove declarations within codeMike Hommey2012-04-294-13/+15
| | | | | | | | | | | | MSVC doesn't support C99, and building as C++ to be able to use them is dangerous, as C++ and C99 are incompatible. Introduce a VARIABLE_ARRAY macro that either uses VLA when supported, or alloca() otherwise. Note that using alloca() inside loops doesn't quite work like VLAs, thus the use of VARIABLE_ARRAY there is discouraged. It might be worth investigating ways to check whether VARIABLE_ARRAY is used in such context at runtime in debug builds and bail out if that happens.
* Fix more prof_tdata resurrection corner cases.Jason Evans2012-04-291-2/+2
|
* Handle prof_tdata resurrection.Jason Evans2012-04-291-17/+37
| | | | | Handle prof_tdata resurrection during thread shutdown, similarly to how tcache and quarantine handle resurrection.
* Don't set prof_tdata during thread cleanup.Jason Evans2012-04-281-3/+0
| | | | | | Don't set prof_tdata during thread cleanup, because doing so will cause the cleanup function to be called again, the second time with a NULL argument.
* 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.
* Fix the "epoch" mallctl.Jason Evans2012-04-251-12/+11
| | | | | Fix the "epoch" mallctl to update cached stats even if the passed in epoch is 0.
* Add missing Valgrind annotations.Jason Evans2012-04-242-0/+4
|
* Fix quarantine_grow() bugs.Jason Evans2012-04-241-9/+8
|
* Add usize sanity checking to quarantine.Jason Evans2012-04-241-13/+21
|
* Handle quarantine resurrection during thread exit.Jason Evans2012-04-241-5/+45
| | | | | Handle quarantine resurrection during thread exit in much the same way as tcache resurrection is handled.
* Fix two CHILD() macro calls in the ctl tree.Jason Evans2012-04-241-2/+2
|
* Fix ctl regression.Jason Evans2012-04-241-24/+26
| | | | | Fix ctl to correctly compute the number of children at each level of the ctl tree.
* Silence compiler warnings.Jason Evans2012-04-231-3/+3
|
* Avoid using a union for ctl_node_sMike Hommey2012-04-231-69/+99
| | | | | | | MSVC doesn't support C99, and as such doesn't support designated initialization of structs and unions. As there is never a mix of indexed and named nodes, it is pretty straightforward to use a different type for each.
* Fix heap profiling bugs.Jason Evans2012-04-221-76/+88
| | | | | | | | | | | Fix a potential deadlock that could occur during interval- and growth-triggered heap profile dumps. Fix an off-by-one heap profile statistics bug that could be observed in interval- and growth-triggered heap profiles. Fix heap profile dump filename sequence numbers (regression during conversion to malloc_snprintf()).
* Remove leftovers from the vsnprintf check in malloc_vsnprintfMike Hommey2012-04-221-4/+0
| | | | | Commit 4eeb52f removed vsnprintf validation, but left a now unused va_copy. It so happens that MSVC doesn't support va_copy.
* Add support for MingwMike Hommey2012-04-225-40/+150
|
* Remove mmap_unaligned.Jason Evans2012-04-223-91/+28
| | | | | | | | | | | | | 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.
* Fix chunk allocation/deallocation bugs.Jason Evans2012-04-213-6/+25
| | | | | | | | | | | | Fix chunk_alloc_dss() to zero memory when requested. Fix chunk_dealloc() to avoid chunk_dealloc_mmap() for dss-allocated memory. Fix huge_palloc() to always junk fill when requested. Improve chunk_recycle() to report that memory is zeroed as a side effect of pages_purge().