History log of /freebsd-10.0-release/lib/libc/stdlib/reallocf.3
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 234370 17-Apr-2012 jasone

Import jemalloc 9ef7f5dc34ff02f50d401e41c8d9a4a928e7c2aa (dev branch,
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.


# 219377 07-Mar-2011 rstone

Correct a typo in the malloc(3) manpage. Malloc options are set in the
MALLOC_OPTIONS environment variable, not JEMALLOC_OPTIONS.

Reviewed by: jasone
Approved by: emaste (mentor)


# 213573 08-Oct-2010 uqs

mdoc: drop redundant .Pp and .LP calls

They have no effect when coming in pairs, or before .Bl/.Bd


# 212463 11-Sep-2010 brucec

Revert changes of 'assure' to 'ensure' made in r211936.

Approved by: rrs (mentor)


# 211936 28-Aug-2010 brucec

Fix incorrect usage of 'assure' and 'insure'.

Approved by: rrs (mentor)


# 210933 06-Aug-2010 joel

Fix typos and spelling mistakes.


# 203329 31-Jan-2010 jasone

Fix bugs:

* 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.


# 197524 26-Sep-2009 alc

Make malloc(3) superpage aware. Specifically, if getpagesizes(3) returns
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


# 184602 03-Nov-2008 jasone

Revert to preferring mmap(2) over sbrk(2) when mapping memory, due to
potential extreme contention in the kernel for multi-threaded applications
on SMP systems.

Reported by: kris


# 182225 27-Aug-2008 jasone

Add thread-specific caching for small size classes, based on magazines.
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.


# 176368 17-Feb-2008 jasone

Remove support for lazy deallocation. Benchmarks across a wide range of
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.


# 176022 06-Feb-2008 jasone

Track dirty unused pages so that they can be purged if they exceed a
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.


# 175075 03-Jan-2008 jasone

Enable both sbrk(2)- and mmap(2)-based memory acquisition methods by
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.


# 174950 27-Dec-2007 jasone

Add the 'D' and 'M' run time options, and use them to control whether
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


# 173969 27-Nov-2007 jasone

Document the B and L MALLOC_OPTIONS.


# 170798 15-Jun-2007 jasone

Add information about the implications of using mmap(2) instead of sbrk(2).

Submitted by: bmah, jhb


# 167969 28-Mar-2007 jasone

Update the IMPLEMENTATION NOTES section to reflect recent malloc
enhancements.


# 162385 17-Sep-2006 ru

Markup fixes.


# 157735 13-Apr-2006 schweikh

s/soley/solely


# 157508 04-Apr-2006 jasone

Add malloc_usable_size() to the RETURN VALUES section.


# 157236 28-Mar-2006 jasone

Add malloc_usable_size(3).

Discussed with: arch@


# 156800 17-Mar-2006 jasone

Modify allocation policy, in order to avoid excessive fragmentation for
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.


# 155181 01-Feb-2006 joel

Expand contractions.


# 154306 13-Jan-2006 jasone

Replace malloc(), calloc(), posix_memalign(), realloc(), and free() with
a scalable concurrent allocator implementation.

Reviewed by: current@
Approved by: phk, markm (mentor)


# 152734 23-Nov-2005 ru

Fix prototype.


# 140505 20-Jan-2005 ru

Sort sections.


# 134020 19-Aug-2004 alfred

Reword recent addition about memory moving.

Requested by: keramida

Bump .Dd

Requested by: ru


# 133985 18-Aug-2004 alfred

Clarify that realloc and reallocf may move the memory allocation.


# 108257 24-Dec-2002 ru

mdoc(7) police: Deal with self-xrefs.


# 108113 19-Dec-2002 trhodes

Document what really occurs when we obtain an error.

PR: 43357
Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU>


# 108040 18-Dec-2002 ru

mdoc(7) police: Fixed abuses of the .Ar and .Em macros.


# 108037 18-Dec-2002 ru

mdoc(7) police: "The .Fn function".


# 107788 12-Dec-2002 ru

Uniformly refer to a file system as "file system".

Approved by: re


# 107619 04-Dec-2002 ru

Consistently mark std(in|out|err) with .Dv, because that's how they
are marked up in stdio(3), and because they are defined expressions
of type "FILE *".

Approved by: re


# 97967 06-Jun-2002 keramida

Clarify the bit about realloc() and its `ptr' argument a bit.
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>


# 97467 29-May-2002 ru

mdoc(7) police: nit.


# 95377 24-Apr-2002 phk

Constify _malloc_options.


# 87737 12-Dec-2001 ru

mdoc(7) police: kill HSBs, add missing comma.


# 86845 24-Nov-2001 keramida

Be more explicit about the fact that realloc() might return a
different pointer than the one passed to it.

PR: docs/31925
Submitted by: Andrew <andrew@ugh.net.au>


# 86063 04-Nov-2001 dd

malloc and calloc do not free memory.

PR: 31365
Submitted by: SUZUKI Koichi <koich@cac.co.jp>


# 83206 07-Sep-2001 asmodai

Move to using .In instead of .Fd #include <> for include mark-up.

Inspired by comment from: dd


# 81446 10-Aug-2001 ru

Markup nits: use diagnostic type lists for error and warning messages.

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.


# 81285 08-Aug-2001 ru

mdoc(7) police: expand plain text xrefs.


# 79754 15-Jul-2001 dd

Remove whitespace at EOL.


# 79531 10-Jul-2001 ru

mdoc(7) police: removed HISTORY info from the .Os call.


# 79454 09-Jul-2001 dd

mdoc(7) police: remove extraneous .Pp before and/or after .Sh.


# 79200 04-Jul-2001 ru

mdoc(7) police: mark NULL with .Dv.


# 78727 24-Jun-2001 dd

mdoc(7) police: the BUGS section should go after HISTORY and AUTHORS.


# 78726 24-Jun-2001 dd

The fact that phk wrote this is not a bug!


# 78706 24-Jun-2001 dd

Reword a sentence to make it proper English.


# 73088 26-Feb-2001 ru

.St -ansiC -> .St -isoC


# 72400 12-Feb-2001 ru

mmap(3) -> mmap(2).


# 72368 11-Feb-2001 nik

.Xr to mmap.


# 72126 07-Feb-2001 ru

mdoc(7) police: Change -filled displays (which just happen
to be the same as -ragged in the current implementation) to
-ragged. With mdocNG, -filled displays produce the correct
output, formatted and justified to both margins.


# 71895 01-Feb-2001 ru

mdoc(7) police: split punctuation characters + misc fixes.


# 71097 16-Jan-2001 ru

Prepare for mdoc(7)NG.


# 70481 29-Dec-2000 ru

Prepare for mdoc(7)NG.


# 70015 14-Dec-2000 ru

mdoc(7) police: removed history info from the .Os FreeBSD call.


# 69201 26-Nov-2000 phk

Make it possible to override the function which writes messages to
stderr in case of warnings and errors.

Rename malloc_options to have a leading underscore, I belive I have been
told that is more correct namespace wise.


# 68716 14-Nov-2000 ru

Use Fx macro wherever possible.


# 60015 05-May-2000 mpp

Minor mdoc cleanup.

PR: docs/13218


# 59460 21-Apr-2000 phantom

Introduce ".Lb" macro to libc manpages.

More libraries manpages updates following.


# 59117 10-Apr-2000 phk

Add a missing THREAD_UNLOCK() found missing by Valentin Nechayev
<netch@segfault.kiev.ua>

Remove allocation failure check from 'A' option, the 'X' option does
this as a standalone check now.


# 55186 28-Dec-1999 hoek

Add history: The reallocf() function first appeared in FreeBSD-3.0.

See imp's 199808201619.KAA20970@harmony.village.org in freebsd-hackers (the
reallocf.c cvs history mistakenly refers to freebsd-current).


# 55006 22-Dec-1999 sheldonh

Document the current behaviour with respect to the handling of errno.

Approved by: phk


# 53111 12-Nov-1999 peter

Go to a bit more trouble to make it absolutely clear that malloc(3)
does not zero the allocated memory.


# 51667 25-Sep-1999 chris

Change .Fn to .Xr on a couple of lines where abort(3) is referenced.


# 50476 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 49828 15-Aug-1999 mpp

Various man page cleanup:

- Sort xrefs
- FreeBSD.ORG -> FreeBSD.org
- Be consistent with section names as outlines in mdoc(7)
- Other misc mdoc cleanup.

PR: doc/13144
Submitted by: Alexy M. Zelkin <phantom@cris.net>


# 49744 14-Aug-1999 chris

Fix .Xr line for `getpagesize'


# 45091 28-Mar-1999 phk

Disable the "Hint" option in phkmalloc as default. Recent VM system
changes have made this too expensive. This gains about 1.25% on
worldstone on my SMP machine.

Swap-less machines, for instance PicoBSDs, and machines which experience
page-out trafic, check with top(1), will probably want to reenable this
with:
ln -s H /etc/malloc.conf

Suggested by: alc (&dyson ?)


# 39325 16-Sep-1998 imp

o Don't reference non-existant function freealloc.
o Properly order things

Pointed out by: bde


# 39191 14-Sep-1998 imp

Add reallocf to the library. This function is simliar to realloc, but
when it returns NULL to indicate failure, it will also free the memory
that was passed to it, if that was non-null.

This does not change the semantics of realloc.

A second commit will be done to commit the conversion of those places in
the code that can safely use this to avoid memory leaks when confronted
with low memory situations.

Beaten-to-death-but-finally-approved-in: -current


# 29563 18-Sep-1997 charnier

environmental -> environment.


# 28830 27-Aug-1997 phk

Malloc option H is now default.


# 27152 01-Jul-1997 phk

malloc_sysv used before initialized, reported in PR4002 by
Dmitrij Tejblum <dima@tejblum.dnttm.rssi.ru>

Various cleanup from Keith Bostic

Reinstate calloc() as a separate funtion, in its own source/object file.
leave the manpage integrated with malloc.3 and friends. Too many things
were broken in this respect.

PR: 4002
Reviewed by: phk
Submitted by: Dmitrij Tejblum <dima@tejblum.dnttm.rssi.ru>
Submitted by: Keith Bostic <bostic@bostic.com>


# 26816 22-Jun-1997 phk

Integrate calloc with the rest of the gang.
Various portability and stylistic cleanups.
Kill MALLOC_STATS & the 'D' option.
Fix the 'V' option.
Major overhaul of the man-page.
You milage should not vary.

Reviewed by: Keith Bostic <bostic@bostic.com>
Submitted by: Keith Bostic <bostic@bostic.com>


# 26579 12-Jun-1997 phk

Add yet an option, this time on how to deal with malloc(0) and realloc(ptr.0)

Prompted by: X11 & XFree86


# 26284 30-May-1997 phk

Malloc flag X makes malloc behave like the canonical xmalloc() wrapper.

Untested support for Solaris from John-Mark Gurney

Reviewed by: phk
Submitted by: (partially) John-Mark Gurney <gurney_j@resnet.uoregon.edu>


# 24125 22-Mar-1997 mpp

Remove an extra comma.


# 22993 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 18479 23-Sep-1996 phk

phkmalloc/3
Various neat features added. More documentation in the manpage.
If your machine has very little RAM, I guess that would be < 16M
these days :-(, you may want to try this:
ln -fs 'H<' /etc/malloc.conf
check the manpage.


# 14038 11-Feb-1996 mpp

Correct a bunch of man page cross references and generally
try and silence "manck".

ncurses, rpc, and some of the gnu stuff are still a big mess, however.


# 13750 30-Jan-1996 mpp

Fix even more spelling errors in some more man pages.


# 11338 08-Oct-1995 phk

phkmalloc/2
"zero' and 'junk' options to help find and diagnose malloc abuse.
EXTRA_SANITY defaults "junk" to on.
Don't dump the internal state, unless EXTRA_SANITY.
General code cleanup.
Error messages cleaned up a bit, more checking earlier.
EXTRA_SANITY is default at this time (just in case).
Performance (without EXTRA_SANITY) is better, beats gnumalloc in
both time & space most of the time:

# In-memory test.
./malloc 50000000 2000 8192
159.2u 1.5s 2:41.85 99.3% 5+7742k 0+0io 0pf+0w
./gnumalloc 50000000 2000 8192
272.6u 0.4s 4:35.01 99.3% 5+8533k 0+0io 0pf+0w

# Swap-space test.
./malloc 500000 14000 8192
6.5u 4.1s 4:08.87 4.3% 5+49209k 0+0io 9772pf+0w
./gnumalloc 500000 14000 8192
16.2u 14.5s 15:36.14 3.2% 5+54100k 0+0io 47651pf+0w

# Small items test.
./malloc 20000000 20000 2048
67.0u 0.3s 1:07.83 99.2% 5+18199k 0+0io 4pf+0w
./gnumalloc 20000000 20000 2048
66.2u 0.3s 1:07.03 99.3% 5+18107k 0+0io 0pf+0w

SANITY is not an option anymore. (!!)


# 10818 16-Sep-1995 phk

``phkmalloc''
Performance is comparable to gnumalloc if you have sufficient RAM, and
it screams around it if you don't.
Compiled with "EXTRA_SANITY" until further notice.
see malloc.3 for more details.


# 1574 27-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1573,
which included commits to RCS files with non-trunk default branches.


# 1573 27-May-1994 rgrimes

BSD 4.4 Lite Lib Sources