Skip site navigation (1)Skip section navigation (2)

CVS log for src/lib/libc/stdlib/malloc.c

[BACK] Up to [FreeBSD] / src / lib / libc / stdlib

Request diff between arbitrary revisions


Keyword substitution: kv
Default branch: MAIN


Revision 1.199: download - view: text, markup, annotated - select for diffs
Mon Jan 9 06:36:28 2012 UTC (4 weeks, 3 days ago) by ed
Branches: MAIN
CVS tags: HEAD
Diff to: previous 1.198: preferred, colored
Changes since revision 1.198: +14 -0 lines
SVN rev 229848 on 2012-01-09 06:36:28Z by ed

Add aligned_alloc(3).

The C11 folks reinvented the wheel by introducing an aligned version of
malloc(3) called aligned_alloc(3), instead of posix_memalign(3). Instead
of returning the allocation by reference, it returns the address, just
like malloc(3).

Reviewed by:	jasone@

Revision 1.197.2.3: download - view: text, markup, annotated - select for diffs
Sat Dec 31 12:58:21 2011 UTC (5 weeks, 5 days ago) by dim
Branches: RELENG_9
Diff to: previous 1.197.2.2: preferred, colored; branchpoint 1.197: preferred, colored; next MAIN 1.198: preferred, colored
Changes since revision 1.197.2.2: +10 -2 lines
SVN rev 229079 on 2011-12-31 12:58:21Z by dim

MFC r228540:

Since clang does not support the tls_model attribute used in malloc.c
yet (see LLVM PR 9788), and warns about it, rub it out for now.  When
clang grows support for this attribute, I will revert this again.

Revision 1.198: download - view: text, markup, annotated - select for diffs
Thu Dec 15 20:40:11 2011 UTC (7 weeks, 6 days ago) by dim
Branches: MAIN
Diff to: previous 1.197: preferred, colored
Changes since revision 1.197: +10 -2 lines
SVN rev 228540 on 2011-12-15 20:40:11Z by dim

Since clang does not support the tls_model attribute used in malloc.c
yet (see LLVM PR 9788), and warns about it, rub it out for now.  When
clang grows support for this attribute, I will revert this again.

MFC after:	1 week

Revision 1.197.2.2.2.1: download - view: text, markup, annotated - select for diffs
Fri Nov 11 04:20:22 2011 UTC (2 months, 4 weeks ago) by kensmith
Branches: RELENG_9_0
CVS tags: RELENG_9_0_0_RELEASE
Diff to: previous 1.197.2.2: preferred, colored; next MAIN 1.197.2.3: preferred, colored
Changes since revision 1.197.2.2: +0 -0 lines
SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)

Revision 1.197.2.2: download - view: text, markup, annotated - select for diffs
Sat Oct 15 21:23:04 2011 UTC (3 months, 3 weeks ago) by kensmith
Branches: RELENG_9
CVS tags: RELENG_9_0_BP
Branch point for: RELENG_9_0
Diff to: previous 1.197.2.1: preferred, colored; branchpoint 1.197: preferred, colored
Changes since revision 1.197.2.1: +1 -1 lines
SVN rev 226405 on 2011-10-15 21:23:04Z by kensmith

Remove extra debuggin gsupport that is turned on for head but turned off
for stable branches:

	- shift to MALLOC_PRODUCTION
	- turn off automatic crash dumps
	- remove kernel debuggers, INVARIANT*[1], WITNESS* from GENERIC
	  kernel config files

[1] INVARIANT* left on for ia64 at least temporarily, marcel@ will test
    to see if they are still required as they had been for stable/8.

Approved by:	re (implicit)

Revision 1.197.2.1: download - view: text, markup, annotated - select for diffs
Fri Sep 23 00:51:37 2011 UTC (4 months, 2 weeks ago) by kensmith
Branches: RELENG_9
Diff to: previous 1.197: preferred, colored
Changes since revision 1.197: +0 -0 lines
SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)

Revision 1.197: download - view: text, markup, annotated - select for diffs
Tue Jun 21 19:15:23 2011 UTC (7 months, 2 weeks ago) by marius
Branches: MAIN
CVS tags: RELENG_9_BP
Branch point for: RELENG_9
Diff to: previous 1.196: preferred, colored
Changes since revision 1.196: +1 -1 lines
SVN rev 223369 on 2011-06-21 19:15:23Z by marius

Change sparc64 to use the initial exec TLS model, too. This avoids random
assertion failures in _malloc_thread_cleanup().

Revision 1.196: download - view: text, markup, annotated - select for diffs
Fri Mar 11 21:35:38 2011 UTC (11 months ago) by marius
Branches: MAIN
Diff to: previous 1.195: preferred, colored
Changes since revision 1.195: +1 -1 lines
SVN rev 219535 on 2011-03-11 21:35:38Z by marius

Now that TLS generally is available on sparc64 since r219534 turn on
support for it. Note that while sparc64 also supports the static TLS
model and thus tls_model("initial-exec"), using the default model
turned out to yield slightly better buildstone performance.

Revision 1.147.2.7.4.1: download - view: text, markup, annotated - select for diffs
Tue Dec 21 17:10:29 2010 UTC (13 months, 2 weeks ago) by kensmith
Branches: RELENG_7_4
CVS tags: RELENG_7_4_0_RELEASE
Diff to: previous 1.147.2.7: preferred, colored; next MAIN 1.148: preferred, colored
Changes since revision 1.147.2.7: +0 -0 lines
SVN rev 216618 on 2010-12-21 17:10:29Z by kensmith

Copy stable/7 to releng/7.4 in preparation for FreeBSD-7.4 release.

Approved by:	re (implicit)

Revision 1.183.2.5.4.1: download - view: text, markup, annotated - select for diffs
Tue Dec 21 17:09:25 2010 UTC (13 months, 2 weeks ago) by kensmith
Branches: RELENG_8_2
CVS tags: RELENG_8_2_0_RELEASE
Diff to: previous 1.183.2.5: preferred, colored; next MAIN 1.184: preferred, colored
Changes since revision 1.183.2.5: +0 -0 lines
SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)

Revision 1.195: download - view: text, markup, annotated - select for diffs
Tue Aug 17 09:13:26 2010 UTC (17 months, 3 weeks ago) by kib
Branches: MAIN
Diff to: previous 1.194: preferred, colored
Changes since revision 1.194: +15 -6 lines
SVN rev 211416 on 2010-08-17 09:13:26Z by kib

Use aux vector to get values for SSP canary, pagesize, pagesizes array,
number of host CPUs and osreldate.

This eliminates the last sysctl(2) calls from the dynamically linked image
startup.

No objections from:	kan
Tested by:	marius (sparc64)
MFC after:	1 month

Revision 1.194: download - view: text, markup, annotated - select for diffs
Sat Jul 10 14:45:03 2010 UTC (19 months ago) by nwhitehorn
Branches: MAIN
Diff to: previous 1.193: preferred, colored
Changes since revision 1.193: +6 -1 lines
SVN rev 209878 on 2010-07-10 14:45:03Z by nwhitehorn

Provide 64-bit PowerPC support in libc.

Obtained from:	projects/ppc64

Revision 1.183.2.5.2.1: download - view: text, markup, annotated - select for diffs
Mon Jun 14 02:09:06 2010 UTC (19 months, 3 weeks ago) by kensmith
Branches: RELENG_8_1
CVS tags: RELENG_8_1_0_RELEASE
Diff to: previous 1.183.2.5: preferred, colored; next MAIN 1.184: preferred, colored
Changes since revision 1.183.2.5: +0 -0 lines
SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)

Revision 1.193: download - view: text, markup, annotated - select for diffs
Sun Feb 28 22:57:13 2010 UTC (23 months, 1 week ago) by jasone
Branches: MAIN
Diff to: previous 1.192: preferred, colored
Changes since revision 1.192: +20 -10 lines
SVN rev 204493 on 2010-02-28 22:57:13Z by jasone

Rewrite red-black trees to do lazy balance fixup.  This improves
insert/remove speed by ~30%.

Revision 1.192: download - view: text, markup, annotated - select for diffs
Tue Feb 16 20:46:22 2010 UTC (23 months, 3 weeks ago) by marcel
Branches: MAIN
Diff to: previous 1.191: preferred, colored
Changes since revision 1.191: +1 -0 lines
SVN rev 203969 on 2010-02-16 20:46:22Z by marcel

Define TLS_MODEL for PowerPC as well. Since PowerPC uses variant I,
like ia64, leave it empty (default model).

Revision 1.191: download - view: text, markup, annotated - select for diffs
Tue Feb 16 06:47:00 2010 UTC (23 months, 3 weeks ago) by marcel
Branches: MAIN
Diff to: previous 1.190: preferred, colored
Changes since revision 1.190: +9 -11 lines
SVN rev 203950 on 2010-02-16 06:47:00Z by marcel

Unbreak ia64: tls_model("initial-exec") is invalid, because it assumes
the static TLS model, which is fundamentally different from the dynamic
TLS model. The consequence was data corruption. Limit the attribute to
i386 and amd64.

Revision 1.147.2.7.2.1: download - view: text, markup, annotated - select for diffs
Wed Feb 10 00:26:20 2010 UTC (23 months, 4 weeks ago) by kensmith
Branches: RELENG_7_3
CVS tags: RELENG_7_3_0_RELEASE
Diff to: previous 1.147.2.7: preferred, colored; next MAIN 1.148: preferred, colored
Changes since revision 1.147.2.7: +0 -0 lines
SVN rev 203736 on 2010-02-10 00:26:20Z by kensmith

Copy stable/7 to releng/7.3 as part of the 7.3-RELEASE process.

Approved by:	re (implicit)

Revision 1.183.2.5: download - view: text, markup, annotated - select for diffs
Tue Feb 9 13:07:32 2010 UTC (23 months, 4 weeks ago) by emaste
Branches: RELENG_8
CVS tags: RELENG_8_2_BP, RELENG_8_1_BP
Branch point for: RELENG_8_2, RELENG_8_1
Diff to: previous 1.183.2.4: preferred, colored; branchpoint 1.183: preferred, colored; next MAIN 1.184: preferred, colored
Changes since revision 1.183.2.4: +1 -0 lines
SVN rev 203701 on 2010-02-09 13:07:32Z by emaste

MFC r203077:

  Add missing return, in a rare case where we can't allocate memory in
  deallocate.

Submitted by: Ryan Stone (rysto32 at gmail dot com)
Approved by:  jasone

Revision 1.190: download - view: text, markup, annotated - select for diffs
Sun Jan 31 23:16:10 2010 UTC (2 years ago) by jasone
Branches: MAIN
Diff to: previous 1.189: preferred, colored
Changes since revision 1.189: +1960 -1290 lines
SVN rev 203329 on 2010-01-31 23:16:10Z by 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.

Revision 1.189: download - view: text, markup, annotated - select for diffs
Wed Jan 27 16:47:02 2010 UTC (2 years ago) by emaste
Branches: MAIN
Diff to: previous 1.188: preferred, colored
Changes since revision 1.188: +1 -0 lines
SVN rev 203077 on 2010-01-27 16:47:02Z by emaste

Add missing return, in a rare case where we can't allocate memory in
deallocate.

Submitted by:	Ryan Stone (rysto32 at gmail dot com)
Approved by:	jasone

