freebsd-skq/sys
rwatson 7035f9f56a Kernel malloc layers malloc_type allocation over one of two underlying
allocators: a set of power-of-two UMA zones for small allocations, and the
VM page allocator for large allocations.  In order to maintain unified
statistics for specific malloc types, kernel malloc maintains a separate
per-type statistics pool, which can be monitored using vmstat -m.  Prior
to this commit, each pool of per-type statistics was protected using a
per-type mutex associated with the malloc type.

This change modifies kernel malloc to maintain per-CPU statistics pools
for each malloc type, and protects writing those statistics using critical
sections.  It also moves to unsynchronized reads of per-CPU statistics
when generating coalesced statistics.  To do this, several changes are
implemented:

- In the previous world order, the statistics memory was allocated by
  the owner of the malloc type structure, allocated statically using
  MALLOC_DEFINE().  This embedded the definition of the malloc_type
  structure into all kernel modules.  Move to a model in which a pointer
  within struct malloc_type points at a UMA-allocated
  malloc_type_internal data structure owned and maintained by
  kern_malloc.c, and not part of the exported ABI/API to the rest of
  the kernel.  For the purposes of easing a possible MFC, re-use an
  existing pointer in 'struct malloc_type', and maintain the current
  malloc_type structure size, as well as layout with respect to the
  fields reused outside of the malloc subsystem (such as ks_shortdesc).
  There are several unused fields as a result of no longer requiring
  the mutex in malloc_type.

- Struct malloc_type_internal contains an array of malloc_type_stats,
  of size MAXCPU.  The structure defined above avoids hard-coding a
  kernel compile-time value of MAXCPU into kernel modules that interact
  with malloc.

- When accessing per-cpu statistics for a malloc type, surround read -
  modify - update requests with critical_enter()/critical_exit() in
  order to avoid races during write.  The per-CPU fields are written
  only from the CPU that owns them.

- Per-CPU stats now maintained "allocated" and "freed" counters for
  number of allocations/frees and bytes allocated/freed, since there is
  no longer a coherent global notion of the totals.  When coalescing
  malloc stats, accept a slight race between reading stats across CPUs,
  and avoid showing the user a negative allocation count for the type
  in the event of a race.  The global high watermark is no longer
  maintained for a malloc type, as there is no global notion of the
  number of allocations.

- While tearing up the sysctl() path, also switch to using sbufs.  The
  current "export as text" sysctl format is retained with the same
  syntax.  We may want to change this in the future to export more
  per-CPU information, such as how allocations and frees are balanced
  across CPUs.

This change results in a substantial speedup of kernel malloc and free
paths on SMP, as critical sections (where usable) out-perform mutexes
due to avoiding atomic/bus-locked operations.  There is also a minor
improvement on UP due to the slightly lower cost of critical sections
there.  The cost of the change to this approach is the loss of a
continuous notion of total allocations that can be exploited to track
per-type high watermarks, as well as increased complexity when
monitoring statistics.

Due to carefully avoiding changing the ABI, as well as hardening the ABI
against future changes, it is not necessary to recompile kernel modules
for this change.  However, MFC'ing this change to RELENG_5 will require
also MFC'ing optimizations for soft critical sections, which may modify
exposed kernel ABIs.  The internal malloc API is changed, and
modifications to vmstat in order to restore "vmstat -m" on core dumps will
follow shortly.

