summaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
Commit message (Collapse)AuthorAgeFilesLines
* Add init_param3() to subr_param. This function is calledMike Silbersack2003-07-111-0/+5
| | | | | | | | | | | immediately after the kernel map has been sized, and is the optimal place for the autosizing of memory allocations which occur within the kernel map to occur. Suggested by: bde Notes: svn path=/head/; revision=117391
* Don't overflow when calculating vm_kmem_size. This fixes kmem_mapPaul Saab2003-06-111-4/+4
| | | | | | | | | | | too small panics on PAE machines which have odd > 4GB sizes (4.5 gig would render a 20MB of KVA for kmem_map instead of 200MB). Submitted by: John Cagle <john.cagle@hp.com>, jeff Reviewed by: jeff, peter, scottl, lots of USENIX folks Notes: svn path=/head/; revision=116187
* Use __FBSDID().David E. O'Brien2003-06-111-1/+3
| | | | Notes: svn path=/head/; revision=116182
* Don't pass NULL pointer to memset if we are compiled with DIAGNOSTICPoul-Henning Kamp2003-05-121-4/+3
| | | | | | | Approved by: re/rwatson Notes: svn path=/head/; revision=114935
* Add two KASSERTS which trigger if free(9) would drag the "memuse" statisticPoul-Henning Kamp2003-05-051-0/+6
| | | | | | | | for a malloc bucket under zero. This typically happens if you malloc(9) from one bucket and free to another. Notes: svn path=/head/; revision=114713
* Update the "last malloc failure timestamp" also for simulatedPoul-Henning Kamp2003-04-251-0/+1
| | | | | | | malloc errors. Notes: svn path=/head/; revision=114042
* Permit debug.malloc.failure_rate to be specified using a tunable soRobert Watson2003-03-261-0/+1
| | | | | | | | | | that the feature can be enabled during the boot process. Note the continued limitation that FreeBSD fails so rapidly with this setting enabled that it's hard to narrow down particular failures for correction; we really need per-malloc type failure rates. Notes: svn path=/head/; revision=112692
* Add a new kernel option, MALLOC_MAKE_FAILURES, which compilesRobert Watson2003-03-261-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in a debugging feature causing M_NOWAIT allocations to fail at a specified rate. This can be useful for detecting poor handling of M_NOWAIT: the most frequent problems I've bumped into are unconditional deference of the pointer even though it's NULL, and hangs as a result of a lost event where memory for the event couldn't be allocated. Two sysctls are added: debug.malloc.failure_rate How often to generate a failure: if set to 0 (default), this feature is disabled. Otherwise, the frequency of failures -- I've been using 10 (one in ten mallocs fails), but other popular settings might be much lower or much higher. debug.malloc.failure_count Number of times a coerced malloc failure has occurred as a result of this feature. Useful for tracking what might have happened and whether failures are being generated. Useful possible additions: tying failure rate to malloc type, printfs indicating the thread that experienced the coerced failure. Reviewed by: jeffr, jhb Notes: svn path=/head/; revision=112689
* PHCC[1]:Poul-Henning Kamp2003-03-101-2/+2
| | | | | | | | | | | | | I had commented the #ifdef INVARIANTS checks out to make sure I ran this code in all kernels and forgot to comment the #ifdefs back in before I committed. Spotted by: bmilekic [1] PHCC = Pointy Hat Correction Commit Notes: svn path=/head/; revision=112066
* Make malloc and mbuf allocation mode flags nonoverlapping.Poul-Henning Kamp2003-03-101-1/+18
| | | | | | | | | Under INVARIANTS whine if we get incompatible flags. Submitted by: imp Notes: svn path=/head/; revision=112063
* o Allow "buckets" in mb_alloc to be differently sized (according toBosko Milekic2003-02-201-2/+1
| | | | | | | | | | | | | | | | | | | compile-time constants). That is, a "bucket" now is not necessarily a page-worth of mbufs or clusters, but it is MBUF_BUCK_SZ, CLUS_BUCK_SZ worth of mbufs, clusters. o Rename {mbuf,clust}_limit to {mbuf,clust}_hiwm and introduce {mbuf,clust}_lowm, which currently has no effect but will be used to set the low watermarks. o Fix netstat so that it can deal with the differently-sized buckets and teach it about the low watermarks too. o Make sure the per-cpu stats for an absent CPU has mb_active set to 0, explicitly. o Get rid of the allocate refcounts from mbuf map mess. Instead, just malloc() the refcounts in one shot from mbuf_init() o Clean up / update comments in subr_mbuf.c Notes: svn path=/head/; revision=111164
* Back out M_* changes, per decision of the TRB.Warner Losh2003-02-191-4/+4
| | | | | | | Approved by: trb Notes: svn path=/head/; revision=111119
* Under #ifdef DIAGNOSTIC, fill malloc(9) allocations which do not havePoul-Henning Kamp2003-02-011-0/+8
| | | | | | | M_ZERO specified with 0x70. (malloc_flags=J for the kernel :-) Notes: svn path=/head/; revision=110186
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.Alfred Perlstein2003-01-211-4/+4
| | | | | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT. Notes: svn path=/head/; revision=109623
* Introduce malloc_last_fail() which returns the number of seconds sincePoul-Henning Kamp2002-11-011-0/+16
| | | | | | | | | | | | malloc(9) failed last time. This is intended to help code adjust memory usage to the current circumstances. A typical use could be: if (malloc_last_fail() < 60) reduce_cache_by_one(); Notes: svn path=/head/; revision=106305
* - Split UMA_ZFLAG_OFFPAGE into UMA_ZFLAG_OFFPAGE and UMA_ZFLAG_HASH.Jeff Roberson2002-09-181-33/+9
| | | | | | | | | | - Remove all instances of the mallochash. - Stash the slab pointer in the vm page's object pointer when allocating from the kmem_obj. - Use the overloaded object pointer to find slabs for malloced memory. Notes: svn path=/head/; revision=103531
* - Replace the bandaid introduced in revision 1.110 withRobert Drehmel2002-05-311-1/+3
| | | | | | | | | a better solution. - Add braces for a ``for'' statement containing a single multi-line statement. Notes: svn path=/head/; revision=97655
* Add a bandaid so that sysctl kern.malloc works on sparc64.Jake Burkholder2002-05-201-1/+1
| | | | Notes: svn path=/head/; revision=97009
* Fix the td_intr_nesting_level check to work ok if a flag like M_ZERO isJohn Baldwin2002-05-201-3/+1
| | | | | | | passed in with M_WAITOK to malloc(). Notes: svn path=/head/; revision=97005
* Hide a pointer to the malloc_type bucket at the end of the freed memory. IfJeff Roberson2002-05-021-1/+19
| | | | | | | | this memory is modified after it has been freed we can now report it's previous owner. Notes: svn path=/head/; revision=95931
* malloc/free(9) no longer require Giant. Use the malloc_mtx to protect theJeff Roberson2002-05-021-1/+21
| | | | | | | | | | mallochash. Mallochash is going to go away as soon as I introduce the kfree/kmalloc api and partially overhaul the malloc wrapper. This can't happen until all users of the malloc api that expect memory to be aligned on the size of the allocation are fixed. Notes: svn path=/head/; revision=95923
* Remove the temporary alignment check in free().Jeff Roberson2002-05-021-6/+0
| | | | | | | | | | | | | | Implement the following checks on freed memory in the bucket path: - Slab membership - Alignment - Duplicate free This previously was only done if we skipped the buckets. This code will slow down INVARIANTS a bit, but it is smp safe. The checks were moved out of the normal path and into hooks supplied in uma_dbg. Notes: svn path=/head/; revision=95899
* Convert longs to u_longs in stats. This will hold off wrap arounds for aJeff Roberson2002-04-301-1/+1
| | | | | | | while longer. Notes: svn path=/head/; revision=95824
* Add a new UMA debugging facility. This will overwrite freed memory withJeff Roberson2002-04-301-2/+8
| | | | | | | | | | | | | | 0xdeadc0de and then check for it just before memory is handed off as part of a new request. This will catch any post free/pre alloc modification of memory, as well as introduce errors for anything that tries to dereference it as a pointer. This code takes the form of special init, fini, ctor and dtor routines that are specificly used by malloc. It is in a seperate file because additional debugging aids will want to live here as well. Notes: svn path=/head/; revision=95771
* Move the implementation of M_ZERO into UMA so that it can be passed toJeff Roberson2002-04-301-3/+0
| | | | | | | | | uma_zalloc and friends. Remove this functionality from the malloc wrapper. Document this change in uma.h and adjust variable names in uma_core. Notes: svn path=/head/; revision=95766
* Re-add the 16384 bucket also.Robert Watson2002-04-291-0/+1
| | | | | | | Submitted by: green Notes: svn path=/head/; revision=95743
* Revert a portion of kern_malloc.c:1.99, which (in addition to addingRobert Watson2002-04-291-1/+3
| | | | | | | | | | | | | | | | malloc profiling) also modified the set of pre-defined buckets for the memory allocator. For reasons unknown to me, this resulted in extensive memory corruption in the kernel, in particular on SMP boxes, so I'm committing this work-around until Jeff gets a chance to debug it properly. David Wolfskill pointed me at this commit as the one that might be a problem; I've been running this code on two dual-processor burn-in boxes for about 12 hours now, and the rate of panics due to memory corruption has dropped to zero (from one every five minutes). Hopefully not treading on the toes of: jeff Notes: svn path=/head/; revision=95742
* Add a basic sanity check on pointers passed to free(9).Poul-Henning Kamp2002-04-231-0/+10
| | | | | | | Should be improved by: jeff Notes: svn path=/head/; revision=95319
* Finish adding support code for sysctl kern.mprof. This dumps some mallocJeff Roberson2002-04-151-11/+68
| | | | | | | | | | | | | | | | | | | | information related to bucket size effeciency. Three things are printed on each row: Size is the size the user actually asked for rounded to 16 bytes. Requests is the number of times this size was asked for. Real Size is the size we actually handed out. At the end the total memory used and total waste is displayed. Currently my system displays about 33% wasted memory. The intent of this code is to gather statistics for tuning the malloc bucket sizes. It is not intended to be run with INVARIANTS and it is not entirely mp safe. It can be enabled via 'options MALLOC_PROFILE' which was commited earlier. Notes: svn path=/head/; revision=94730
* Remove malloc_type's ks_limit.Jeff Roberson2002-04-151-84/+135
| | | | | | | | | | | | | | | Updated the kmemzones logic such that the ks_size bitmap can be used as an index into it to report the size of the zone used. Create the kern.malloc sysctl which replaces the kvm mechanism to report similar data. This will provide an easy place for statistics aggregation if malloc_type statistics become per cpu data. Add some code ifdef'd under MALLOC_PROFILING to facilitate a tool for sizing the malloc buckets. Notes: svn path=/head/; revision=94729
* Change callers of mtx_init() to pass in an appropriate lock type name. InJohn Baldwin2002-04-041-1/+1
| | | | | | | | | | most cases NULL is passed, but in some cases such as network driver locks (which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used. Tested on: i386, alpha, sparc64 Notes: svn path=/head/; revision=93818
* Remove __P.Alfred Perlstein2002-03-191-1/+1
| | | | Notes: svn path=/head/; revision=92723
* This is the first part of the new kernel memory allocator. This replacesJeff Roberson2002-03-191-299/+122
| | | | | | | | | malloc(9) and vm_zone with a slab like allocator. Reviewed by: arch@ Notes: svn path=/head/; revision=92654
* Add realloc() and reallocf(), and make free(NULL, ...) acceptable.Archie Cobbs2002-03-131-0/+74
| | | | | | | Reviewed by: alfred Notes: svn path=/head/; revision=92194
* KSE Milestone 2Julian Elischer2001-09-121-1/+1
| | | | | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha Notes: svn path=/head/; revision=83366
* - Remove asleep(), await(), and M_ASLEEP.John Baldwin2001-08-101-9/+0
| | | | | | | | | | | | - Callers of asleep() and await() have been converted to calling tsleep(). The only caller outside of M_ASLEEP was the ata driver, which called both asleep() and await() with spl-raised, so there was no need for the asleep() and await() pair. M_ASLEEP was unused. Reviewed by: jasone, peter Notes: svn path=/head/; revision=81398
* Rename mb_init() mbuf subsystem initialization routine to mbuf_init(), inBosko Milekic2001-08-031-1/+1
| | | | | | | | | | | order to avoid namespace collision with subr_mchain.c's mb_init(). This wasn't "fatal" as the mbuf initialization routine mb_init() was local to subr_mbuf.c which in turn didn't pull in subr_mchain.c's mb_init() declaration, but it should deffinately be changed now before it creates headache. Notes: svn path=/head/; revision=81089
* Remove some code that appears to have endian problems with INVARIANTS.Jake Burkholder2001-08-031-5/+0
| | | | | | | | This is #if BIG_ENDIAN, but is only necessary if malloc types are shorts, not struct malloc_type * like they are now. Notes: svn path=/head/; revision=81088
* Introduce numerous SMP friendly changes to the mbuf allocator. Namely,Bosko Milekic2001-06-221-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | introduce a modified allocation mechanism for mbufs and mbuf clusters; one which can scale under SMP and which offers the possibility of resource reclamation to be implemented in the future. Notable advantages: o Reduce contention for SMP by offering per-CPU pools and locks. o Better use of data cache due to per-CPU pools. o Much less code cache pollution due to excessively large allocation macros. o Framework for `grouping' objects from same page together so as to be able to possibly free wired-down pages back to the system if they are no longer needed by the network stacks. Additional things changed with this addition: - Moved some mbuf specific declarations and initializations from sys/conf/param.c into mbuf-specific code where they belong. - m_getclr() has been renamed to m_get_clrd() because the old name is really confusing. m_getclr() HAS been preserved though and is defined to the new name. No tree sweep has been done "to change the interface," as the old name will continue to be supported and is not depracated. The change was merely done because m_getclr() sounds too much like "m_get a cluster." - TEMPORARILY disabled mbtypes statistics displaying in netstat(1) and systat(1) (see TODO below). - Fixed systat(1) to display number of "free mbufs" based on new per-CPU stat structures. - Fixed netstat(1) to display new per-CPU stats based on sysctl-exported per-CPU stat structures. All infos are fetched via sysctl. TODO (in order of priority): - Re-enable mbtypes statistics in both netstat(1) and systat(1) after introducing an SMP friendly way to collect the mbtypes stats under the already introduced per-CPU locks (i.e. hopefully don't use atomic() - it seems too costly for a mere stat update, especially when other locks are already present). - Optionally have systat(1) display not only "total free mbufs" but also "total free mbufs per CPU pool." - Fix minor length-fetching issues in netstat(1) related to recently re-enabled option to read mbuf stats from a core file. - Move reference counters at least for mbuf clusters into an unused portion of the cluster itself, to save space and need to allocate a counter. - Look into introducing resource freeing possibly from a kproc. Reviewed by (in parts): jlemon, jake, silby, terry Tested by: jlemon (Intel & Alpha), mjacob (Intel & Alpha) Preliminary performance measurements: jlemon (and me, obviously) URL: http://people.freebsd.org/~bmilekic/mb_alloc/ Notes: svn path=/head/; revision=78592
* "Fix" the previous initial attempt at fixing TUNABLE_INT(). This timePeter Wemm2001-06-081-1/+1
| | | | | | | | | | around, use a common function for looking up and extracting the tunables from the kernel environment. This saves duplicating the same function over and over again. This way typically has an overhead of 8 bytes + the path string, versus about 26 bytes + the path string. Notes: svn path=/head/; revision=77900
* Back out part of my previous commit. This was a last minute changePeter Wemm2001-06-071-1/+1
| | | | | | | | and I botched testing. This is a perfect example of how NOT to do this sort of thing. :-( Notes: svn path=/head/; revision=77853
* Make the TUNABLE_*() macros look and behave more consistantly like thePeter Wemm2001-06-061-7/+6
| | | | | | | | SYSCTL_*() macros. TUNABLE_INT_DECL() was an odd name because it didn't actually declare the int, which is what the name suggests it would do. Notes: svn path=/head/; revision=77843
* Undo part of the tangle of having sys/lock.h and sys/mutex.h included inMark Murray2001-05-011-1/+1
| | | | | | | | | | | | | | other "system" header files. Also help the deprecation of lockmgr.h by making it a sub-include of sys/lock.h and removing sys/lockmgr.h form kernel .c files. Sort sys/*.h includes where possible in affected files. OK'ed by: bde (with reservations) Notes: svn path=/head/; revision=76166
* Fix inconsistency in setup of kernel_map: we need to make sure thatBosko Milekic2001-04-181-2/+2
| | | | | | | | | | | we also reserve _adequate_ space for the mb_map submap; i.e. we need space for nmbclusters, nmbufs, _and_ nmbcnt. Furthermore, we need to rounddown, and not roundup, so that we are consistent. Pointed out by: bde Notes: svn path=/head/; revision=75686
* Change and clean the mutex lock interface.Bosko Milekic2001-02-091-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mtx_enter(lock, type) becomes: mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks) mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized) similarily, for releasing a lock, we now have: mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN. We change the caller interface for the two different types of locks because the semantics are entirely different for each case, and this makes it explicitly clear and, at the same time, it rids us of the extra `type' argument. The enter->lock and exit->unlock change has been made with the idea that we're "locking data" and not "entering locked code" in mind. Further, remove all additional "flags" previously passed to the lock acquire/release routines with the exception of two: MTX_QUIET and MTX_NOSWITCH The functionality of these flags is preserved and they can be passed to the lock/unlock routines by calling the corresponding wrappers: mtx_{lock, unlock}_flags(lock, flag(s)) and mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN locks, respectively. Re-inline some lock acq/rel code; in the sleep lock case, we only inline the _obtain_lock()s in order to ensure that the inlined code fits into a cache line. In the spin lock case, we inline recursion and actually only perform a function call if we need to spin. This change has been made with the idea that we generally tend to avoid spin locks and that also the spin locks that we do have and are heavily used (i.e. sched_lock) do recurse, and therefore in an effort to reduce function call overhead for some architectures (such as alpha), we inline recursion for this case. Create a new malloc type for the witness code and retire from using the M_DEV type. The new type is called M_WITNESS and is only declared if WITNESS is enabled. Begin cleaning up some machdep/mutex.h code - specifically updated the "optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently need those. Finally, caught up to the interface changes in all sys code. Contributors: jake, jhb, jasone (in no particular order) Notes: svn path=/head/; revision=72200
* Let M_PANIC go back to the private tree as its intention isn't understood wellBoris Popov2001-01-311-6/+2
| | | | | | | for now. Notes: svn path=/head/; revision=71859
* Add M_PANIC flag to the list of available flags passed to malloc().Boris Popov2001-01-291-2/+6
| | | | | | | | | | With this flag set malloc() will panic if memory allocation failed. This usable only in critical places where failed allocation is fatal. Reviewed by: peter Notes: svn path=/head/; revision=71799
* p->p_intr_nesting_level is MI now and initialized to 0 in kern_fork.c,Peter Wemm2001-01-271-1/+1
| | | | | | | | so it should be save to KASSERT() on it even on an arch that may not use it. Notes: svn path=/head/; revision=71707
* Don't grab Giant when calling kmem_alloc/kmem_free as this is justJohn Baldwin2001-01-241-4/+0
| | | | | | | | encouraging other people to follow the same practice. If this is going to be done, then it should be done inside of those two functions instead. Notes: svn path=/head/; revision=71501
* Make intr_nesting_level per-process, rather than per-cpu. SetupJake Burkholder2001-01-211-1/+2
| | | | | | | | | | | interrupt threads to run with it always >= 1, so that malloc can detect M_WAITOK from "interrupt" context. This is also necessary in order to context switch from sched_ithd() directly. Reviewed By: peter Notes: svn path=/head/; revision=71337