Revision 1.188: download - view: text, markup, annotated - select for diffs
Thu Dec 10 02:51:40 2009 UTC (2 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.187: preferred, colored
Changes since revision 1.187: +28 -89 lines
SVN rev 200345 on 2009-12-10 02:51:40Z by jasone

Simplify arena_run_reg_dalloc(), and remove a bug that was due to incorrect
initialization of ssize_invs.

Revision 1.187: download - view: text, markup, annotated - select for diffs
Thu Dec 10 00:16:11 2009 UTC (2 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.186: preferred, colored
Changes since revision 1.186: +1 -0 lines
SVN rev 200340 on 2009-12-10 00:16:11Z by jasone

Fix the posix_memalign() changes in r196861 to actually return a NULL pointer
as intended.

PR:		standards/138307

Revision 1.186: download - view: text, markup, annotated - select for diffs
Sat Nov 14 09:31:47 2009 UTC (2 years, 2 months ago) by cperciva
Branches: MAIN
Diff to: previous 1.185: preferred, colored
Changes since revision 1.185: +1 -1 lines
SVN rev 199264 on 2009-11-14 09:31:47Z by cperciva

Change the utrace log entry for malloc_init from (0, 0, 0) to (-1, 0, 0)
in order to distinguish it from free(NULL), which is logged as (0, 0, 0).

Reviewed by:	jhb

Revision 1.183.2.4: download - view: text, markup, annotated - select for diffs
Mon Nov 2 18:44:01 2009 UTC (2 years, 3 months ago) by alc
Branches: RELENG_8
Diff to: previous 1.183.2.3: preferred, colored; branchpoint 1.183: preferred, colored
Changes since revision 1.183.2.3: +15 -0 lines
SVN rev 198815 on 2009-11-02 18:44:01Z by alc

MFC r197524
  Make malloc(3) superpage aware.

Revision 1.183.2.3.2.1: download - view: text, markup, annotated - select for diffs
Sun Oct 25 01:10:29 2009 UTC (2 years, 3 months ago) by kensmith
Branches: RELENG_8_0
CVS tags: RELENG_8_0_0_RELEASE
Diff to: previous 1.183.2.3: preferred, colored; next MAIN 1.183.2.4: preferred, colored
Changes since revision 1.183.2.3: +0 -0 lines
SVN rev 198460 on 2009-10-25 01:10:29Z by kensmith

Copy stable/8 to releng/8.0 as part of 8.0-RELEASE release procedure.

Approved by:	re (implicit)

Revision 1.185: download - view: text, markup, annotated - select for diffs
Sat Sep 26 18:20:40 2009 UTC (2 years, 4 months ago) by alc
Branches: MAIN
Diff to: previous 1.184: preferred, colored
Changes since revision 1.184: +15 -0 lines
SVN rev 197524 on 2009-09-26 18:20:40Z by 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

Revision 1.183.2.3: download - view: text, markup, annotated - select for diffs
Sat Sep 12 18:16:46 2009 UTC (2 years, 4 months ago) by kib
Branches: RELENG_8
CVS tags: RELENG_8_0_BP
Branch point for: RELENG_8_0
Diff to: previous 1.183.2.2: preferred, colored; branchpoint 1.183: preferred, colored
Changes since revision 1.183.2.2: +9 -0 lines
SVN rev 197127 on 2009-09-12 18:16:46Z by kib

MFC r196861:
Handle zero size for posix_memalign. Return NULL or unique address
according to the 'V' option.

Approved by:	re (kensmith)

Revision 1.183.2.2: download - view: text, markup, annotated - select for diffs
Thu Sep 10 14:04:00 2009 UTC (2 years, 4 months ago) by kensmith
Branches: RELENG_8
Diff to: previous 1.183.2.1: preferred, colored; branchpoint 1.183: preferred, colored
Changes since revision 1.183.2.1: +1 -1 lines
SVN rev 197065 on 2009-09-10 14:04:00Z by kensmith

Remove extra debugging support that is turned on for head but turned off
for stable branches:

	- shift to MALLOC_PRODUCTION
	- turn off automatic crash dumps
	- Remove kernel debuggers, INVARIANTS*[1], WITNESS* from
	  GENERIC kernel config files[2]

[1] INVARIANTS* left on for ia64 by request marcel
[2] sun4v was left as-is

Reviewed by:	marcel, kib
Approved by:	re (implicit)

Revision 1.184: download - view: text, markup, annotated - select for diffs
Sat Sep 5 13:32:05 2009 UTC (2 years, 5 months ago) by kib
Branches: MAIN
Diff to: previous 1.183: preferred, colored
Changes since revision 1.183: +9 -0 lines
SVN rev 196861 on 2009-09-05 13:32:05Z by kib

Handle zero size for posix_memalign. Return NULL or unique address
according to the 'V' option.

PR:	standards/138307
MFC after:	1 week

Revision 1.183.2.1: download - view: text, markup, annotated - select for diffs
Mon Aug 3 08:13:06 2009 UTC (2 years, 6 months ago) by kensmith
Branches: RELENG_8
Diff to: previous 1.183: preferred, colored
Changes since revision 1.183: +0 -0 lines
SVN rev 196045 on 2009-08-03 08:13:06Z by kensmith

Copy head to stable/8 as part of 8.0 Release cycle.

Approved by:	re (Implicit)

Revision 1.147.2.6.2.2: download - view: text, markup, annotated - select for diffs
Wed Jun 24 05:28:09 2009 UTC (2 years, 7 months ago) by cperciva
Branches: RELENG_7_2
Diff to: previous 1.147.2.6.2.1: preferred, colored; branchpoint 1.147.2.6: preferred, colored; next MAIN 1.147.2.7: preferred, colored
Changes since revision 1.147.2.6.2.1: +37 -11 lines
SVN rev 194808 on 2009-06-24 05:28:09Z by cperciva

MFS r192477: Fix packet length calculation in bce(4). [EN-09:02]

MFS r191867: Correctly set IP packet length for TSO in fxp(4). [EN-09:03]

MFS r191767: Fix a lock order reversal bug that could cause deadlock during
fork(2). [EN-09:04]

Submitted by:	re (kensmith)
Approved by:	so (cperciva)
Errata:		FreeBSD-SA-09:02.bce
Errata:		FreeBSD-SA-09:03.fxp
Errata:		FreeBSD-SA-09:04.fork

Revision 1.147.2.7: download - view: text, markup, annotated - select for diffs
Sun May 3 17:51:38 2009 UTC (2 years, 9 months ago) by kib
Branches: RELENG_7
CVS tags: RELENG_7_4_BP, RELENG_7_3_BP
Branch point for: RELENG_7_4, RELENG_7_3
Diff to: previous 1.147.2.6: preferred, colored; branchpoint 1.147: preferred, colored; next MAIN 1.148: preferred, colored
Changes since revision 1.147.2.6: +37 -11 lines
SVN rev 191767 on 2009-05-03 17:51:38Z by kib

MFC r185514 (by jasone):
Fix a lock order reversal bug that could cause deadlock during fork(2).

Reported and tested by:	makc
Approved by:	re (kensmith)

Revision 1.147.2.6.2.1: download - view: text, markup, annotated - select for diffs
Wed Apr 15 03:14:26 2009 UTC (2 years, 9 months ago) by kensmith
Branches: RELENG_7_2
CVS tags: RELENG_7_2_0_RELEASE
Diff to: previous 1.147.2.6: preferred, colored
Changes since revision 1.147.2.6: +0 -0 lines
SVN rev 191087 on 2009-04-15 03:14:26Z by kensmith

Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.

Approved by:	re (implicit)

Revision 1.147.2.6: download - view: text, markup, annotated - select for diffs
Tue Mar 24 20:57:10 2009 UTC (2 years, 10 months ago) by kib
Branches: RELENG_7
CVS tags: RELENG_7_2_BP
Branch point for: RELENG_7_2
Diff to: previous 1.147.2.5: preferred, colored; branchpoint 1.147: preferred, colored
Changes since revision 1.147.2.5: +11 -0 lines
SVN rev 190393 on 2009-03-24 20:57:10Z by kib

Mostly synchronize  lib/libthr and sys/kern/kern_umtx.c with the code
from HEAD.

Since libkse is still built on RELENG_7, pthread_cleanup_push/pop
are left as the functions, but the support code in libthr is present for
the macro versions.

Malloc in RELENG_7 does not require thread exit hook, but I decided
to add empty handler for it, instead of removing callback from thr_exit().

No mergeinfo since this change is prepared by patching libthr and then
bringing in required missed bits.

Requested by:	bms
Reviewed by:	davidxu
Tested by:	bms, Mykola Dzham <i levsha org ua>
Approved by:	re (kensmith)

Revision 1.183: download - view: text, markup, annotated - select for diffs
Mon Dec 1 10:20:59 2008 UTC (3 years, 2 months ago) by jasone
Branches: MAIN
CVS tags: RELENG_8_BP
Branch point for: RELENG_8
Diff to: previous 1.182: preferred, colored
Changes since revision 1.182: +37 -11 lines
SVN rev 185514 on 2008-12-01 10:20:59Z by jasone

Fix a lock order reversal bug that could cause deadlock during fork(2).

Reported by:	kib

Revision 1.182: download - view: text, markup, annotated - select for diffs
Sun Nov 30 19:30:31 2008 UTC (3 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.181: preferred, colored
Changes since revision 1.181: +1 -1 lines
SVN rev 185483 on 2008-11-30 19:30:31Z by jasone

Adjust an assertion to handle the case where a lock is contested, but
spinning is avoided due to running on a single-CPU system.

Reported by:	stefanf

Revision 1.181: download - view: text, markup, annotated - select for diffs
Sun Nov 30 05:55:24 2008 UTC (3 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.180: preferred, colored
Changes since revision 1.180: +12 -10 lines
SVN rev 185468 on 2008-11-30 05:55:24Z by jasone

Do not spin when trying to lock on a single-CPU system.

Reported by:	davidxu

Revision 1.147.2.5.2.1: download - view: text, markup, annotated - select for diffs
Tue Nov 25 02:59:29 2008 UTC (3 years, 2 months ago) by kensmith
Branches: RELENG_7_1
CVS tags: RELENG_7_1_0_RELEASE
Diff to: previous 1.147.2.5: preferred, colored; next MAIN 1.147.2.6: preferred, colored
Changes since revision 1.147.2.5: +0 -0 lines
SVN rev 185281 on 2008-11-25 02:59:29Z by kensmith

Create releng/7.1 in preparation for moving into RC phase of 7.1 release
cycle.

Approved by:	re (implicit)

Revision 1.147.2.5: download - view: text, markup, annotated - select for diffs
Mon Nov 10 17:30:49 2008 UTC (3 years, 2 months ago) by jasone
Branches: RELENG_7
CVS tags: RELENG_7_1_BP
Branch point for: RELENG_7_1
Diff to: previous 1.147.2.4: preferred, colored; branchpoint 1.147: preferred, colored
Changes since revision 1.147.2.4: +17 -12 lines
SVN rev 184819 on 2008-11-10 17:30:49Z by jasone

MFC:
	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.

Approved by:	re (kib)

Revision 1.180: download - view: text, markup, annotated - select for diffs
Mon Nov 3 21:17:18 2008 UTC (3 years, 3 months ago) by jasone
Branches: MAIN
Diff to: previous 1.179: preferred, colored
Changes since revision 1.179: +17 -12 lines
SVN rev 184602 on 2008-11-03 21:17:18Z by 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

Revision 1.90.2.1.10.1: download - view: text, markup, annotated - select for diffs
Thu Oct 2 02:57:24 2008 UTC (3 years, 4 months ago) by kensmith
Branches: RELENG_6_4
CVS tags: RELENG_6_4_0_RELEASE
Diff to: previous 1.90.2.1: preferred, colored; next MAIN 1.91: preferred, colored
Changes since revision 1.90.2.1: +0 -0 lines
SVN rev 183531 on 2008-10-02 02:57:24Z by kensmith

Create releng/6.4 from stable/6 in preparation for 6.4-RC1.

Approved by:	re (implicit)

Revision 1.179: download - view: text, markup, annotated - select for diffs
Wed Sep 10 14:27:34 2008 UTC (3 years, 4 months ago) by jasone
Branches: MAIN
Diff to: previous 1.178: preferred, colored
Changes since revision 1.178: +88 -120 lines
SVN rev 182906 on 2008-09-10 14:27:34Z by jasone

Use PAGE_{SIZE,MASK,SHIFT} from machine/param.h rather than hard-coding
page size and using sysconf(3).

Suggested by:	marcel

Revision 1.178: download - view: text, markup, annotated - select for diffs
Sat Sep 6 05:26:31 2008 UTC (3 years, 5 months ago) by marcel
Branches: MAIN
Diff to: previous 1.177: preferred, colored
Changes since revision 1.177: +1 -1 lines
SVN rev 182809 on 2008-09-06 05:26:31Z by marcel

Unbreak ia64: pges are 8KB.

Revision 1.177: download - view: text, markup, annotated - select for diffs
Wed Aug 27 02:00:53 2008 UTC (3 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.176: preferred, colored
Changes since revision 1.176: +1080 -231 lines
SVN rev 182225 on 2008-08-27 02:00:53Z by 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.

Revision 1.147.2.4: download - view: text, markup, annotated - select for diffs
Sat Aug 16 20:14:21 2008 UTC (3 years, 5 months ago) by jasone
Branches: RELENG_7
Diff to: previous 1.147.2.3: preferred, colored; branchpoint 1.147: preferred, colored
Changes since revision 1.147.2.3: +339 -398 lines
SVN rev 181788 on 2008-08-16 20:14:21Z by jasone

MFC allocator improvements and fixes:

* Enhance the chunk map to support run coalescing, and substantially reduce
  the number of red-black tree operations performed.

* Remove unused code.

* Fix arena_run_reg_dalloc() to use the entire precomputed division table.

* Improve lock preemption performance for hyperthreaded CPUs.

Revision 1.176: download - view: text, markup, annotated - select for diffs
Thu Aug 14 17:31:42 2008 UTC (3 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.175: preferred, colored
Changes since revision 1.175: +3 -2 lines
SVN rev 181733 on 2008-08-14 17:31:42Z by jasone

Move CPU_SPINWAIT into the innermost spin loop, in order to allow faster
preemption while busy-waiting.

Submitted by:	Mike Schuster <schuster@adobe.com>

Revision 1.175: download - view: text, markup, annotated - select for diffs
Thu Aug 14 17:03:29 2008 UTC (3 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.174: preferred, colored
Changes since revision 1.174: +2 -2 lines
SVN rev 181732 on 2008-08-14 17:03:29Z by jasone

Re-order the terms of an expression in arena_run_reg_dalloc() to correctly
detect whether the integer division table is large enough to handle the
divisor.  Before this change, the last two table elements were never used,
thus causing the slow path to be used for those divisors.

Revision 1.174: download - view: text, markup, annotated - select for diffs
Fri Aug 8 20:42:42 2008 UTC (3 years, 6 months ago) by cperciva
Branches: MAIN
Diff to: previous 1.173: preferred, colored
Changes since revision 1.173: +1 -5 lines
SVN rev 181438 on 2008-08-08 20:42:42Z by cperciva

Remove variables which are assigned values and never used thereafter.

Found by:	LLVM/Clang Static Checker
Approved by:	jasone

Revision 1.173: download - view: text, markup, annotated - select for diffs
Fri Jul 18 19:35:44 2008 UTC (3 years, 6 months ago) by jasone
Branches: MAIN
Diff to: previous 1.172: preferred, colored
Changes since revision 1.172: +336 -392 lines
SVN rev 180599 on 2008-07-18 19:35:44Z by jasone

Enhance arena_chunk_map_t to directly support run coalescing, and use
the chunk map instead of red-black trees where possible.  Remove the
red-black trees and node objects that are obsoleted by this change.  The
net result is a ~1-2% memory savings, and a substantial allocation speed
improvement.

Revision 1.147.2.3: download - view: text, markup, annotated - select for diffs
Mon Jun 16 23:42:05 2008 UTC (3 years, 7 months ago) by jasone
Branches: RELENG_7
Diff to: previous 1.147.2.2: preferred, colored; branchpoint 1.147: preferred, colored
Changes since revision 1.147.2.2: +209 -162 lines
SVN rev 179836 on 2008-06-16 23:42:05Z by jasone

MFC allocator improvements and fixes:

* Implement more compact red-black trees, thus reducing memory usage
  by ~0.5-1%.

* Add a separate tree to track dirty-page-containing chunks, thus
  improving worst case allocation performance.

* Fix a deadlock in base_alloc() for the error (OOM) path.

* Catch integer overflow for huge allocations when using sbrk(2).

* Fix bit vector initialization for run headers.  This fix has no
  practical impact for correct programs.  Incorrect programs will
  potentially experience allocation failures rather than memory
  corruption, both of which are "undefined behavior".

Revision 1.172: download - view: text, markup, annotated - select for diffs
Tue Jun 10 15:46:18 2008 UTC (3 years, 8 months ago) by jasone
Branches: MAIN
Diff to: previous 1.171: preferred, colored
Changes since revision 1.171: +7 -3 lines
SVN rev 179704 on 2008-06-10 15:46:18Z by jasone

In the error path through base_alloc(), release base_mtx [1].

Fix bit vector initialization for run headers.

Submitted by:	[1] Mike Schuster <schuster@adobe.com>

Revision 1.171: download - view: text, markup, annotated - select for diffs
Thu May 1 17:25:55 2008 UTC (3 years, 9 months ago) by jasone
Branches: MAIN
Diff to: previous 1.170: preferred, colored
Changes since revision 1.170: +134 -158 lines
Add a separate tree to track arena chunks that contain dirty pages.
This substantially improves worst case allocation performance, since
O(lg n) tree search can be used instead of O(n) tree iteration.

Use rb_wrap() instead of directly calling rb_*() macros.

Revision 1.170: download - view: text, markup, annotated - select for diffs
Tue Apr 29 22:56:05 2008 UTC (3 years, 9 months ago) by gonzo
Branches: MAIN
Diff to: previous 1.169: preferred, colored
Changes since revision 1.169: +5 -0 lines
  Set QUANTUM_2POW_MIN and SIZEOF_PTR_2POW parameters for MIPS

  Approved by: imp

Revision 1.169: download - view: text, markup, annotated - select for diffs
Tue Apr 29 01:32:42 2008 UTC (3 years, 9 months ago) by jasone
Branches: MAIN
Diff to: previous 1.168: preferred, colored
Changes since revision 1.168: +7 -0 lines
Check for integer overflow before calling sbrk(2), since it uses a
signed increment argument, but the size is an unsigned integer.

Revision 1.168: download - view: text, markup, annotated - select for diffs
Wed Apr 23 16:09:18 2008 UTC (3 years, 9 months ago) by jasone
Branches: MAIN
Diff to: previous 1.167: preferred, colored
Changes since revision 1.167: +171 -116 lines
Implement red-black trees without using parent pointers, and store the
color bit in the least significant bit of the right child pointer, in
order to reduce red-black tree linkage overhead by ~2X as compared to
sys/tree.h.

Use the new red-black tree implementation in malloc, which drops
memory usage by ~0.5 or ~1%, for 32- and 64-bit systems, respectively.

Revision 1.147.2.2: download - view: text, markup, annotated - select for diffs
Fri Mar 7 22:39:38 2008 UTC (3 years, 11 months ago) by jasone
Branches: RELENG_7
Diff to: previous 1.147.2.1: preferred, colored; branchpoint 1.147: preferred, colored
Changes since revision 1.147.2.1: +2283 -1341 lines
MFC: Merge malloc(3) improvements and fixes.  The highlights are:

* Avoid re-zeroing memory in calloc() when possible.

* Use pthread mutexes where possible instead of libc "spinlocks", and
  actually spin some during contention before blocking.

* Implement dynamic load balancing of thread-->arena mapping.

* Avoid floating point math in order to avoid increased context switch
  overhead for applications that otherwise would not use floating point
  math.

* Restructure how sbrk() and mmap() are used to acquire memory mappings.
  This provides a way to force malloc to only use sbrk(), which can be
  useful in the context of resource limits.

* Reduce the number of mmap() calls typically necessary when allocating
  a chunk.

* Track dirty unused pages so that they can be purged if they exceed a
  threshold.

* Try to realloc() large objects in place.

* Manage page runs with trees instead of chunk maps, which allows
  logarithmic-time run allocation.

Revision 1.167: download - view: text, markup, annotated - select for diffs
Fri Mar 7 16:54:03 2008 UTC (3 years, 11 months ago) by jasone
Branches: MAIN
Diff to: previous 1.166: preferred, colored
Changes since revision 1.166: +4 -4 lines
Remove stale #include <machine/atomic.h>, which as needed by lazy
deallocation.

Revision 1.166: download - view: text, markup, annotated - select for diffs
Sun Feb 17 18:34:17 2008 UTC (3 years, 11 months ago) by jasone
Branches: MAIN
Diff to: previous 1.165: preferred, colored
Changes since revision 1.165: +41 -25 lines
Fix a race condition in arena_ralloc() for shrinking in-place large
reallocation, when junk filling is enabled.  Junk filling must occur
prior to shrinking, since any deallocated trailing pages are immediately
available for use by other threads.

Reported by:	Mats Palmgren <mats.palmgren@bredband.net>

Revision 1.165: download - view: text, markup, annotated - select for diffs
Sun Feb 17 17:09:24 2008 UTC (3 years, 11 months ago) by jasone
Branches: MAIN
Diff to: previous 1.164: preferred, colored
Changes since revision 1.164: +3 -209 lines
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.

Revision 1.164: download - view: text, markup, annotated - select for diffs
Fri Feb 8 08:02:34 2008 UTC (4 years ago) by jasone
Branches: MAIN
Diff to: previous 1.163: preferred, colored
Changes since revision 1.163: +10 -7 lines
Fix a bug in lazy deallocation that was introduced when
arena_dalloc_lazy_hard() was split out of arena_dalloc_lazy() in revision
1.162.

Reduce thundering herd problems in lazy deallocation by randomly varying
how many probes a thread does before taking the slow path.

Revision 1.163: download - view: text, markup, annotated - select for diffs
Fri Feb 8 00:35:56 2008 UTC (4 years ago) by jasone
Branches: MAIN
Diff to: previous 1.162: preferred, colored
Changes since revision 1.162: +374 -379 lines
Clean up manipulation of chunk page map elements to remove some tenuous
assumptions about whether bits are set at various times.  This makes
adding other flags safe.

Reorganize functions in order to inline i{m,c,p,s,re}alloc().  This
allows the entire fast-path call chains for malloc() and free() to be
inlined. [1]

Suggested by:	[1] Stuart Parmenter <stuart@mozilla.com>

Revision 1.162: download - view: text, markup, annotated - select for diffs
Wed Feb 6 02:59:54 2008 UTC (4 years ago) by jasone
Branches: MAIN
Diff to: previous 1.161: preferred, colored
Changes since revision 1.161: +960 -668 lines
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.

Revision 1.161: download - view: text, markup, annotated - select for diffs
Thu Jan 3 23:22:13 2008 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.160: preferred, colored
Changes since revision 1.160: +8 -7 lines
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.

Revision 1.160: download - view: text, markup, annotated - select for diffs
Mon Dec 31 06:19:48 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.159: preferred, colored
Changes since revision 1.159: +56 -65 lines
Fix a major chunk-related memory leak in chunk_dealloc_dss_record(). [1]

Clean up DSS-related locking and protect all pertinent variables with
dss_mtx (remove dss_chunks_mtx).  This fixes race conditions that could
cause chunk leaks.

Reported by:	[1] kris

Revision 1.159: download - view: text, markup, annotated - select for diffs
Mon Dec 31 00:59:16 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.158: preferred, colored
Changes since revision 1.158: +268 -186 lines
Fix a bug related to sbrk() calls that could cause address space leaks.
This is a long-standing bug, but until recent changes it was difficult
to trigger, and even then its impact was non-catastrophic, with the
exception of revision 1.157.

Optimize chunk_alloc_mmap() to avoid the need for unmapping pages in the
common case.  Thanks go to Kris Kennaway for a patch that inspired this
change.

Do not maintain a record of previously mmap'ed chunk address ranges.
The original intent was to avoid the extra system call overhead in
chunk_alloc_mmap(), which is no longer a concern.  This also allows some
simplifications for the tree of unused DSS chunks.

Introduce huge_mtx and dss_chunks_mtx to replace chunks_mtx.  There was
no compelling reason to use the same mutex for these disjoint purposes.

Avoid memset() for huge allocations when possible.

Maintain two trees instead of one for tracking unused DSS address
ranges.  This allows scalable allocation of multi-chunk huge objects in
the DSS.  Previously, multi-chunk huge allocation requests failed if the
DSS could not be extended.

Revision 1.158: download - view: text, markup, annotated - select for diffs
Fri Dec 28 09:21:12 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.157: preferred, colored
Changes since revision 1.157: +113 -183 lines
Back out premature commit of previous version.

Revision 1.157: download - view: text, markup, annotated - select for diffs
Fri Dec 28 07:24:19 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.156: preferred, colored
Changes since revision 1.156: +183 -113 lines
Maintain two trees instead of one (old_chunks --> old_chunks_{ad,szad}) in
order to support re-use of multi-chunk unused regions within the DSS for
huge allocations.  This generalization is important to correct function
when mmap-based allocation is disabled.

Avoid zeroing re-used memory in the DSS unless it really needs to be
zeroed.

Revision 1.156: download - view: text, markup, annotated - select for diffs
Fri Dec 28 02:15:08 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.155: preferred, colored
Changes since revision 1.155: +4 -1 lines
Release chunks_mtx for all paths through chunk_dealloc().

Reported by:	kris

Revision 1.155: download - view: text, markup, annotated - select for diffs
Thu Dec 27 23:29:44 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.154: preferred, colored
Changes since revision 1.154: +436 -292 lines
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

Revision 1.154: download - view: text, markup, annotated - select for diffs
Tue Dec 18 05:27:57 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.153: preferred, colored
Changes since revision 1.153: +47 -42 lines
Use fixed point integer math instead of floating point math when
calculating run sizes.  Use of the floating point unit was a potential
pessimization to context switching for applications that do not otherwise
use floating point math. [1]

Reformat cpp macro-related comments to improve consistency.

Submitted by:	das

Revision 1.153: download - view: text, markup, annotated - select for diffs
Mon Dec 17 01:20:04 2007 UTC (4 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.152: preferred, colored
Changes since revision 1.152: +127 -52 lines
Refactor features a bit in order to make it possible to disable lazy
deallocation and dynamic load balancing via the MALLOC_LAZY_FREE and
MALLOC_BALANCE knobs.  This is a non-functional change, since these
features are still enabled when possible.

Clean up a few things that more pedantic compiler settings would cause
complaints over.

Revision 1.152: download - view: text, markup, annotated - select for diffs
Wed Nov 28 00:17:34 2007 UTC (4 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.151: preferred, colored
Changes since revision 1.151: +1 -1 lines
Only zero large allocations when necessary (for calloc()).

Revision 1.151: download - view: text, markup, annotated - select for diffs
Tue Nov 27 03:17:30 2007 UTC (4 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.150: preferred, colored
Changes since revision 1.150: +297 -58 lines
Implement dynamic load balancing of thread-->arena mapping, based on lock
contention.  The intent is to dynamically adjust to load imbalances, which
can cause severe contention.

Use pthread mutexes where possible instead of libc "spinlocks" (they aren't
actually spin locks).  Conceptually, this change is meant only to support
the dynamic load balancing code by enabling the use of spin locks, but it
has the added apparent benefit of substantially improving performance due to
reduced context switches when there is moderate arena lock contention.

Proper tuning parameter configuration for this change is a finicky business,
and it is very much machine-dependent.  One seemingly promising solution
would be to run a tuning program during operating system installation that
computes appropriate settings for load balancing.  (The pthreads adaptive
spin locks should probably be similarly tuned.)

Revision 1.150: download - view: text, markup, annotated - select for diffs
Tue Nov 27 03:13:15 2007 UTC (4 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.149: preferred, colored
Changes since revision 1.149: +218 -0 lines
Implement lazy deallocation of small objects.  For each arena, maintain a
vector of slots for lazily freed objects.  For each deallocation, before
doing the hard work of locking the arena and deallocating, try several times
to randomly insert the object into the vector using atomic operations.

This approach is particularly effective at reducing contention for
multi-threaded applications that use the producer-consumer model, wherein
one producer thread allocates objects, then multiple consumer threads
deallocate those objects.

Revision 1.149: download - view: text, markup, annotated - select for diffs
Tue Nov 27 03:12:15 2007 UTC (4 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.148: preferred, colored
Changes since revision 1.148: +218 -143 lines
Avoid re-zeroing memory in calloc() when possible.

Revision 1.148: download - view: text, markup, annotated - select for diffs
Tue Nov 27 03:09:23 2007 UTC (4 years, 2 months ago) by jasone
Branches: MAIN
Diff to: previous 1.147: preferred, colored
Changes since revision 1.147: +37 -36 lines
Fix stats printing of the amount of memory currently consumed by huge
allocations. [1]

Fix calculation of the number of arenas when 'n' is specified via
MALLOC_OPTIONS.

Clean up various style inconsistencies.

Obtained from:	[1] NetBSD

Revision 1.147.2.1: download - view: text, markup, annotated - select for diffs
Thu Oct 11 06:35:46 2007 UTC (4 years, 4 months ago) by kensmith
Branches: RELENG_7
CVS tags: RELENG_7_0_BP, RELENG_7_0_0_RELEASE, RELENG_7_0
Diff to: previous 1.147: preferred, colored
Changes since revision 1.147: +1 -1 lines
Turn on MALLOC_PRODUCTION which turns off some stuff used for debugging
support.

Reminded by:	kris
Approved by:	re (implicit)

Revision 1.147: download - view: text, markup, annotated - select for diffs
Fri Jun 15 22:00:16 2007 UTC (4 years, 7 months ago) by jasone
Branches: MAIN
CVS tags: RELENG_7_BP
Branch point for: RELENG_7
Diff to: previous 1.146: preferred, colored
Changes since revision 1.146: +48 -36 lines
Fix junk/zero filling for realloc().  Junk filling was missing in one case,
and zero filling was broken in a way that could cause memory corruption.

Update comments.

Revision 1.146: download - view: text, markup, annotated - select for diffs
Thu Mar 29 21:07:17 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.145: preferred, colored
Changes since revision 1.145: +8 -4 lines
Use size_t instead of unsigned for pagesize-related values, in order to
avoid downcasting issues.  In particular, this change fixes
posix_memalign(3) for alignments greater than 2^31 on LP64 systems.

Make sure that NDEBUG is always set to be compatible with MALLOC_DEBUG. [1]

Reported by:	[1] Lee Hyo geol <hyogeollee@gmail.com>

Revision 1.145: download - view: text, markup, annotated - select for diffs
Wed Mar 28 19:55:07 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.144: preferred, colored
Changes since revision 1.144: +221 -432 lines
Remove the run promotion/demotion machinery.  Replace it with red-black
trees that track all non-full runs for each bin.  Use the red-black
trees to be able to guarantee that each new allocation is placed in the
lowest address available in any non-full run.  This change completes the
transition to allocating from low addresses in order to reduce the
retention of sparsely used chunks.

If the run in current use by a bin becomes empty, deallocate the run
rather than retaining it for later use.  The previous behavior had the
tendency to spread empty runs across multiple chunks, thus preventing
the release of chunks that were completely unused.

Generalize base_chunk_alloc() (and rename it to base_pages_alloc()) to
handle allocation sizes larger than the chunk size, so that it is
possible to support chunk sizes that are smaller than an arena object.

Reduce the minimum chunk size from 64kB to 8kB.

Optimize tracking of addresses for deleted chunks.

Fix a statistics bug for huge allocations.

Revision 1.144: download - view: text, markup, annotated - select for diffs
Sat Mar 24 20:44:06 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.143: preferred, colored
Changes since revision 1.143: +43 -18 lines
Fix some subtle bugs for posix_memalign() having to do with integer
rounding and overflow.  Carefully document what the various overflow
tests actually detect.

The bugs mostly canceled out, such that the worst possible failure
cases resulted in non-fatal over-allocations.

Revision 1.143: download - view: text, markup, annotated - select for diffs
Fri Mar 23 22:58:15 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.142: preferred, colored
Changes since revision 1.142: +297 -151 lines
Fix posix_memalign() for large objects.  Now that runs are extents rather
than binary buddies, the alignment guarantees are weaker, which requires
a more complex aligned allocation algorithm, similar to that used for
alignment greater than the chunk size.

Reported by:	matteo

Revision 1.142: download - view: text, markup, annotated - select for diffs
Fri Mar 23 05:05:48 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.141: preferred, colored
Changes since revision 1.141: +337 -328 lines
Use extents rather than binary buddies to track free pages within
chunks.  This allows runs to be any multiple of the page size.  The
primary advantage is that large objects are no longer constrained to be
2^n pages, which can dramatically decrease internal fragmentation for
large objects.  This also allows the sizes for runs that back small
objects to be more finely tuned.

Free runs are searched for linearly using the chunk page map (with the
help of some heuristic optimizations).  This changes the allocation
policy from "first best fit" to "first fit".  A prototype red-black tree
implementation for tracking free runs that implemented "first best fit"
did not cause a measurable speed or memory usage difference for
realistic chunk sizes (though of course it is possible to construct
benchmarks that favor one allocation policy over another).

Refine the handling of fullness constraints for small runs to be more
tunable.

Restructure the per chunk page map to contain only two fields per entry,
rather than four.  Also, increase each entry from 4 to 8 bytes, since it
allows for 32-bit integers, without increasing the number of chunk
header pages.

Relax the maximum chunk size constraint.  This is of no practical
interest; it is merely fallout from the chunk page map restructuring.

Revamp statistics gathering and reporting to be faster, clearer and more
informative.  Statistics gathering is fast enough now to have little
to no impact on application speed, but it still requires approximately
two extra pages of memory per arena (per process).  This memory overhead
may be acceptable for most systems, but we still need to leave
statistics gathering disabled by default in RELENG branches.

Rename NO_MALLOC_EXTRAS to MALLOC_PRODUCTION in order to make its intent
clearer (i.e. it should be defined in RELENG branches).

Revision 1.141: download - view: text, markup, annotated - select for diffs
Tue Mar 20 03:44:10 2007 UTC (4 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.140: preferred, colored
Changes since revision 1.140: +235 -154 lines
Avoid using vsnprintf(3) unless MALLOC_STATS is defined, in order to
avoid substantial potential bloat for static binaries that do not
otherwise use any printf(3)-family functions. [1]

Rearrange arena_run_t so that the region bitmask can be minimally sized
according to constraints related to each bin's size class.  Previously,
the region bitmask was the same size for all run headers, which wasted
a measurable amount of memory.

Rather than making runs for small objects as large as possible, make
runs as small as possible such that header overhead stays below a
certain bound.  There are two exceptions that override the header
overhead bound:

	1) If the bound is impossible to honor, it is relaxed on a
	   per-size-class basis.  Since there is one bit of header
	   overhead per object (plus a constant), it is impossible to
	   achieve a header overhead less than or equal to 1/(# of bits
	   per object).  For the current setting of maximum 0.5% header
	   overhead, this relaxation comes into play for {2, 4, 8,
	   16}-byte objects, for which header overhead is (on 64-bit
	   systems) {7.1, 4.3, 2.2, 1.2}%, respectively.

	2) There is still a cap on small run size, still set to 64kB.
	   This comes into play for {1024, 2048}-byte objects, for which
	   header overhead is {1.6, 3.1}%, respectively.

In practice, this reduces the run sizes, which makes worst case
low-water memory usage due to fragmentation less bad.  It also reduces
worst case high-water run fragmentation due to non-full runs, but this
is only a constant improvement (most important to small short-lived
processes).

Reduce the default chunk size from 2MB to 1MB.  Benchmarks indicate that
the external fragmentation reduction makes 1MB the new sweet spot (as
small as possible without adversely affecting performance).

Reported by:	[1] kientzle

Revision 1.140: download - view: text, markup, annotated - select for diffs
Thu Feb 22 19:10:30 2007 UTC (4 years, 11 months ago) by jasone
Branches: MAIN
Diff to: previous 1.139: preferred, colored
Changes since revision 1.139: +40 -36 lines
Modify chunk_alloc() to prefer mmap()ed memory over sbrk()ed memory.
This has no impact unless USE_BRK is defined (32-bit platforms), in
which case user allocations are allocated via mmap() if at all possible,
in order to avoid the possibility of unreclaimable chunks in the data
segment.

Fix an obscure bug in base_alloc() that could have allowed undefined
behavior if an application were to use sbrk() in conjunction with a
USE_BRK-enabled malloc.

Revision 1.139: download - view: text, markup, annotated - select for diffs
Wed Jan 31 22:54:19 2007 UTC (5 years ago) by jasone
Branches: MAIN
Diff to: previous 1.138: preferred, colored
Changes since revision 1.138: +56 -44 lines
Fix a utrace(2)-related bug in calloc(3).

Integrate various pedantic cleanups.

Submitted by:	Andrew Doran <ad@netbsd.org>

Revision 1.138: download - view: text, markup, annotated - select for diffs
Sat Dec 23 00:18:51 2006 UTC (5 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.137: preferred, colored
Changes since revision 1.137: +86 -51 lines
Implement chunk allocation/deallocation hysteresis by caching one spare
chunk per arena, rather than immediately deallocating all unused chunks.
This fixes a potential performance issue when allocating/deallocating
an object of size (4kB..1MB] in a loop.

Reported by:	davidxu

Revision 1.137: download - view: text, markup, annotated - select for diffs
Fri Sep 8 17:52:15 2006 UTC (5 years, 5 months ago) by jasone
Branches: MAIN
Diff to: previous 1.136: preferred, colored
Changes since revision 1.136: +93 -56 lines
Change the way base allocation is done for internal malloc data
structures, in order to avoid the possibility of attempted recursive
lock acquisition for chunks_mtx.

Reported by:	Slawa Olhovchenkov <slw@zxy.spb.ru>

Revision 1.136: download - view: text, markup, annotated - select for diffs
Fri Sep 1 19:14:14 2006 UTC (5 years, 5 months ago) by marcel
Branches: MAIN
Diff to: previous 1.135: preferred, colored
Changes since revision 1.135: +0 -1 lines
Enable TLS on PowerPC.

Revision 1.135: download - view: text, markup, annotated - select for diffs
Fri Sep 1 06:18:43 2006 UTC (5 years, 5 months ago) by marcel
Branches: MAIN
Diff to: previous 1.134: preferred, colored
Changes since revision 1.134: +0 -1 lines
Enable TLS on ia64.

Revision 1.134: download - view: text, markup, annotated - select for diffs
Sun Aug 13 21:54:47 2006 UTC (5 years, 5 months ago) by cperciva
Branches: MAIN
Diff to: previous 1.133: preferred, colored
Changes since revision 1.133: +1 -1 lines
Correctly handle the case in calloc(num, size) where
  (size_t)(num * size) == 0
but both num and size are nonzero.

Reported by:	Ilja van Sprundel
Approved by:	jasone
Security:	Integer overflow; calloc was allocating 1 byte in
		response to a request for a multiple of 2^32 (or 2^64)
		bytes instead of returning NULL.

Revision 1.133: download - view: text, markup, annotated - select for diffs
Wed Aug 9 19:01:27 2006 UTC (5 years, 6 months ago) by marcel
Branches: MAIN
Diff to: previous 1.132: preferred, colored
Changes since revision 1.132: +1 -0 lines
Define NO_TLS on PowerPC.

See also: PR ia64/91846

Revision 1.132: download - view: text, markup, annotated - select for diffs
Thu Jul 27 19:09:32 2006 UTC (5 years, 6 months ago) by jasone
Branches: MAIN
Diff to: previous 1.131: preferred, colored
Changes since revision 1.131: +12 -1 lines
Conditionally expand the size_invs lookup table in arena_run_reg_dalloc()
so that architectures with a quantum of 8 (rather than 16) work.

Restore arm's quantum to 8.

Submitted by:	jmg

Revision 1.131: download - view: text, markup, annotated - select for diffs
Thu Jul 27 14:36:28 2006 UTC (5 years, 6 months ago) by cognet
Branches: MAIN
Diff to: previous 1.130: preferred, colored
Changes since revision 1.130: +1 -1 lines
Use 4 as QUANTUM_2POW_MIN on arm as it is on any other architecture, to avoid
triggering an assertion later.

Revision 1.130: download - view: text, markup, annotated - select for diffs
Thu Jul 27 04:00:12 2006 UTC (5 years, 6 months ago) by jasone
Branches: MAIN
Diff to: previous 1.129: preferred, colored
Changes since revision 1.129: +19 -23 lines
Fix cpp logic in arena_malloc() to adjust size when assertions are enabled,
even if stats gathering is disabled. [1]

Remove 'size' parameter from several functions that do not use it.

Reported by:	[1] ache

Revision 1.129: download - view: text, markup, annotated - select for diffs
Sat Jul 1 16:51:10 2006 UTC (5 years, 7 months ago) by jasone
Branches: MAIN
Diff to: previous 1.128: preferred, colored
Changes since revision 1.128: +90 -83 lines
Use some math tricks in arena_run_reg_dalloc() to avoid actual division, as
well as avoiding a switch statement.  This change has no significant impact
to performance when branch prediction is successful at predicting the sizes
of objects passed to free(), but in the case that the object sizes are
semi-random, this change has the potential to prevent many branch prediction
misses, thus improving performance substantially.

Take advantage of alignment guarantees in ipalloc(), and pad object sizes to
something less than a power of two when possible.  This has the potential
to substantially reduce internal fragmentation for objects allocated via
posix_memalign().

Avoid an unnecessary pow2_ceil() call in arena_ralloc().

Submitted by:	djam8193ah@hotmail.com

Revision 1.128: download - view: text, markup, annotated - select for diffs
Fri Jun 30 20:54:15 2006 UTC (5 years, 7 months ago) by jasone
Branches: MAIN
Diff to: previous 1.127: preferred, colored
Changes since revision 1.127: +46 -48 lines
Make the behavior of malloc(0) standards-compliant by getting rid of nil,
and instead creating a small allocation for each malloc(0) call.  The
optional SysV compatibility behavior remains unchanged.

Add a couple of assertions.

Fix a couple of typos in error message strings.

Revision 1.127: download - view: text, markup, annotated - select for diffs
Tue Jun 20 20:38:25 2006 UTC (5 years, 7 months ago) by jasone
Branches: MAIN
Diff to: previous 1.126: preferred, colored
Changes since revision 1.126: +20 -8 lines
Add a missing case for the switch statement in arena_run_reg_dalloc(). [1]

Fix a leak in chunk_dealloc(). [2]

Reported by:	[1] djam8193ah@hotmail.com,
		[2] Ville-Pertti Keinonen <will@exomi.com>

Revision 1.126: download - view: text, markup, annotated - select for diffs
Wed May 10 00:07:45 2006 UTC (5 years, 9 months ago) by jasone
Branches: MAIN
Diff to: previous 1.125: preferred, colored
Changes since revision 1.125: +2 -2 lines
Increase the minimum chunk size by a power of two (32kB --> 64kB, assuming
4kB pages), in order to avoid dangerous rounding error when calculating
fullness limits during run promotion/demotion.

Convert a structure bitfield to a normal field in areana_run_t.  This should
have been changed along with the other fields in revision 1.120.

Revision 1.125: download - view: text, markup, annotated - select for diffs
Thu Apr 27 01:03:00 2006 UTC (5 years, 9 months ago) by jasone
Branches: MAIN
Diff to: previous 1.124: preferred, colored
Changes since revision 1.124: +83 -71 lines
Change the semantics of brk_max to dynamically deal with data segment
bounds. [1]

Modify logic for utilizing the data segment, such that it is possible to
create huge allocations there.

Shrink the data segment when deallocating a chunk, if it is at the end of
the data segment.

Rename chunk_size to csize in huge_malloc(), in order to avoid masking a
static variable of the same name. [1]

Reported by:	Paul Allen <nospam@ugcs.caltech.edu>

Revision 1.124: download - view: text, markup, annotated - select for diffs
Wed Apr 5 18:46:24 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.123: preferred, colored
Changes since revision 1.123: +1 -0 lines
Add an unreachable return statement, in order to avoid a compiler warning
for non-standard optimization levels.

Reported by:	Michael Zach <zach@webges.com>

Revision 1.123: download - view: text, markup, annotated - select for diffs
Wed Apr 5 04:15:12 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.122: preferred, colored
Changes since revision 1.122: +16 -31 lines
Only initialize the first per-chunk page map element for free runs.  This
makes run split/coalesce operations of complexity lg(n) rather than n.

Revision 1.122: download - view: text, markup, annotated - select for diffs
Tue Apr 4 19:46:28 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.121: preferred, colored
Changes since revision 1.121: +21 -8 lines
Add init_lock, and use it to protect against allocator initialization
races.  This isn't currently necessary for libpthread or libthr, but
without it external threads libraries like the linuxthreads port are
not safe to use.

Reported by:	ganbold@micom.mng.net

Revision 1.121: download - view: text, markup, annotated - select for diffs
Tue Apr 4 03:51:47 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.120: preferred, colored
Changes since revision 1.120: +131 -69 lines
Refactor per-run bitmap manipulation functions so that bitmap offsets only
have to be calculated once per allocator operation.

Make nil const.

Update various comments.

Remove/avoid division where possible.

For the one division operation that remains in the critical path, add a
switch statement that has a case for each small size class, and do division
with a constant divisor in each case.  This allows the compiler to generate
optimized code that does not use hardware division [1].

Obtained from:	peter [1]

Revision 1.120: download - view: text, markup, annotated - select for diffs
Thu Mar 30 20:25:52 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.119: preferred, colored
Changes since revision 1.119: +294 -285 lines
Optimize runtime performance, primary using the following techniques:

  * Avoid choosing an arena until it's certain that an arena is needed
    for allocation.

  * Convert division/multiplication to bitshifting where possible.

  * Avoid accessing TLS variables in single-threaded code.

  * Reduce the amount of pointer dereferencing.

  * Move lock acquisition in critical paths to only protect the the code
    that requires synchronization, and completely remove locking where
    possible.

Revision 1.119: download - view: text, markup, annotated - select for diffs
Tue Mar 28 22:16:04 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.118: preferred, colored
Changes since revision 1.118: +20 -0 lines
Add malloc_usable_size(3).

Discussed with:		arch@

Revision 1.118: download - view: text, markup, annotated - select for diffs
Sun Mar 26 23:41:35 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.117: preferred, colored
Changes since revision 1.117: +16 -2 lines
Allow the 'n' option to decrease the number of arenas below the default,
to as little as one arena.  Also, limit the number of arenas to avoid a
potential invariant violation in base_alloc().

Revision 1.117: download - view: text, markup, annotated - select for diffs
Sun Mar 26 23:37:25 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.116: preferred, colored
Changes since revision 1.116: +224 -208 lines
Add comments and reformat/rearrange code.  There are no significant
functional changes in this commit.

Revision 1.116: download - view: text, markup, annotated - select for diffs
Fri Mar 24 22:13:49 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.115: preferred, colored
Changes since revision 1.115: +37 -21 lines
Convert TINY_MIN_2POW from a cpp macro to tiny_min_2pow (a variable), and
determine its value at run time according to other relevant values.  This
avoids the creation of runs that are incompletely utilized, as long as
pagesize isn't too large (>32kB, given the current RUN_MIN_REGS_2POW
setting).

Increase the size of several structure bitfields in arena_run_t in order
to avoid integer overflow in the case that a run's header does not overlap
with the space that is usable as application allocation regions.  Given
the tiny_min_2pow change, this fix has no additional impact unless
pagesize is >32kB.

Reported by:	kris

Revision 1.115: download - view: text, markup, annotated - select for diffs
Fri Mar 24 00:28:08 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.114: preferred, colored
Changes since revision 1.114: +110 -65 lines
Add USE_BRK-specific code in malloc_init_hard() to allow the first
internally used chunk to start at the beginning of the heap, rather
than at a chunk-aligned address.  This reduces mapped memory somewhat
for 32-bit architectures.

Add the arena_run_link_t type and use it wherever a run object is only
used as a ring 'header'.  This saves approximately 40 kB of memory per
arena.

Remove an obsolete (no longer used) code path from base_alloc(), which
supported the internal allocation of objects larger than the chunk
size.

Enhance chunk_dealloc() to cache chunk addresses for all deallocated
chunks.  This has no impact for most programs, but has the potential
to reduce VM map fragmentation for programs that use huge
allocations.

Revision 1.114: download - view: text, markup, annotated - select for diffs
Mon Mar 20 04:05:05 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.113: preferred, colored
Changes since revision 1.113: +72 -62 lines
Separate completely full runs from runs that are merely almost full, so
that no linear searching is necessary if we resort to allocating from a
run that is known to be mostly full.  There are pathological edge cases
that could have caused severely degraded performance, and this change
fixes that.

Revision 1.113: download - view: text, markup, annotated - select for diffs
Sun Mar 19 18:28:06 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.112: preferred, colored
Changes since revision 1.112: +167 -105 lines
Optimize realloc() to reallocate in place if the old and new sizes are
close enough to each other that reallocation would allocate a new region
of the same size.  This improves the performance of repeated incremental
reallocations by up to three orders of magnitude. [1]

Fix arena_new() to properly constrain run size if a small chunk size was
specified during runtime configuration.

Suggested by:	se [1]

Revision 1.112: download - view: text, markup, annotated - select for diffs
Fri Mar 17 09:00:27 2006 UTC (5 years, 10 months ago) by jasone
Branches: MAIN
Diff to: previous 1.111: preferred, colored
Changes since revision 1.111: +1064 -2499 lines
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.

Revision 1.111: download - view: text, markup, annotated - select for diffs
Sat Feb 4 01:11:30 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.110: preferred, colored
Changes since revision 1.110: +1 -1 lines
Fix calculation of the number of arenas to use on multi-processor systems.

Revision 1.110: download - view: text, markup, annotated - select for diffs
Fri Jan 27 07:46:22 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.109: preferred, colored
Changes since revision 1.109: +151 -201 lines
Remove unwarranted uses of 'goto'.

Revision 1.109: download - view: text, markup, annotated - select for diffs
Fri Jan 27 04:42:10 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.108: preferred, colored
Changes since revision 1.108: +16 -3 lines
Add NO_MALLOC_EXTRAS, so that various extra features that can cause
performance degradation can be disabled via something like the following
in /etc/malloc.conf:

	CFLAGS+=-DNO_MALLOC_EXTRAS

Suggested by:	deischen

Revision 1.108: download - view: text, markup, annotated - select for diffs
Fri Jan 27 04:36:39 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.107: preferred, colored
Changes since revision 1.107: +1 -1 lines
Fix the type of a statistics counter (unsigned --> unsigned long).

Revision 1.107: download - view: text, markup, annotated - select for diffs
Fri Jan 27 02:36:44 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.106: preferred, colored
Changes since revision 1.106: +64 -71 lines
Clean up statistics gathering and printing.

Revision 1.106: download - view: text, markup, annotated - select for diffs
Thu Jan 26 08:11:23 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.105: preferred, colored
Changes since revision 1.105: +10 -13 lines
Optimize arena_bin_pop() to reduce the number of separator operations.
Remove the block of code that tries to use delayed regions in LIFO order,
since from a policy perspective, it conflicts with LRU caching of newly
coalesced regions in arena_undelay().  There are numerous policy
alternatives, and it isn't readily obvious which (if any) is superior;
this change at least has the virtue of being consistent with policy.

Revision 1.105: download - view: text, markup, annotated - select for diffs
Wed Jan 25 05:41:02 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.104: preferred, colored
Changes since revision 1.104: +0 -1 lines
Remove a redundant variable assignment in arena_reg_frag_alloc().

Revision 1.104: download - view: text, markup, annotated - select for diffs
Wed Jan 25 04:21:22 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.103: preferred, colored
Changes since revision 1.103: +184 -171 lines
If no coalesced exact-fit small regions are available, but delayed exact-
fit regions are available, use the delayed regions in LIFO order, in order
to increase locality of reference.  We might expect this to cause delayed
regions to be removed from the delay ring buffer more often (since we're
now re-using more recently buffered regions), but numerous tests indicate
that the overall impact on memory usage tends to be good (reduced
fragmentation).

Re-work arena_frag_reg_alloc() so that when large free regions are
exhausted, it uses small regions in a way that favors contiguous allocation
of sequentially allocated small regions.  Use arena_frag_reg_alloc() in
this capacity, rather than directly attempting over-fitting of small
requests when no large regions are available.

Remove the bin overfit statistic, since it is no longer relevant due to
the arena_frag_reg_alloc() changes.

Do not specify arena_frag_reg_alloc() as an inline function.  It is too
large to benefit much from being inlined, and it is also called in two
places, only one of which is in the critical path (the other call bloated
arena_reg_alloc()).

Call arena_coalesce() for a region before caching it with
arena_mru_cache().

Add assertions that detect the attempted caching of adjacent free regions,
so that we notice this problem when it is first created, rather than in
arena_coalesce(), when it's too late to know how the problem arose.

Reported by:    Hans Blancke

Revision 1.103: download - view: text, markup, annotated - select for diffs
Mon Jan 23 03:32:38 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.102: preferred, colored
Changes since revision 1.102: +2 -2 lines
Make the 'C' and 'c' malloc options consistent with other options; 'C'
doubles the cache size, and 'c' halves the cache size.

Revision 1.102: download - view: text, markup, annotated - select for diffs
Mon Jan 23 03:19:01 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.101: preferred, colored
Changes since revision 1.101: +24 -7 lines
In arena_chunk_reg_alloc(), try to avoid touching the last page in the
chunk during initialization, in order to avoid physically backing the
page unless data are allocated there.

Revision 1.101: download - view: text, markup, annotated - select for diffs
Fri Jan 20 03:11:11 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.100: preferred, colored
Changes since revision 1.100: +45 -44 lines
Use uintptr_t rather than size_t when casting pointers to integers.  Also,
fix the few remaining casting style(9) errors that remained after the
functional change.

Reported by:	jmallett

Revision 1.100: download - view: text, markup, annotated - select for diffs
Thu Jan 19 19:20:42 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.99: preferred, colored
Changes since revision 1.99: +0 -7 lines
Revert addtion of assertions in revision 1.99.  These assertions cause
problems in cases where regions are faked up for the purposes of red-black
tree searches, since those faked region headers reside on the stack, rather
than in a malloc chunk.

Revision 1.99: download - view: text, markup, annotated - select for diffs
Thu Jan 19 19:08:11 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.98: preferred, colored
Changes since revision 1.98: +7 -0 lines
Add assertions that detect some forms of region separator corruption.

Revision 1.98: download - view: text, markup, annotated - select for diffs
Thu Jan 19 18:37:30 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.97: preferred, colored
Changes since revision 1.97: +5 -4 lines
Remove loops in arena_coalesce().  They are no longer necessary, now that
internal allocation does not rely on recursive arena use (base_arena was
removed in revision 1.95).

Revision 1.97: download - view: text, markup, annotated - select for diffs
Thu Jan 19 07:23:13 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.96: preferred, colored
Changes since revision 1.96: +15 -12 lines
Make all internal variables and functions static.

Reported by:	ache

Revision 1.96: download - view: text, markup, annotated - select for diffs
Thu Jan 19 02:11:05 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.95: preferred, colored
Changes since revision 1.95: +50 -35 lines
Return NULL if there is an OOM error during initialization, rather than
allowing the error to be fatal.

Move a label in order to make sure to properly handle errors in malloc(0).

Reported by:	Alastair D'Silva, Saneto Takanori

Revision 1.95: download - view: text, markup, annotated - select for diffs
Mon Jan 16 05:13:49 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.94: preferred, colored
Changes since revision 1.94: +175 -151 lines
Add a separate simple internal base allocator and remove base_arena, so that
there is never any need to recursively call the main allocation functions.

Remove recursive spinlock support, since it is no longer needed.

Allow chunks to be as small as the page size.

Correctly propagate OOM errors from arena_new().

Revision 1.94: download - view: text, markup, annotated - select for diffs
Mon Jan 16 00:32:46 2006 UTC (6 years ago) by marcel
Branches: MAIN
Diff to: previous 1.93: preferred, colored
Changes since revision 1.93: +1 -0 lines
Define NO_TLS on ia64. The dynamic TLS implementation on ia64 is
broken for non-threaded shared processes in that __tls_get_addr()
assumes the thread pointer is always initialized. This is not the
case. When arenas_map is referenced in choose_arena() and it is
defined as a thread-local variable, it will result in a SIGSEGV.

PR: ia64/91846 (describes the TLS/ia64 bug).

Revision 1.93: download - view: text, markup, annotated - select for diffs
Fri Jan 13 18:38:56 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.92: preferred, colored
Changes since revision 1.92: +4505 -951 lines
Replace malloc(), calloc(), posix_memalign(), realloc(), and free() with
a scalable concurrent allocator implementation.

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

Revision 1.92: download - view: text, markup, annotated - select for diffs
Thu Jan 12 18:09:25 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.91: preferred, colored
Changes since revision 1.91: +2 -2 lines
Fix a bitwise logic error in posix_memalign().

Reported by:	glebius

Revision 1.91: download - view: text, markup, annotated - select for diffs
Thu Jan 12 07:28:20 2006 UTC (6 years ago) by jasone
Branches: MAIN
Diff to: previous 1.90: preferred, colored
Changes since revision 1.90: +64 -0 lines
In preparation for a new malloc implementation:

  * Add posix_memalign().

  * Move calloc() from calloc.c to malloc.c.  Add a calloc() implementation in
    rtld-elf in order to make the loader happy (even though calloc() isn't
    used in rtld-elf).

  * Add _malloc_prefork() and _malloc_postfork(), and use them instead of
    directly manipulating __malloc_lock.

Approved by:	phk, markm (mentor)

Revision 1.90.2.1: download - view: text, markup, annotated - select for diffs
Sun Sep 18 03:45:24 2005 UTC (6 years, 4 months ago) by scottl
Branches: RELENG_6
CVS tags: RELENG_6_4_BP, RELENG_6_3_BP, RELENG_6_3_0_RELEASE, RELENG_6_3, RELENG_6_2_BP, RELENG_6_2_0_RELEASE, RELENG_6_2, RELENG_6_1_BP, RELENG_6_1_0_RELEASE, RELENG_6_1, RELENG_6_0_BP, RELENG_6_0_0_RELEASE, RELENG_6_0
Branch point for: RELENG_6_4
Diff to: previous 1.90: preferred, colored; next MAIN 1.91: preferred, colored
Changes since revision 1.90: +2 -2 lines
Take a step closer to the release and turn off malloc debugging.

Approved by: re (implicit)

Revision 1.90: download - view: text, markup, annotated - select for diffs
Sun Feb 27 17:16:16 2005 UTC (6 years, 11 months ago) by delphij
Branches: MAIN
CVS tags: RELENG_6_BP
Branch point for: RELENG_6
Diff to: previous 1.89: preferred, colored
Changes since revision 1.89: +0 -2 lines
Remove the check about whether MALLOC_EXTRA_SANITY is defined,
surrounding the undef'ing it.  It does not seem necessary to
undef some symbol that is not exist, and gcc does not complain
about whether a symbol is exist before #undef'ing it out.

Spotted by:	mingyanguo via ChinaUnix.net forum
Reviewed by:	phk

Revision 1.89.2.1: download - view: text, markup, annotated - select for diffs
Tue Sep 7 15:38:34 2004 UTC (7 years, 5 months ago) by scottl
Branches: RELENG_5
CVS tags: RELENG_5_5_BP, RELENG_5_5_0_RELEASE, RELENG_5_5, RELENG_5_4_BP, RELENG_5_4_0_RELEASE, RELENG_5_4, RELENG_5_3_BP, RELENG_5_3_0_RELEASE, RELENG_5_3
Diff to: previous 1.89: preferred, colored; next MAIN 1.90: preferred, colored
Changes since revision 1.89: +2 -2 lines
Turn off malloc debugging for RELENG_5.  This is intended to be off for the
remainder of the RELENG_5/5-STABLE lifespan.  It remains on in HEAD/6-CURRENT.

Approved by: re

Revision 1.89: download - view: text, markup, annotated - select for diffs
Sun Jul 4 16:11:01 2004 UTC (7 years, 7 months ago) by stefanf
Branches: MAIN
CVS tags: RELENG_5_BP
Branch point for: RELENG_5
Diff to: previous 1.88: preferred, colored
Changes since revision 1.88: +3 -3 lines
Consistently use __inline instead of __inline__ as the former is an empty macro
in <sys/cdefs.h> for compilers without support for inline.

Revision 1.88: download - view: text, markup, annotated - select for diffs
Fri May 14 11:50:51 2004 UTC (7 years, 8 months ago) by cognet
Branches: MAIN
Diff to: previous 1.87: preferred, colored
Changes since revision 1.87: +4 -0 lines
Define malloc_pageshift and malloc_minsize for arm.

Revision 1.49.2.5: download - view: text, markup, annotated - select for diffs
Tue Apr 20 14:43:25 2004 UTC (7 years, 9 months ago) by kensmith
Branches: RELENG_4
CVS tags: RELENG_4_11_BP, RELENG_4_11_0_RELEASE, RELENG_4_11, RELENG_4_10_BP, RELENG_4_10_0_RELEASE, RELENG_4_10
Diff to: previous 1.49.2.4: preferred, colored; branchpoint 1.49: preferred, colored; next MAIN 1.50: preferred, colored
Changes since revision 1.49.2.4: +2 -0 lines
This is a partial MFC of 1.74.  From the CVS log for that:

	revision 1.74
	date: 2003/01/30 15:00:17;  author: phk;  state: Exp;  lines: +4 -0
	Catch some cases where asking for ridiculously large allocations could
	result in a segfault.  Instead just return NULL.

Requested by:	JINMEI Tatuya <jinmei (at) isl.rdc.toshiba.co.jp> and so@
Reviewed by:	phk (but he's not responsible if this makes 4.10 go boom :-)
Approved by:	re (scottl)

Revision 1.87: download - view: text, markup, annotated - select for diffs
Sun Mar 7 20:41:27 2004 UTC (7 years, 11 months ago) by phk
Branches: MAIN
Diff to: previous 1.86: preferred, colored
Changes since revision 1.86: +13 -19 lines
Rearrange (centralize) initialization of mallocs internals to always be
done before the first call, even if this is a malloc(0) call.

PR:	62859

Revision 1.86: download - view: text, markup, annotated - select for diffs
Sat Feb 21 09:14:38 2004 UTC (7 years, 11 months ago) by phk
Branches: MAIN
Diff to: previous 1.85: preferred, colored
Changes since revision 1.85: +49 -70 lines
Remove the triplicity in the public functions by vectoring them all
through a realloc like function.

Make the malloc_active variable a local static to this new function.

Don't warn about recursion more than once per base call.

constify malloc_func.

Revision 1.85: download - view: text, markup, annotated - select for diffs
Sat Feb 21 08:55:38 2004 UTC (7 years, 11 months ago) by phk
Branches: MAIN
Diff to: previous 1.84: preferred, colored
Changes since revision 1.84: +7 -14 lines
Move the check for sensitive processes to the point where the exception
has been hit, this makes it cover more cases.

Call the message function directly rather than fiddle with flag-saving
when we find an unknown character in our options.

The 'A' flag should not trigger on legal out of memory conditions.

Revision 1.84.2.1: download - view: text, markup, annotated - select for diffs
Sun Dec 7 04:12:46 2003 UTC (8 years, 2 months ago) by scottl
Branches: RELENG_5_2
CVS tags: RELENG_5_2_1_RELEASE, RELENG_5_2_0_RELEASE
Diff to: previous 1.84: preferred, colored; next MAIN 1.85: preferred, colored
Changes since revision 1.84: +2 -2 lines
Remove malloc debugging for the release.

Revision 1.84: download - view: text, markup, annotated - select for diffs
Fri Nov 28 18:03:22 2003 UTC (8 years, 2 months ago) by marcel
Branches: MAIN
CVS tags: RELENG_5_2_BP
Branch point for: RELENG_5_2
Diff to: previous 1.83: preferred, colored
Changes since revision 1.83: +2 -8 lines
Do not adjust to the pagesize at runtime. Besides for the one-time
initialization overhead, there's a problem in that we never call
imalloc() and thus malloc_init() for zero-sized allocations. As a
result, malloc(0) returns NULL when it's the first or only malloc in
the program. Any non-zero allocation will initialize the malloc code
with the side-effect that subsequent zero-sized allocations return a
non-NULL pointer. This is because the pointer we return for zero-
sized allocations is calculated from malloc_pageshift, which needs
to be initialized at runtime on ia64.

The result of the inconsistent behaviour described above is that
configure scripts failed the test for a GNU compatible malloc. This
resulted in a lot of broken ports.

Other, even simpler, solutions were possible as well:
1.  initialize malloc_pageshift with some non-zero value (say 13 for
    8KB pages) and keep the runtime adjustment.
2.  Stop using malloc_pageshift to calculate ZEROSIZEPTR.

Removal of the runtime adjustment was chosen because then ia64 is the
same as any other platform. It is not to say that using a page size
obtained at runtime is bad per se. It's that there's currently a high
level of gratuity for its existence and the moment it causes problems
is the moment you need to get rid of it. Hence, it's not unthinkable
that this commit is (partially) reverted some time in the future when
we do have a good reason for it and a good way to achieve it.

Approved by: re@ (rwatson)
Reported by: kris (portmgr@) -- may the ports be with you

Revision 1.83: download - view: text, markup, annotated - select for diffs
Tue Nov 4 19:49:56 2003 UTC (8 years, 3 months ago) by deischen
Branches: MAIN
Diff to: previous 1.82: preferred, colored
Changes since revision 1.82: +1 -0 lines
Externalize malloc's spinlock so that a thread library can take
it around an application's fork() call.  Our new thread libraries
(libthr, libpthread) can now have threads running while another
thread calls fork().  In this case, it is possible for malloc
to be left in an inconsistent state in the child.  Our thread
libraries, libpthread in particular, need to use malloc internally
after a fork (in the child).

Reviewed by:	davidxu

Revision 1.82: download - view: text, markup, annotated - select for diffs
Wed Oct 29 10:45:01 2003 UTC (8 years, 3 months ago) by tjr
Branches: MAIN
Diff to: previous 1.81: preferred, colored
Changes since revision 1.81: +1 -3 lines
Remove incomplete support for running FreeBSD userland on old NetBSD kernels
lacking the issetugid() and utrace() syscalls.

Revision 1.81: download - view: text, markup, annotated - select for diffs
Sat Oct 25 23:47:33 2003 UTC (8 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.80: preferred, colored
Changes since revision 1.80: +3 -3 lines
Consistently cast to (u_char *) when filling with junk.

Revision 1.80: download - view: text, markup, annotated - select for diffs
Sat Oct 25 12:56:51 2003 UTC (8 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.79: preferred, colored
Changes since revision 1.79: +60 -61 lines
Style changes.  Inching closer to convergence with OpenBSD.

Revision 1.79: download - view: text, markup, annotated - select for diffs
Sat Sep 27 18:58:26 2003 UTC (8 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.78: preferred, colored
Changes since revision 1.78: +54 -46 lines
More style fixes to improve diffability with OpenBSD.

Pull 'A' evilness for realloc(3) from OpenBSD.

Revision 1.78: download - view: text, markup, annotated - select for diffs
Sat Sep 27 17:29:03 2003 UTC (8 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.77: preferred, colored
Changes since revision 1.77: +91 -91 lines
Style changes to improve diffability against OpenBSD version.

Revision 1.77: download - view: text, markup, annotated - select for diffs
Tue Jul 29 11:16:14 2003 UTC (8 years, 6 months ago) by phk
Branches: MAIN
Diff to: previous 1.76: preferred, colored
Changes since revision 1.76: +2 -2 lines
Minor constification.

Revision 1.76: download - view: text, markup, annotated - select for diffs
Sun Jun 1 09:16:50 2003 UTC (8 years, 8 months ago) by phk
Branches: MAIN
Diff to: previous 1.75: preferred, colored
Changes since revision 1.75: +2 -1 lines
Clarify the code a bit.

Submitted by:	Nadav Eiron <nadav@TheEirons.org>

Revision 1.75.2.1: download - view: text, markup, annotated - select for diffs
Sat May 31 12:53:42 2003 UTC (8 years, 8 months ago) by scottl
Branches: RELENG_5_1
CVS tags: RELENG_5_1_0_RELEASE
Diff to: previous 1.75: preferred, colored; next MAIN 1.76: preferred, colored
Changes since revision 1.75: +2 -2 lines
Turn off malloc_abort and malloc_junk for the release.

Approved by:	re (implicit)

Revision 1.75: download - view: text, markup, annotated - select for diffs
Wed Apr 30 19:30:34 2003 UTC (8 years, 9 months ago) by peter
Branches: MAIN
CVS tags: RELENG_5_1_BP
Branch point for: RELENG_5_1
Diff to: previous 1.74: preferred, colored
Changes since revision 1.74: +4 -0 lines
Tell malloc.c that AMD64 uses the same pagesize as i386.

Revision 1.74: download - view: text, markup, annotated - select for diffs
Thu Jan 30 15:00:17 2003 UTC (9 years ago) by phk
Branches: MAIN
Diff to: previous 1.73: preferred, colored
Changes since revision 1.73: +4 -0 lines
Catch some cases where asking for ridiculously large allocations could
result in a segfault.  Instead just return NULL.

Revision 1.73: download - view: text, markup, annotated - select for diffs
Thu Jan 23 21:26:47 2003 UTC (9 years ago) by phk
Branches: MAIN
Diff to: previous 1.72: preferred, colored
Changes since revision 1.72: +7 -0 lines
For "sensitive" processes, we always set the 'A' flag which causes abort()
to be called on first sight of trouble.

"sensitive" is somewhat arbitrarily defined as "setuid, setgid, uid == root
or gid == wheel".

The 'A' option carries no performance penalty.

It is not possible to override this setting: fix the program instead.

Absentmindedly nodded OK to by:    various

Revision 1.72.2.1: download - view: text, markup, annotated - select for diffs
Fri Jan 3 22:36:35 2003 UTC (9 years, 1 month ago) by scottl
Branches: RELENG_5_0
CVS tags: RELENG_5_0_0_RELEASE
Diff to: previous 1.72: preferred, colored; next MAIN 1.73: preferred, colored
Changes since revision 1.72: +2 -2 lines
As per the 5.0 TODO list, make malloc default to 'aj' instead of 'AJ'.
This matches the default for the 4.x releases, and is only going into
the RELENG_5_0 branch for now.  Making similar chages to HEAD is up
for debate as always.

Approved by:	re (rwatson)

Revision 1.72: download - view: text, markup, annotated - select for diffs
Wed Aug 21 17:11:00 2002 UTC (9 years, 5 months ago) by phk
Branches: MAIN
CVS tags: RELENG_5_0_BP
Branch point for: RELENG_5_0
Diff to: previous 1.71: preferred, colored
Changes since revision 1.71: +3 -3 lines
s/EDOFUS/EDOOFUS/

Persuaded by:	Google

Revision 1.71: download - view: text, markup, annotated - select for diffs
Fri Aug 9 10:16:24 2002 UTC (9 years, 6 months ago) by phk
Branches: MAIN
Diff to: previous 1.70: preferred, colored
Changes since revision 1.70: +7 -0 lines
Make sure we set errno sensibly in case of failure.

Spotted by:	ache

Revision 1.70: download - view: text, markup, annotated - select for diffs
Thu May 30 21:59:16 2002 UTC (9 years, 8 months ago) by phk
Branches: MAIN
Diff to: previous 1.69: preferred, colored
Changes since revision 1.69: +5 -3 lines
Const poison.

Partially submitted by:	wollman

Revision 1.69: download - view: text, markup, annotated - select for diffs
Fri May 10 12:50:59 2002 UTC (9 years, 9 months ago) by peter
Branches: MAIN
Diff to: previous 1.68: preferred, colored
Changes since revision 1.68: +1 -1 lines
Avoid casting a different sized integer to a pointer on LP64 systems.

Revision 1.68: download - view: text, markup, annotated - select for diffs
Wed Apr 24 16:49:36 2002 UTC (9 years, 9 months ago) by phk
Branches: MAIN
Diff to: previous 1.67: preferred, colored
Changes since revision 1.67: +1 -1 lines
Constify _malloc_options.

Revision 1.67: download - view: text, markup, annotated - select for diffs
Fri Mar 29 22:43:42 2002 UTC (9 years, 10 months ago) by markm
Branches: MAIN
Diff to: previous 1.66: preferred, colored
Changes since revision 1.66: +2 -4 lines
Do not use __progname directly (except in [gs]etprogname(3)).
Also, make an internal _getprogname() that is used only inside
libc. For libc, getprogname(3) is a weak symbol in case a
function of the same name is defined in userland.

Revision 1.66: download - view: text, markup, annotated - select for diffs
Fri Mar 22 21:53:10 2002 UTC (9 years, 10 months ago) by obrien
Branches: MAIN
Diff to: previous 1.65: preferred, colored
Changes since revision 1.65: +3 -2 lines
Fix the style of the SCM ID's.
I believe have made all of libc .c's as consistent as possible.

Revision 1.65: download - view: text, markup, annotated - select for diffs
Thu Mar 21 22:48:41 2002 UTC (9 years, 10 months ago) by obrien
Branches: MAIN
Diff to: previous 1.64: preferred, colored
Changes since revision 1.64: +1 -1 lines
Remove __P() usage.

Revision 1.64: download - view: text, markup, annotated - select for diffs
Thu Mar 21 18:44:31 2002 UTC (9 years, 10 months ago) by obrien
Branches: MAIN
Diff to: previous 1.63: preferred, colored
Changes since revision 1.63: +1 -1 lines
Remove 'register' keyword.

Revision 1.63: download - view: text, markup, annotated - select for diffs
Sat Feb 23 19:03:30 2002 UTC (9 years, 11 months ago) by jake
Branches: MAIN
Diff to: previous 1.62: preferred, colored
Changes since revision 1.62: +4 -0 lines
Add ifdefs for sparc64.

Revision 1.49.2.4: download - view: text, markup, annotated - select for diffs
Sat Dec 29 08:10:14 2001 UTC (10 years, 1 month ago) by knu
Branches: RELENG_4
CVS tags: RELENG_4_9_BP, RELENG_4_9_0_RELEASE, RELENG_4_9, RELENG_4_8_BP, RELENG_4_8_0_RELEASE, RELENG_4_8, RELENG_4_7_BP, RELENG_4_7_0_RELEASE, RELENG_4_7, RELENG_4_6_BP, RELENG_4_6_2_RELEASE, RELENG_4_6_1_RELEASE, RELENG_4_6_0_RELEASE, RELENG_4_6, RELENG_4_5_BP, RELENG_4_5_0_RELEASE, RELENG_4_5
Diff to: previous 1.49.2.3: preferred, colored; branchpoint 1.49: preferred, colored
Changes since revision 1.49.2.3: +30 -25 lines
MFC:
  1.62: If 'VX' is given, realloc(foo,0) will bail, it shouldn't.
  1.61: Correctly call THREAD_UNLOCK() if the recursive call trap is sprung.
  1.58: Fixed style bugs (dot `.' at the end of error and warning messages).

Approved by:	phk, re (rwatson)

Revision 1.62: download - view: text, markup, annotated - select for diffs
Sat Nov 17 10:57:04 2001 UTC (10 years, 2 months ago) by phk
Branches: MAIN
Diff to: previous 1.61: preferred, colored
Changes since revision 1.61: +5 -2 lines
If 'VX' is given, realloc(foo,0) will bail, it shouldn't.

PR:		29376
Submitted by:	Farooq Mela <fmela0@sm.socccd.cc.ca.us>

Revision 1.61: download - view: text, markup, annotated - select for diffs
Fri Nov 16 18:15:33 2001 UTC (10 years, 2 months ago) by phk
Branches: MAIN
Diff to: previous 1.60: preferred, colored
Changes since revision 1.60: +2 -0 lines
Correctly call THREAD_UNLOCK() if the recursive call trap is sprung.

Pointed out by:		knu

Revision 1.60: download - view: text, markup, annotated - select for diffs
Fri Nov 2 11:32:28 2001 UTC (10 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.59: preferred, colored
Changes since revision 1.59: +14 -4 lines
phkmalloc->evilchecks++;

If zero bytes are allocated, return pointer to the middle of page-zero
(which is protected) so that the program will crash if it dereferences
this illgotten pointer.

Inspired & Urged by:	Theo de Raadt <deraadt@cvs.openbsd.org>

Revision 1.59: download - view: text, markup, annotated - select for diffs
Fri Sep 7 12:32:43 2001 UTC (10 years, 5 months ago) by dfr
Branches: MAIN
Diff to: previous 1.58: preferred, colored
Changes since revision 1.58: +12 -1 lines
Port to ia64, taking into account the fact that pagesizes may be variable.

Revision 1.58: download - view: text, markup, annotated - select for diffs
Fri Aug 10 11:46:37 2001 UTC (10 years, 6 months ago) by ru
Branches: MAIN
Diff to: previous 1.57: preferred, colored
Changes since revision 1.57: +23 -23 lines
Fixed style bugs (dot `.' at the end of error and warning messages).

Noticed by:	bde

Revision 1.49.2.3: download - view: text, markup, annotated - select for diffs
Mon Mar 5 11:31:30 2001 UTC (10 years, 11 months ago) by obrien
Branches: RELENG_4
CVS tags: RELENG_4_4_BP, RELENG_4_4_0_RELEASE, RELENG_4_4, RELENG_4_3_BP, RELENG_4_3_0_RELEASE, RELENG_4_3
Diff to: previous 1.49.2.2: preferred, colored; branchpoint 1.49: preferred, colored
Changes since revision 1.49.2.2: +8 -8 lines
MFC: 1.57: remove sizeof(void *) == sizeof(int) assumptions

Revision 1.57: download - view: text, markup, annotated - select for diffs
Sun Feb 4 10:06:24 2001 UTC (11 years ago) by phk
Branches: MAIN
Diff to: previous 1.56: preferred, colored
Changes since revision 1.56: +8 -8 lines
Remove a sizeof(void *) == sizeof(int) assumption.

Submitted by:	Loren James Rittle <rittle@latour.rsch.comm.mot.com>

Revision 1.56: download - view: text, markup, annotated - select for diffs
Wed Jan 24 13:00:58 2001 UTC (11 years ago) by deischen
Branches: MAIN
Diff to: previous 1.55: preferred, colored
Changes since revision 1.55: +3 -1 lines
Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions.  If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
	__sys_foo - actual system call
	_foo - weak definition to __sys_foo
	foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo.  In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde).  All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes.  <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h  namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE.  We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by:	-arch

Revision 1.49.2.2: download - view: text, markup, annotated - select for diffs
Mon Dec 11 01:03:19 2000 UTC (11 years, 2 months ago) by obrien
Branches: RELENG_4
Diff to: previous 1.49.2.1: preferred, colored; branchpoint 1.49: preferred, colored
Changes since revision 1.49.2.1: +3 -2 lines
MFC: add /dev/zero and use PATH_* where possible.

Revision 1.55: download - view: text, markup, annotated - select for diffs
Sat Dec 9 09:35:32 2000 UTC (11 years, 2 months ago) by obrien
Branches: MAIN
Diff to: previous 1.54: preferred, colored
Changes since revision 1.54: +3 -2 lines
Add `_PATH_DEVZERO'.
Use _PATH_* where where possible.

Revision 1.54: download - view: text, markup, annotated - select for diffs
Sun Nov 26 10:30:18 2000 UTC (11 years, 2 months ago) by phk
Branches: MAIN
Diff to: previous 1.53: preferred, colored
Changes since revision 1.53: +19 -13 lines
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.

Revision 1.53: download - view: text, markup, annotated - select for diffs
Wed Sep 20 06:16:23 2000 UTC (11 years, 4 months ago) by brian
Branches: MAIN
Diff to: previous 1.52: preferred, colored
Changes since revision 1.52: +1 -2 lines
Oops, un-spam this file - the last commit was an accident.

Pointed out by: phk

Revision 1.52: download - view: text, markup, annotated - select for diffs
Wed Sep 20 03:05:37 2000 UTC (11 years, 4 months ago) by brian
Branches: MAIN
Diff to: previous 1.51: preferred, colored
Changes since revision 1.51: +2 -1 lines
Only realloc() environ if we're sure that we know where it came from.

The recent problems with sshd were due to sshd reassigning
`environ' when setenv() thinks it owns it.  setenv() subsequently
realloc()s the new version of environ and *boom*

Revision 1.49.2.1: download - view: text, markup, annotated - select for diffs
Wed Aug 23 00:12:17 2000 UTC (11 years, 5 months ago) by jhb
Branches: RELENG_4
CVS tags: RELENG_4_2_0_RELEASE, RELENG_4_1_1_RELEASE
Diff to: previous 1.49: preferred, colored
Changes since revision 1.49: +2 -4 lines
MFC:
- Add a missing THREAD_UNLOCK()
- Remove allocation failure check from 'A' option, the 'X' option does
  this as a standalone check now.

Revision 1.51: download - view: text, markup, annotated - select for diffs
Sun Jul 9 13:10:18 2000 UTC (11 years, 7 months ago) by phk
Branches: MAIN
CVS tags: PRE_SMPNG
Diff to: previous 1.50: preferred, colored
Changes since revision 1.50: +3 -3 lines
Turn malloc options "AJ" on by default.

These will be turned off again as we approach 5.0-RELEASE.

If you benchmark things, make sure to
	ln -sf j /etc/malloc.conf
to see "true" performance.

Revision 1.50: download - view: text, markup, annotated - select for diffs
Mon Apr 10 09:24:44 2000 UTC (11 years, 10 months ago) by phk
Branches: MAIN
Diff to: previous 1.49: preferred, colored
Changes since revision 1.49: +2 -4 lines
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.

Revision 1.49: download - view: text, markup, annotated - select for diffs
Thu Jan 27 23:06:48 2000 UTC (12 years ago) by jasone
Branches: MAIN
CVS tags: RELENG_4_BP, RELENG_4_1_0_RELEASE, RELENG_4_0_0_RELEASE
Branch point for: RELENG_4
Diff to: previous 1.48: preferred, colored
Changes since revision 1.48: +10 -10 lines
Simplify sytem call renaming.  Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo().  In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate.  In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by:	deischen

Revision 1.48: download - view: text, markup, annotated - select for diffs
Wed Jan 12 09:23:43 2000 UTC (12 years, 1 month ago) by jasone
Branches: MAIN
Diff to: previous 1.47: preferred, colored
Changes since revision 1.47: +10 -11 lines
Add three-tier symbol naming in support of POSIX thread cancellation
points.  For library functions, the pattern is __sleep() <--
_libc_sleep() <-- sleep().  The arrows represent weak aliases.  For
system calls, the pattern is _read() <-- _libc_read() <-- read().

Revision 1.18.2.7: download - view: text, markup, annotated - select for diffs
Sun Sep 5 11:16:45 1999 UTC (12 years, 5 months ago) by peter
Branches: RELENG_2_2
Diff to: previous 1.18.2.6: preferred, colored; branchpoint 1.18: preferred, colored; next MAIN 1.19: preferred, colored
Changes since revision 1.18.2.6: +1 -1 lines
$Id$ -> $FreeBSD$

Revision 1.43.2.4: download - view: text, markup, annotated - select for diffs
Sun Aug 29 14:48:36 1999 UTC (12 years, 5 months ago) by peter
Branches: RELENG_3
CVS tags: RELENG_3_5_0_RELEASE, RELENG_3_4_0_RELEASE, RELENG_3_3_0_RELEASE
Diff to: previous 1.43.2.3: preferred, colored; branchpoint 1.43: preferred, colored; next MAIN 1.44: preferred, colored
Changes since revision 1.43.2.3: +1 -1 lines
$Id$ -> $FreeBSD$

Revision 1.47: download - view: text, markup, annotated - select for diffs
Sat Aug 28 00:01:34 1999 UTC (12 years, 5 months ago) by peter
Branches: MAIN
Diff to: previous 1.46: preferred, colored
Changes since revision 1.46: +1 -1 lines
$Id$ -> $FreeBSD$

Revision 1.46: download - view: text, markup, annotated - select for diffs
Wed Jul 7 21:01:20 1999 UTC (12 years, 7 months ago) by des
Branches: MAIN
Diff to: previous 1.45: preferred, colored
Changes since revision 1.45: +0 -4 lines
Back out previous commit after discussing it with Dmitrij Tejblum.

Revision 1.43.2.3: download - view: text, markup, annotated - select for diffs
Wed Jul 7 20:57:51 1999 UTC (12 years, 7 months ago) by des
Branches: RELENG_3
Diff to: previous 1.43.2.2: preferred, colored; branchpoint 1.43: preferred, colored
Changes since revision 1.43.2.2: +0 -4 lines
Back out previous commit after discussing it with Dmitrij Tejblum.

Revision 1.43.2.2: download - view: text, markup, annotated - select for diffs
Wed Jul 7 19:58:14 1999 UTC (12 years, 7 months ago) by des
Branches: RELENG_3
Diff to: previous 1.43.2.1: preferred, colored; branchpoint 1.43: preferred, colored
Changes since revision 1.43.2.1: +5 -1 lines
MFC: Always set errno to ENOMEM when returning 0.

Revision 1.45: download - view: text, markup, annotated - select for diffs
Wed Jul 7 19:54:08 1999 UTC (12 years, 7 months ago) by des
Branches: MAIN
Diff to: previous 1.44: preferred, colored
Changes since revision 1.44: +5 -1 lines
Always set errno to ENOMEM when returning 0 from malloc() or realloc().

Approved by:	phk

Revision 1.43.2.1: download - view: text, markup, annotated - select for diffs
Sun May 9 18:41:49 1999 UTC (12 years, 9 months ago) by alc
Branches: RELENG_3
CVS tags: RELENG_3_2_PAO_BP, RELENG_3_2_PAO, RELENG_3_2_0_RELEASE
Diff to: previous 1.43: preferred, colored
Changes since revision 1.43: +2 -2 lines
MFC: Disable the "Hint" option in phkmalloc as default.

Reviewed by:	Poul-Henning Kamp <phk@critter.freebsd.dk>

Revision 1.44: download - view: text, markup, annotated - select for diffs
Sun Mar 28 14:16:05 1999 UTC (12 years, 10 months ago) by phk
Branches: MAIN
Diff to: previous 1.43: preferred, colored
Changes since revision 1.43: +2 -2 lines
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 ?)

Revision 1.18.2.6: download - view: text, markup, annotated - select for diffs
Wed Nov 4 08:42:04 1998 UTC (13 years, 3 months ago) by tg
Branches: RELENG_2_2
CVS tags: RELENG_2_2_8_RELEASE
Diff to: previous 1.18.2.5: preferred, colored; branchpoint 1.18: preferred, colored
Changes since revision 1.18.2.5: +27 -25 lines
As theatened two weeks ago: merge the major changes from -current's pthread
implementation. This includes file locking based on FILE *, signal fixes,
read/write-locks, better POSIX compliance and better performance. Not included
are changes relating to realtime scheduling.

Famous last words: I've now built the world several times with these changes,
so they shouldn't break anything.

Revision 1.43: download - view: text, markup, annotated - select for diffs
Wed Sep 30 06:13:59 1998 UTC (13 years, 4 months ago) by jb
Branches: MAIN
CVS tags: RELENG_3_BP, RELENG_3_1_0_RELEASE, RELENG_3_0_0_RELEASE
Branch point for: RELENG_3
Diff to: previous 1.42: preferred, colored
Changes since revision 1.42: +1 -15 lines
Delete the XXX comments that refer to spinlock recursion. The malloc/free/
realloc functions check for recursion within the malloc code itself. In
a thread-safe library, the single spinlock ensures that no two threads
go inside the protected code at the same time. The thread implementation
is responsible for ensuring that the spinlock does in fact protect malloc.
There was a window of opportunity in which this was not the case. I'll fix
that with a commit RSN.

Revision 1.42: download - view: text, markup, annotated - select for diffs
Wed Sep 23 21:26:04 1998 UTC (13 years, 4 months ago) by dfr
Branches: MAIN
Diff to: previous 1.41: preferred, colored
Changes since revision 1.41: +5 -1 lines
Use 8k pagesize on alpha, not 4k.

Revision 1.41: download - view: text, markup, annotated - select for diffs
Sun Sep 20 01:07:50 1998 UTC (13 years, 4 months ago) by alex
Branches: MAIN
Diff to: previous 1.40: preferred, colored
Changes since revision 1.40: +17 -1 lines
Back out part of previous commit (even though it's technically correct).
Our spinlock implementation allows a particular thread to obtain a lock
multiple times, but release the lock with a single unlock call.  Since
we're detecting recursion, we know the lock is already owned by the
current thread in a previous call and must not be released in the
current call.  This is really far too dependent on this particular
spinlock implementation, so I've added commented out calls to
THREAD_UNLOCK in the appropriate places.  We can activate this code when
spinlock is taught to count each lock operation.

Revision 1.40: download - view: text, markup, annotated - select for diffs
Sat Sep 19 20:55:36 1998 UTC (13 years, 4 months ago) by alex
Branches: MAIN
Diff to: previous 1.39: preferred, colored
Changes since revision 1.39: +7 -8 lines
Correctly back out of free if a recursive call into malloc.c is detected.
Set malloc_func *after* grabbing the thread lock.

Noticed by:	Simon Coggins <simon@oz.org>

Revision 1.39: download - view: text, markup, annotated - select for diffs
Thu Jun 18 09:13:16 1998 UTC (13 years, 7 months ago) by peter
Branches: MAIN
Diff to: previous 1.38: preferred, colored
Changes since revision 1.38: +4 -1 lines
preserve errno across the readlink() calls.  There is no value in trashing
errno during a successful malloc() call.

Revision 1.38: download - view: text, markup, annotated - select for diffs
Tue Jun 9 08:30:32 1998 UTC (13 years, 8 months ago) by jb
Branches: MAIN
Diff to: previous 1.37: preferred, colored
Changes since revision 1.37: +4 -4 lines
Add support for thread lock debug. No impact of the malloc code.

Revision 1.18.2.5: download - view: text, markup, annotated - select for diffs
Thu Apr 30 07:53:36 1998 UTC (13 years, 9 months ago) by tg
Branches: RELENG_2_2
CVS tags: RELENG_2_2_7_RELEASE
Diff to: previous 1.18.2.4: preferred, colored; branchpoint 1.18: preferred, colored
Changes since revision 1.18.2.4: +12 -3 lines
MFC part 5: Fix recursion problem which occurs when a signal is received
during a malloc. The signal handler creates a thread which requires a malloc...
For now, the only thing to do is to block signals.

Revision 1.37: download - view: text, markup, annotated - select for diffs
Wed Apr 29 09:10:58 1998 UTC (13 years, 9 months ago) by jb
Branches: MAIN
Diff to: previous 1.36: preferred, colored
Changes since revision 1.36: +10 -18 lines
Replace the threaded locking with spinlock calls for both threaded
and non-threaded programs. This makes malloc thread safe for linking
with libpthread and kernel threads.

Reviewed by: phk

Revision 1.18.2.4: download - view: text, markup, annotated - select for diffs
Thu Apr 23 08:21:49 1998 UTC (13 years, 9 months ago) by tg
Branches: RELENG_2_2
Diff to: previous 1.18.2.3: preferred, colored; branchpoint 1.18: preferred, colored
Changes since revision 1.18.2.3: +2 -2 lines
MFC part 2: Static initializers for mutexes and condition variables.

Revision 1.36: download - view: text, markup, annotated - select for diffs
Sat Apr 4 11:01:52 1998 UTC (13 years, 10 months ago) by jb
Branches: MAIN
Diff to: previous 1.35: preferred, colored
Changes since revision 1.35: +2 -2 lines
Change in name of the static initializer define.

Revision 1.35: download - view: text, markup, annotated - select for diffs
Mon Mar 9 07:00:38 1998 UTC (13 years, 11 months ago) by jb
Branches: MAIN
Diff to: previous 1.34: preferred, colored
Changes since revision 1.34: +4 -2 lines
NetBSD doesn't have a utrace syscall, so don't define that if
__NETBSD_SYSCALLS is defined.

Revision 1.34: download - view: text, markup, annotated - select for diffs
Wed Dec 31 03:15:06 1997 UTC (14 years, 1 month ago) by alex
Branches: MAIN
Diff to: previous 1.33: preferred, colored
Changes since revision 1.33: +4 -4 lines
Drop the use of caddr_t in conjunction with mmap(2).

Revision 1.33: download - view: text, markup, annotated - select for diffs
Mon Dec 15 02:12:42 1997 UTC (14 years, 1 month ago) by jb
Branches: MAIN
Diff to: previous 1.32: preferred, colored
Changes since revision 1.32: +12 -3 lines
Fix recursion problem which occurs when a signal is received during
a malloc. The signal handler creates a thread which requires a malloc...
For now, the only thing to do is to block signals. When we move user
pthreads to use the kernel threads, mutexes will be implemented in kernel
space and then malloc can revert.

Revision 1.32: download - view: text, markup, annotated - select for diffs
Sun Aug 31 05:59:39 1997 UTC (14 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.31: preferred, colored
Changes since revision 1.31: +2 -2 lines
Another 32bits of 64bits conformance.

Reviewed by:	phk
Submitted by:	jdp

Revision 1.31: download - view: text, markup, annotated - select for diffs
Wed Aug 27 12:04:33 1997 UTC (14 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.30: preferred, colored
Changes since revision 1.30: +4 -3 lines
Improvement of type independency for the bitmap.
This makes 64bit operation more likely.

Reviewed by:	phk
Submitted by:	jdp

Revision 1.30: download - view: text, markup, annotated - select for diffs
Wed Aug 27 06:40:34 1997 UTC (14 years, 5 months ago) by phk
Branches: MAIN
Diff to: previous 1.29: preferred, colored
Changes since revision 1.29: +2 -2 lines
Malloc option H is now default.

Revision 1.29: download - view: text, markup, annotated - select for diffs
Sat Jul 26 03:43:14 1997 UTC (14 years, 6 months ago) by jdp
Branches: MAIN
Diff to: previous 1.28: preferred, colored
Changes since revision 1.28: +2 -2 lines
Fix a minor typo.  It only affects the sparc version.

Revision 1.18.2.3: download - view: text, markup, annotated - select for diffs
Thu Jul 24 08:25:25 1997 UTC (14 years, 6 months ago) by phk
Branches: RELENG_2_2
CVS tags: RELENG_2_2_6_RELEASE, RELENG_2_2_5_RELEASE
Diff to: previous 1.18.2.2: preferred, colored; branchpoint 1.18: preferred, colored
Changes since revision 1.18.2.2: +120 -152 lines
Merge malloc from current.

Revision 1.28: download - view: text, markup, annotated - select for diffs
Wed Jul 2 19:33:23 1997 UTC (14 years, 7 months ago) by phk
Branches: MAIN
Diff to: previous 1.27: preferred, colored
Changes since revision 1.27: +11 -12 lines
Have another go at the malloc-sysv initialization.

PR:		4002
Pointed out by:	bde

Revision 1.27: download - view: text, markup, annotated - select for diffs
Tue Jul 1 18:39:38 1997 UTC (14 years, 7 months ago) by phk
Branches: MAIN
Diff to: previous 1.26: preferred, colored
Changes since revision 1.26: +19 -33 lines
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>

Revision 1.26: download - view: text, markup, annotated - select for diffs
Sun Jun 22 17:54:27 1997 UTC (14 years, 7 months ago) by phk
Branches: MAIN
Diff to: previous 1.25: preferred, colored
Changes since revision 1.25: +91 -148 lines
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>

Revision 1.25: download - view: text, markup, annotated - select for diffs
Thu Jun 12 12:45:45 1997 UTC (14 years, 8 months ago) by phk
Branches: MAIN
Diff to: previous 1.24: preferred, colored
Changes since revision 1.24: +9 -5 lines
Add yet an option, this time on how to deal with malloc(0) and realloc(ptr.0)

Prompted by:	X11 & XFree86

Revision 1.24: download - view: text, markup, annotated - select for diffs
Wed Jun 4 12:55:49 1997 UTC (14 years, 8 months ago) by jb
Branches: MAIN
Diff to: previous 1.23: preferred, colored
Changes since revision 1.23: +4 -6 lines
Fix mutex initialization.

Malloc cannot use pthread_mutex_init() to initialize a mutex because
the mutex initialization process does a malloc!

libc_r internals skip the malloc and assign an initializer to a static
structure and point the opaque type (pthread_mutex_t in this case) to
that structure. This is done on the assumption that the mutex will never
be destroyed. This style of initialization is only valid inside libc_r
because the structure that is assigned is opaque to the user.

This fix allows a simple program to get to main() again. 8-)

Revision 1.23: download - view: text, markup, annotated - select for diffs
Fri May 30 20:39:32 1997 UTC (14 years, 8 months ago) by phk
Branches: MAIN
Diff to: previous 1.22: preferred, colored
Changes since revision 1.22: +56 -18 lines
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>

Revision 1.18.2.2: download - view: text, markup, annotated - select for diffs
Tue Mar 18 16:18:24 1997 UTC (14 years, 10 months ago) by phk
Branches: RELENG_2_2
CVS tags: RELENG_2_2_2_RELEASE, RELENG_2_2_1_RELEASE
Diff to: previous 1.18.2.1: preferred, colored; branchpoint 1.18: preferred, colored
Changes since revision 1.18.2.1: +4 -2 lines
YAMFC (check for overflow in size argument)

Revision 1.22: download - view: text, markup, annotated - select for diffs
Tue Mar 18 07:54:24 1997 UTC (14 years, 10 months ago) by phk
Branches: MAIN
Diff to: previous 1.21: preferred, colored
Changes since revision 1.21: +4 -2 lines
Check for overflow in size argument.

Tested by:	Joel Maslak <j@pobox.com>
Closes:		PR kern/2964

Revision 1.21: download - view: text, markup, annotated - select for diffs
Sat Feb 22 15:03:12 1997 UTC (14 years, 11 months ago) by peter
Branches: MAIN
Diff to: previous 1.20: preferred, colored
Changes since revision 1.20: +1 -1 lines
Revert $FreeBSD$ to $Id$

Revision 1.20: download - view: text, markup, annotated - select for diffs
Tue Jan 14 06:06:29 1997 UTC (15 years ago) by jkh
Branches: MAIN
Diff to: previous 1.19: preferred, colored
Changes since revision 1.19: +1 -1 lines
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.

Revision 1.18.2.1: download - view: text, markup, annotated - select for diffs
Mon Dec 30 01:35:15 1996 UTC (15 years, 1 month ago) by alex
Branches: RELENG_2_2
CVS tags: RELENG_2_2_0_RELEASE
Diff to: previous 1.18: preferred, colored
Changes since revision 1.18: +2 -2 lines
Bring in thread locking fix from rev 1.19.

Approved by:	jkh

Revision 1.19: download - view: text, markup, annotated - select for diffs
Sun Dec 29 02:38:50 1996 UTC (15 years, 1 month ago) by alex
Branches: MAIN
Diff to: previous 1.18: preferred, colored
Changes since revision 1.18: +2 -2 lines
_thread_kern_sig_unblock takes an integer, not a reference.

Submitted by:	John Birrell <jb@cimlogic.com.au>

Revision 1.18: download - view: text, markup, annotated - select for diffs
Tue Oct 29 20:35:39 1996 UTC (15 years, 3 months ago) by phk
Branches: MAIN
CVS tags: RELENG_2_2_BP
Branch point for: RELENG_2_2
Diff to: previous 1.17: preferred, colored
Changes since revision 1.17: +6 -4 lines
If you run with option Z and malloc fails, memset gets called
with a NULL pointer (archie)
Explain that minsize is also the smallest alignment.

Submitted by:	Archie Cobbs <archie@whistle.com>

Revision 1.17: download - view: text, markup, annotated - select for diffs
Sat Oct 26 08:19:07 1996 UTC (15 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.16: preferred, colored
Changes since revision 1.16: +28 -48 lines
Various cosmetics
Improve chances of troublefree 64bit operation. [imp]

Noticed by:	Warner Losh <imp@village.org>

Revision 1.16: download - view: text, markup, annotated - select for diffs
Sun Oct 20 13:20:57 1996 UTC (15 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.15: preferred, colored
Changes since revision 1.15: +103 -187 lines
malloc_pages should be static.
Add progname to warning/error message layout. (joerg)
Remove inline assembler, no speed impact, not need for the obfuscation (bde)
Remove on the fly calculation of parameters, no longer critical.
Make D & U flags valid even if we don't support them.
Don't call imalloc until we're done initializing.
Zap contents on free() if we have "Junk" set. [*]
Various nitpicking.

[*] As a sideeffect of this change, if you are worried about
sensitive data lingering in memory, you can use the 'Junk' option
now to make sure phkmalloc zaps memory when it is returned.  add
	char * malloc_options = "J";
to your source.  Obviously there is a performance impact.

Revision 1.15: download - view: text, markup, annotated - select for diffs
Wed Sep 25 16:29:15 1996 UTC (15 years, 4 months ago) by sos
Branches: MAIN
Diff to: previous 1.14: preferred, colored
Changes since revision 1.14: +2 -2 lines
Fix a typo.
Reviewed by:	 phk

Revision 1.14: download - view: text, markup, annotated - select for diffs
Wed Sep 25 08:30:46 1996 UTC (15 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.13: preferred, colored
Changes since revision 1.13: +37 -28 lines
A number of minor bogons and portability things from jdp.

Submitted by:	jdp

Revision 1.13: download - view: text, markup, annotated - select for diffs
Mon Sep 23 19:26:39 1996 UTC (15 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.12: preferred, colored
Changes since revision 1.12: +232 -189 lines
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.

Revision 1.12: download - view: text, markup, annotated - select for diffs
Tue Sep 17 19:50:23 1996 UTC (15 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.11: preferred, colored
Changes since revision 1.11: +4 -3 lines
Fix a very rare error condition:  The code to free VM back to the kernel
as done after a quasi-recursive call to free() had modified what we
thought we knew about the last chunk of pages.
This bug manifested itself when I did a "make obj" from src/usr.sbin/lpr,
then make would coredump in the lpd directory.

Revision 1.11: download - view: text, markup, annotated - select for diffs
Wed Jul 3 05:03:07 1996 UTC (15 years, 7 months ago) by phk
Branches: MAIN
Diff to: previous 1.10: preferred, colored
Changes since revision 1.10: +48 -61 lines
Isolated all the crap for thread-safe so I can see what goes on again...

Revision 1.10: download - view: text, markup, annotated - select for diffs
Mon Jan 22 00:01:44 1996 UTC (16 years ago) by julian
Branches: MAIN
Diff to: previous 1.9: preferred, colored
Changes since revision 1.9: +66 -3 lines
Reviewed by:	julian and (hsu?)
Submitted by:	 John Birrel(L?)

changes for threadsafe operations

Revision 1.9: download - view: text, markup, annotated - select for diffs
Fri Jan 5 23:30:41 1996 UTC (16 years, 1 month ago) by phk
Branches: MAIN
Diff to: previous 1.8: preferred, colored
Changes since revision 1.8: +4 -4 lines
Fix a fencepost error.
Found by: Lars Fredriksen <fredriks@mcs.com>

Revision 1.8: download - view: text, markup, annotated - select for diffs
Mon Dec 18 12:03:54 1995 UTC (16 years, 1 month ago) by phk
Branches: MAIN
Diff to: previous 1.7: preferred, colored
Changes since revision 1.7: +8 -2 lines
Preallocate a small structure, so we can sbrk(2) further back.
Reviewed by:	phk
Submitted by:	Kaleb Keithly <kaleb@x.org>

Revision 1.7: download - view: text, markup, annotated - select for diffs
Mon Dec 11 14:28:12 1995 UTC (16 years, 2 months ago) by peter
Branches: MAIN
Diff to: previous 1.6: preferred, colored
Changes since revision 1.6: +47 -29 lines
Change phkmalloc so that the page directory is now floating and allocated
via mmap() up around the shared library area.  Previously the directory
was allocated from space from it's own memory pool.  Because of the way it
was being extended on processes with large malloced data segments (ie: inn)
once the page directory was extended for some reason, it was not possible
to lower the heap size any more to return pages to the OS.
(If my understanding is correct, page directory expansion occurs at 4MB,
12MB, 20MB, 28MB, etc.)  I was seeing INN allocate a large amount of short
term memory, pushing it over the 28MB mark, and once it's transient demands
hit 28MB, it never freed it's pages and swap space again.)

I've been running this in my libc for about a month...

Also, seperate MALLOC_STATS from EXTRA_SANITY..  I found it useful to call
malloc_dump() from within INN from a ctlinnd command to see where the hell
all the memory was going.. :-)  I've left MALLOC_STATS enabled, as it has
no run-time or data storage cost.

Reviewed by: phk

Revision 1.6: download - view: text, markup, annotated - select for diffs
Sun Oct 22 14:47:00 1995 UTC (16 years, 3 months ago) by phk
Branches: MAIN
Diff to: previous 1.5: preferred, colored
Changes since revision 1.5: +8 -4 lines
Remove EXTRA_SANITY, fix a unused var.

Revision 1.5: download - view: text, markup, annotated - select for diffs
Sun Oct 8 18:44:20 1995 UTC (16 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.4: preferred, colored
Changes since revision 1.4: +355 -293 lines
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. (!!)

Revision 1.4: download - view: text, markup, annotated - select for diffs
Fri Sep 22 14:11:00 1995 UTC (16 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.3: preferred, colored
Changes since revision 1.3: +8 -8 lines
A buglet when dumping and a stylistic point from Mike.

Submitted by:	Mike Pritchard <mpp@mpp.minn.net>

Revision 1.3: download - view: text, markup, annotated - select for diffs
Sat Sep 16 09:28:13 1995 UTC (16 years, 4 months ago) by phk
Branches: MAIN
Diff to: previous 1.2: preferred, colored
Changes since revision 1.2: +1007 -362 lines
``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.

Revision 1.2: download - view: text, markup, annotated - select for diffs
Tue May 30 05:41:48 1995 UTC (16 years, 8 months ago) by rgrimes
Branches: MAIN
CVS tags: RELENG_2_1_7_RELEASE, RELENG_2_1_6_RELEASE, RELENG_2_1_6_1_RELEASE, RELENG_2_1_5_RELEASE, RELENG_2_1_0_RELEASE, RELENG_2_1_0_BP, RELENG_2_1_0, RELENG_2_0_5_RELEASE, RELENG_2_0_5_BP, RELENG_2_0_5
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +6 -6 lines
Remove trailing whitespace.

Revision 1.1.1.1 (vendor branch): download - view: text, markup, annotated - select for diffs
Fri May 27 04:57:49 1994 UTC (17 years, 8 months ago) by rgrimes
Branches: CSRG
CVS tags: bsd_44_lite_2, bsd_44_lite, RELENG_2_0_5_ALPHA, RELEASE_2_0, BETA_2_0, ALPHA_2_0
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +0 -0 lines
BSD 4.4 Lite Lib Sources

Revision 1.1: download - view: text, markup, annotated - select for diffs
Fri May 27 04:57:48 1994 UTC (17 years, 8 months ago) by rgrimes
Branches: MAIN
Initial revision

Diff request

This form allows you to request diffs between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.

Log view options