Commit Graph

195 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav
c58b5cffa1 Always set errno to ENOMEM when returning 0 from malloc() or realloc().
Approved by:	phk
1999-07-07 19:54:08 +00:00
Poul-Henning Kamp
5b26e84968 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 ?)
1999-03-28 14:16:05 +00:00
John Birrell
a0aa389007 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.
1998-09-30 06:13:59 +00:00
Doug Rabson
cea1d019fe Use 8k pagesize on alpha, not 4k. 1998-09-23 21:26:04 +00:00
Alexander Langer
d988805a1f 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.
1998-09-20 01:07:50 +00:00
Alexander Langer
366248e086 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>
1998-09-19 20:55:36 +00:00
Peter Wemm
2f92c56cc3 preserve errno across the readlink() calls. There is no value in trashing
errno during a successful malloc() call.
1998-06-18 09:13:16 +00:00
John Birrell
3d853e107e Add support for thread lock debug. No impact of the malloc code. 1998-06-09 08:30:32 +00:00
John Birrell
72b42edfd4 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
1998-04-29 09:10:58 +00:00
John Birrell
5a2f1fed77 Change in name of the static initializer define. 1998-04-04 11:03:07 +00:00
John Birrell
e4193688da NetBSD doesn't have a utrace syscall, so don't define that if
__NETBSD_SYSCALLS is defined.
1998-03-09 07:00:38 +00:00
Alexander Langer
5a5b9efe70 Drop the use of caddr_t in conjunction with mmap(2). 1997-12-31 03:15:06 +00:00
John Birrell
d5bc59bb81 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.
1997-12-15 02:12:42 +00:00
Poul-Henning Kamp
188891873e Another 32bits of 64bits conformance.
Reviewed by:	phk
Submitted by:	jdp
1997-08-31 05:59:39 +00:00
Poul-Henning Kamp
263f4be35c Improvement of type independency for the bitmap.
This makes 64bit operation more likely.

Reviewed by:	phk
Submitted by:	jdp
1997-08-27 12:04:33 +00:00
Poul-Henning Kamp
cd15afa3e8 Malloc option H is now default. 1997-08-27 06:40:34 +00:00
John Polstra
f9e41842fc Fix a minor typo. It only affects the sparc version. 1997-07-26 03:43:14 +00:00
Poul-Henning Kamp
25f5c3ba98 Have another go at the malloc-sysv initialization.
PR:		4002
Pointed out by:	bde
1997-07-02 19:33:23 +00:00
Poul-Henning Kamp
db7f90903d 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>
1997-07-01 18:39:38 +00:00
Poul-Henning Kamp
e3553c0365 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>
1997-06-22 17:54:27 +00:00
Poul-Henning Kamp
7c5232c617 Add yet an option, this time on how to deal with malloc(0) and realloc(ptr.0)
Prompted by:	X11 & XFree86
1997-06-12 12:45:45 +00:00
John Birrell
1a3a296d21 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-)
1997-06-04 12:55:49 +00:00
Poul-Henning Kamp
7e2a8bde3e 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>
1997-05-30 20:39:32 +00:00
Poul-Henning Kamp
753da60320 Check for overflow in size argument.
Tested by:	Joel Maslak <j@pobox.com>
Closes:		PR kern/2964
1997-03-18 07:54:24 +00:00
Peter Wemm
7e546392b5 Revert $FreeBSD$ to $Id$ 1997-02-22 15:12:41 +00:00
Jordan K. Hubbard
1130b656e5 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.
1997-01-14 07:20:47 +00:00
Alexander Langer
8596ee6d82 _thread_kern_sig_unblock takes an integer, not a reference.
Submitted by:	John Birrell <jb@cimlogic.com.au>
1996-12-29 02:38:50 +00:00
Poul-Henning Kamp
f3f639a106 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>
1996-10-29 20:35:39 +00:00
Poul-Henning Kamp
7bd7818f1c Various cosmetics
Improve chances of troublefree 64bit operation. [imp]

Noticed by:	Warner Losh <imp@village.org>
1996-10-26 08:19:07 +00:00
Poul-Henning Kamp
2e7c91ff16 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.
1996-10-20 13:20:57 +00:00
Søren Schmidt
fa19f8481a Fix a typo.
Reviewed by:	 phk
1996-09-25 16:29:15 +00:00
Poul-Henning Kamp
ed3d429586 A number of minor bogons and portability things from jdp.
Submitted by:	jdp
1996-09-25 08:30:46 +00:00
Poul-Henning Kamp
1f05a9e73a 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.
1996-09-23 19:26:39 +00:00
Poul-Henning Kamp
89e3b80fa2 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.
1996-09-17 19:50:23 +00:00
Poul-Henning Kamp
0d3f1a2a53 Isolated all the crap for thread-safe so I can see what goes on again... 1996-07-03 05:03:07 +00:00
Julian Elischer
f70177e76e Reviewed by: julian and (hsu?)
Submitted by:	 John Birrel(L?)

changes for threadsafe operations
1996-01-22 00:02:33 +00:00
Poul-Henning Kamp
926cb56114 Fix a fencepost error.
Found by: Lars Fredriksen <fredriks@mcs.com>
1996-01-05 23:30:41 +00:00
Poul-Henning Kamp
9100bbac3d Preallocate a small structure, so we can sbrk(2) further back.
Reviewed by:	phk
Submitted by:	Kaleb Keithly <kaleb@x.org>
1995-12-18 12:03:54 +00:00
Peter Wemm
04936d2e08 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
1995-12-11 14:28:12 +00:00
Poul-Henning Kamp
f824233e9e Remove EXTRA_SANITY, fix a unused var. 1995-10-22 14:47:00 +00:00
Poul-Henning Kamp
7aa70c9e8e 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. (!!)
1995-10-08 18:44:20 +00:00
Poul-Henning Kamp
182b05e19e A buglet when dumping and a stylistic point from Mike.
Submitted by:	Mike Pritchard <mpp@mpp.minn.net>
1995-09-22 14:11:00 +00:00
Poul-Henning Kamp
81df7b69ef ``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.
1995-09-16 09:28:13 +00:00
Rodney W. Grimes
6c06b4e2aa Remove trailing whitespace. 1995-05-30 05:51:47 +00:00
Rodney W. Grimes
58f0484fa2 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00