Several improvements from:		bde
Statistics approach discussed with:	ups
Tested by:				scottl, others
2005-05-29 13:38:07 +00:00
..
alpha Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
amd64 Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
arm Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
boot - Add support to the loader for multiple consoles. 2005-05-27 19:31:00 +00:00
bsm Add a stub audit_kevents.h, which defines exactly one audit event: 2005-02-02 14:27:36 +00:00
cam Do not initialize path variable with useless value just before 2005-05-11 17:39:33 +00:00
coda - Change all filesystems and vfs_cache to relock the dvp once the child is 2005-04-13 10:59:09 +00:00
compat Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
conf MFi386: Add ReiserFS 2005-05-25 12:32:06 +00:00
contrib This commit was generated by cvs2svn to compensate for changes in r146539, 2005-05-23 13:08:32 +00:00
crypto gbde(8) is also rejndael user. 2005-03-11 22:07:04 +00:00
ddb Don't enter the debugger if KDB_UNATTENDED is set or if 2005-04-20 20:52:46 +00:00
dev Add vr_init_t member to sc_rndr_sw_t instances in order to unbreak 2005-05-29 12:47:39 +00:00
doc
fs Fix three typos in comments. Two of them obtained from OpenBSD. 2005-05-11 21:10:35 +00:00
gdb check return value of gdb_rx_varhex 2005-03-28 18:31:18 +00:00
geom After provider creation!! 2005-05-25 15:54:17 +00:00
gnu Import of ReiserFS filesystem support (currently limited to read-only on 2005-05-24 12:24:45 +00:00
i4b Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
i386 Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
ia64 Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
isa Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
isofs/cd9660 - Change all filesystems and vfs_cache to relock the dvp once the child is 2005-04-13 10:59:09 +00:00
kern Kernel malloc layers malloc_type allocation over one of two underlying 2005-05-29 13:38:07 +00:00
libkern Fix kiconv on the 64bit plathomes. 2005-05-24 15:38:08 +00:00
modules Connect the ReiserFS filesystem to the modules build (i386 only). 2005-05-24 12:30:13 +00:00
net integrate changes from libpcap-0.9.1-096 2005-05-28 21:56:41 +00:00
net80211 Revise crypto api lightly to improve group key handling: 2005-04-12 17:55:13 +00:00
netatalk When generating a phase II ARP lookup from aarpwhohas(), use a 2005-02-22 14:37:22 +00:00
netatm In the current world order, solisten() implements the state transition of 2005-02-21 21:58:17 +00:00
netgraph Fix check for leading zero, so that it does not block two zeroes 2005-05-29 12:20:41 +00:00
netinet Let OSPFv3 go through ipfw. Some more additional checks would be 2005-05-28 07:46:44 +00:00
netinet6 Fixes for various nits found by the Coverity tool. 2005-05-15 02:28:30 +00:00
netipsec correct space check 2005-03-09 15:28:48 +00:00
netipx Back out ipx.h:1.18, which introduced a Linux API compatibility field in 2005-05-27 12:25:42 +00:00
netkey
netnatm Mark netatm and netnatm explicitly as requiring Giant, as they still do. 2005-02-17 14:21:22 +00:00
netncp avoid potential null ptr derefs 2005-02-23 22:44:38 +00:00
netsmb lockmgr(...,LK_DRAIN,...) requires a balancing LK_RELEASE: recent 2005-05-13 11:27:48 +00:00
nfs
nfs4client - We want if (mrep != NULL) not if (m_freem != NULL). m_freem will never 2005-04-25 05:11:19 +00:00
nfsclient Ugh. Previous commit got the logic exactly backward. 2005-05-17 18:23:03 +00:00
nfsserver NFS write gathering defers execution of NFS server write requests to wait 2005-04-17 16:25:36 +00:00
opencrypto just use crypto/rijndael, and nuke opencrypto/rindael.[ch]. 2005-03-11 17:24:46 +00:00
pc98 Sync with syscons update (Add new member to struct sc_rndr_sw). 2005-05-29 11:53:14 +00:00
pccard Change a directory layout for pc98. 2005-05-10 12:02:18 +00:00
pci Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
posix4 Introduce MAC Framework and MAC Policy entry points to label and control 2005-05-04 10:39:15 +00:00
powerpc The end values passed to rman_manage_region() for PCI i/o and mem 2005-05-29 08:51:21 +00:00
rpc - Don't call rpcclnt_realign() if we don't have any mbufs to realign. 2005-03-19 01:16:25 +00:00
security Introduce MAC Framework and MAC Policy entry points to label and control 2005-05-04 10:39:15 +00:00
sparc64 Remove bus_{mem,p}io.h and related code for a micro-optimization on i386 2005-05-29 04:42:30 +00:00
sys Kernel malloc layers malloc_type allocation over one of two underlying 2005-05-29 13:38:07 +00:00
tools - Add the character "E" to the understood lock types. This means 2005-04-11 15:15:03 +00:00
ufs Allow removal of empty directories with high link counts. These can 2005-05-18 22:18:21 +00:00
vm Update some comments to reflect the change from spl-based to lock-based 2005-05-28 17:56:18 +00:00
Makefile When building cscopnamefile, default architecture to ${MACHINE}, not i386. 2005-03-08 00:09:41 +00:00