summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.3
AgeCommit message (Collapse)Author
2012-04-17Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,Jason Evans
prior to 3.0.0 release) as contrib/jemalloc, and integrate it into libc. The code being imported by this commit diverged from lib/libc/stdlib/malloc.c in March 2010, which means that a portion of the jemalloc 1.0.0 ChangeLog entries are relevant, as are the entries for all subsequent releases. Notes: svn path=/head/; revision=234370
2011-03-07Correct a typo in the malloc(3) manpage. Malloc options are set in theRyan Stone
MALLOC_OPTIONS environment variable, not JEMALLOC_OPTIONS. Reviewed by: jasone Approved by: emaste (mentor) Notes: svn path=/head/; revision=219377
2010-10-08mdoc: drop redundant .Pp and .LP callsUlrich Spörlein
They have no effect when coming in pairs, or before .Bl/.Bd Notes: svn path=/head/; revision=213573
2010-09-11Revert changes of 'assure' to 'ensure' made in r211936.Rebecca Cran
Approved by: rrs (mentor) Notes: svn path=/head/; revision=212463
2010-08-28Fix incorrect usage of 'assure' and 'insure'.Rebecca Cran
Approved by: rrs (mentor) Notes: svn path=/head/; revision=211936
2010-08-06Fix typos and spelling mistakes.Joel Dahl
Notes: svn path=/head/; revision=210933
2010-01-31Fix bugs:Jason Evans
* Fix a race in chunk_dealloc_dss(). * Check for allocation failure before zeroing memory in base_calloc(). Merge enhancements from a divergent version of jemalloc: * Convert thread-specific caching from magazines to an algorithm that is more tunable, and implement incremental GC. * Add support for medium size classes, [4KiB..32KiB], 2KiB apart by default. * Add dirty page tracking for pages within active small/medium object runs. This allows malloc to track precisely which pages are in active use, which makes dirty page purging more effective. * Base maximum dirty page count on proportion of active memory. * Use optional zeroing in arena_chunk_alloc() to avoid needless zeroing of chunks. This is useful in the context of DSS allocation, since a long-lived application may commonly recycle chunks. * Increase the default chunk size from 1MiB to 4MiB. Remove feature: * Remove the dynamic rebalancing code, since thread caching reduces its utility. Notes: svn path=/head/; revision=203329
2009-09-26Make malloc(3) superpage aware. Specifically, if getpagesizes(3) returnsAlan Cox
a large page size that is greater than malloc(3)'s default chunk size but less than or equal to 4 MB, then increase the chunk size to match the large page size. Most often, using a chunk size that is less than the large page size is not a problem. However, consider a long-running application that allocates and frees significant amounts of memory. In particular, it frees enough memory at times that some of that memory is munmap()ed. Up until the first munmap(), a 1MB chunk size is just fine; it's not a problem for the virtual memory system. Two adjacent 1MB chunks that are aligned on a 2MB boundary will be promoted automatically to a superpage even though they were allocated at different times. The trouble begins with the munmap(), releasing a 1MB chunk will trigger the demotion of the containing superpage, leaving behind a half-used 2MB reservation. Now comes the real problem. Unfortunately, when the application needs to allocate more memory, and it recycles the previously munmap()ed address range, the implementation of mmap() won't be able to reuse the reservation. Basically, the coalescing rules in the virtual memory system don't allow this new range to combine with its neighbor. The effect being that superpage promotion will not reoccur for this range of addresses until both 1MB chunks are freed at some point in the future. Reviewed by: jasone MFC after: 3 weeks Notes: svn path=/head/; revision=197524
2008-11-03Revert to preferring mmap(2) over sbrk(2) when mapping memory, due toJason Evans
potential extreme contention in the kernel for multi-threaded applications on SMP systems. Reported by: kris Notes: svn path=/head/; revision=184602
2008-08-27Add thread-specific caching for small size classes, based on magazines.Jason Evans
This caching allows for completely lock-free allocation/deallocation in the steady state, at the expense of likely increased memory use and fragmentation. Reduce the default number of arenas to 2*ncpus, since thread-specific caching typically reduces arena contention. Modify size class spacing to include ranges of 2^n-spaced, quantum-spaced, cacheline-spaced, and subpage-spaced size classes. The advantages are: fewer size classes, reduced false cacheline sharing, and reduced internal fragmentation for allocations that are slightly over 512, 1024, etc. Increase RUN_MAX_SMALL, in order to limit fragmentation for the subpage-spaced size classes. Add a size-->bin lookup table for small sizes to simplify translating sizes to size classes. Include a hard-coded constant table that is used unless custom size class spacing is specified at run time. Add the ability to disable tiny size classes at compile time via MALLOC_TINY. Notes: svn path=/head/; revision=182225
2008-02-17Remove support for lazy deallocation. Benchmarks across a wide range ofJason Evans
allocation patterns, number of CPUs, and MALLOC_OPTIONS settings indicate that lazy deallocation has the potential to worsen throughput dramatically. Performance degradation occurs when multiple threads try to clear the lazy free cache simultaneously. Various experiments to avoid this bottleneck failed to completely solve this problem, while adding yet more complexity. Notes: svn path=/head/; revision=176368
2008-02-06Track dirty unused pages so that they can be purged if they exceed aJason Evans
threshold, according to the 'F' MALLOC_OPTIONS flag. This obsoletes the 'H' flag. Try to realloc() large objects in place. This substantially speeds up incremental large reallocations in the common case. Fix a bug in arena_ralloc() that caused relocation of sub-page objects even if the old and new sizes were in the same size class. Maintain trees of runs and simplify the per-chunk page map. This allows logarithmic-time searching for sufficiently large runs in arena_run_alloc(), whereas the previous algorithm required linear time in the worst case. Break various large functions into smaller sub-functions, and inline only the functions that are in the fast path for small object allocation/deallocation. Remove an unnecessary check in base_pages_alloc_mmap(). Avoid integer division in choose_arena() for the NO_TLS case on single-CPU systems. Notes: svn path=/head/; revision=176022
2008-01-03Enable both sbrk(2)- and mmap(2)-based memory acquisition methods byJason Evans
default. This has the disadvantage of rendering the datasize resource limit irrelevant, but without this change, legitimate uses of more memory than will fit in the data segment are thwarted by default. Fix chunk_alloc_mmap() to work correctly if initial mapping is not chunk-aligned and mapping extension fails. Notes: svn path=/head/; revision=175075
2007-12-27Add the 'D' and 'M' run time options, and use them to control whetherJason Evans
memory is acquired from the system via sbrk(2) and/or mmap(2). By default, use sbrk(2) only, in order to support traditional use of resource limits. Additionally, when both options are enabled, prefer the data segment to anonymous mappings, in order to coexist better with large file mappings in applications on 32-bit platforms. This change has the potential to increase memory fragmentation due to the linear nature of the data segment, but from a performance perspective this is mitigated by the use of madvise(2). [1] Add the ability to interpret integer prefixes in MALLOC_OPTIONS processing. For example, MALLOC_OPTIONS=lllllllll can now be specified as MALLOC_OPTIONS=9l. Reported by: [1] rwatson Design review: [1] alc, peter, rwatson Notes: svn path=/head/; revision=174950
2007-11-27Document the B and L MALLOC_OPTIONS.Jason Evans
Notes: svn path=/head/; revision=173969
2007-06-15Add information about the implications of using mmap(2) instead of sbrk(2).Jason Evans
Submitted by: bmah, jhb Notes: svn path=/head/; revision=170798
2007-03-28Update the IMPLEMENTATION NOTES section to reflect recent mallocJason Evans
enhancements. Notes: svn path=/head/; revision=167969
2006-09-17Markup fixes.Ruslan Ermilov
Notes: svn path=/head/; revision=162385
2006-04-13s/soley/solelyJens Schweikhardt
Notes: svn path=/head/; revision=157735
2006-04-04Add malloc_usable_size() to the RETURN VALUES section.Jason Evans
Notes: svn path=/head/; revision=157508
2006-03-28Add malloc_usable_size(3).Jason Evans
Discussed with: arch@ Notes: svn path=/head/; revision=157236
2006-03-17Modify allocation policy, in order to avoid excessive fragmentation forJason Evans
allocation patterns that involve a relatively even mixture of many different size classes. Reduce the chunk size from 16 MB to 2 MB. Since chunks are now carved up using an address-ordered first best fit policy, VM map fragmentation is much less likely, which makes smaller chunks not as much of a risk. This reduces the virtual memory size of most applications. Remove redzones, since program buffer overruns are no longer as likely to corrupt malloc data structures. Remove the C MALLOC_OPTIONS flag, and add H and S. Notes: svn path=/head/; revision=156800
2006-02-01Expand contractions.Joel Dahl
Notes: svn path=/head/; revision=155181
2006-01-13Replace malloc(), calloc(), posix_memalign(), realloc(), and free() withJason Evans
a scalable concurrent allocator implementation. Reviewed by: current@ Approved by: phk, markm (mentor) Notes: svn path=/head/; revision=154306
2005-11-23Fix prototype.Ruslan Ermilov
Notes: svn path=/head/; revision=152734
2005-01-20Sort sections.Ruslan Ermilov
Notes: svn path=/head/; revision=140505
2004-08-19Reword recent addition about memory moving.Alfred Perlstein
Requested by: keramida Bump .Dd Requested by: ru Notes: svn path=/head/; revision=134020
2004-08-18Clarify that realloc and reallocf may move the memory allocation.Alfred Perlstein
Notes: svn path=/head/; revision=133985
2002-12-24mdoc(7) police: Deal with self-xrefs.Ruslan Ermilov
Notes: svn path=/head/; revision=108257
2002-12-20Document what really occurs when we obtain an error.Tom Rhodes
PR: 43357 Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU> Notes: svn path=/head/; revision=108113
2002-12-18mdoc(7) police: Fixed abuses of the .Ar and .Em macros.Ruslan Ermilov
Notes: svn path=/head/; revision=108040
2002-12-18mdoc(7) police: "The .Fn function".Ruslan Ermilov
Notes: svn path=/head/; revision=108037
2002-12-12Uniformly refer to a file system as "file system".Ruslan Ermilov
Approved by: re Notes: svn path=/head/; revision=107788
2002-12-04Consistently mark std(in|out|err) with .Dv, because that's how theyRuslan Ermilov
are marked up in stdio(3), and because they are defined expressions of type "FILE *". Approved by: re Notes: svn path=/head/; revision=107619
2002-06-06Clarify the bit about realloc() and its `ptr' argument a bit.Giorgos Keramidas
Hopefully, now it is more clear that the memory referenced by the ptr argument of realloc(ptr,size) is freed and only the return value of realloc() points to a valid memory area upon successful completion. Submitted by: Martin Faxer <gmh003532@brfmasthugget.se> Notes: svn path=/head/; revision=97967
2002-05-29mdoc(7) police: nit.Ruslan Ermilov
Notes: svn path=/head/; revision=97467
2002-04-24Constify _malloc_options.Poul-Henning Kamp
Notes: svn path=/head/; revision=95377
2001-12-12mdoc(7) police: kill HSBs, add missing comma.Ruslan Ermilov
Notes: svn path=/head/; revision=87737
2001-11-24Be more explicit about the fact that realloc() might return aGiorgos Keramidas
different pointer than the one passed to it. PR: docs/31925 Submitted by: Andrew <andrew@ugh.net.au> Notes: svn path=/head/; revision=86845
2001-11-05malloc and calloc do not free memory.Dima Dorfman
PR: 31365 Submitted by: SUZUKI Koichi <koich@cac.co.jp> Notes: svn path=/head/; revision=86063
2001-09-07Move to using .In instead of .Fd #include <> for include mark-up.Jeroen Ruigrok van der Werven
Inspired by comment from: dd Notes: svn path=/head/; revision=83206
2001-08-10Markup nits: use diagnostic type lists for error and warning messages.Ruslan Ermilov
Backout previous revision. We should not expand plain text xrefs if they appear in the literal text, e.g. in the error or warning message of the library function. (Submitted by: bde) Moved "out of memory" from warning to errors section. Notes: svn path=/head/; revision=81446
2001-08-08mdoc(7) police: expand plain text xrefs.Ruslan Ermilov
Notes: svn path=/head/; revision=81285
2001-07-15Remove whitespace at EOL.Dima Dorfman
Notes: svn path=/head/; revision=79754
2001-07-10mdoc(7) police: removed HISTORY info from the .Os call.Ruslan Ermilov
Notes: svn path=/head/; revision=79531
2001-07-09mdoc(7) police: remove extraneous .Pp before and/or after .Sh.Dima Dorfman
Notes: svn path=/head/; revision=79454
2001-07-04mdoc(7) police: mark NULL with .Dv.Ruslan Ermilov
Notes: svn path=/head/; revision=79200
2001-06-24mdoc(7) police: the BUGS section should go after HISTORY and AUTHORS.Dima Dorfman
Notes: svn path=/head/; revision=78727
2001-06-24The fact that phk wrote this is not a bug!Dima Dorfman
Notes: svn path=/head/; revision=78726
2001-06-24Reword a sentence to make it proper English.Dima Dorfman
Notes: svn path=/head/; revision=78706