Commit Graph

52 Commits

Author SHA1 Message Date
Jeff Roberson
fc03d22b17 Refine UMA bucket allocation to reduce space consumption and improve
performance.

 - Always free to the alloc bucket if there is space.  This gives LIFO
   allocation order to improve hot-cache performance.  This also allows
   for zones with a single bucket per-cpu rather than a pair if the entire
   working set fits in one bucket.
 - Enable per-cpu caches of buckets.  To prevent recursive bucket
   allocation one bucket zone still has per-cpu caches disabled.
 - Pick the initial bucket size based on a table driven maximum size
   per-bucket rather than the number of items per-page.  This gives
   more sane initial sizes.
 - Only grow the bucket size when we face contention on the zone lock, this
   causes bucket sizes to grow more slowly.
 - Adjust the number of items per-bucket to account for the header space.
   This packs the buckets more efficiently per-page while making them
   not quite powers of two.
 - Eliminate the per-zone free bucket list.  Always return buckets back
   to the bucket zone.  This ensures that as zones grow into larger
   bucket sizes they eventually discard the smaller sizes.  It persists
   fewer buckets in the system.  The locking is slightly trickier.
 - Only switch buckets in zalloc, not zfree, this eliminates pathological
   cases where we ping-pong between two buckets.
 - Ensure that the thread that fills a new bucket gets to allocate from
   it to give a better upper bound on allocation time.

Sponsored by:	EMC / Isilon Storage Division
2013-06-18 04:50:20 +00:00
Matthew D Fleming
bb196eb480 Const-ify the zone name argument to uma_zcreate(9).
MFC after:	3 days
2012-10-26 17:51:05 +00:00
Glen Barber
3102cfe2e2 Fix various typos in manual pages.
Submitted by:	amdmi3
PR:		165431
MFC after:	1 week
2012-02-25 14:31:25 +00:00
Sergey Kandaurov
cfc9e655ba Cosmetic cleanup: remove #define LIBMEMSTAT used to prevent a nested
include of opt_vmpage.h from vm/vm_page.h.  opt_vmpage.h was retired
before 7.0 together with options PQ_NOOPT.

Approved by:	re (kib)
MFC after:	3 days
2011-09-02 14:10:42 +00:00
Sergey Kandaurov
1882360b9b Get rid of MAXCPU knowledge used for internal needs only. Switch to
dynamic memory allocation to hold per-CPU memory types data (sized to
mp_maxid for UMA, and to mp_maxcpus for malloc to match the kernel).

That fixes libmemstat with arbitrary large MAXCPU values and therefore
eliminates MEMSTAT_ERROR_TOOMANYCPUS error type.

Reviewed by:	jhb
Approved by:	re (kib)
2011-08-01 09:43:35 +00:00
Attilio Rao
1de471dfee Revert r222363, as bde@ pointed out the initial solution was far more
correct.
2011-05-31 20:59:53 +00:00
Attilio Rao
d361ed4b1c Style fix: cast to size_t rather than u_long when comparing to sizeof()
rets.

Requested by:	kib
2011-05-27 16:01:51 +00:00
Attilio Rao
d40d5f64a2 Sync with -CURRENT 2011-05-10 18:01:53 +00:00
Attilio Rao
be720a4061 Fix a mismerge. 2011-05-08 14:45:53 +00:00
Attilio Rao
34e4a6f408 Revert MAXCPU introduction. In userland it is always 1.
Noted by:	marcel
2011-05-08 14:29:25 +00:00
Attilio Rao
71a19bdc64 Commit the support for removing cpumask_t and replacing it directly with
cpuset_t objects.
That is going to offer the underlying support for a simple bump of
MAXCPU and then support for number of cpus > 32 (as it is today).

Right now, cpumask_t is an int, 32 bits on all our supported architecture.
cpumask_t on the other side is implemented as an array of longs, and
easilly extendible by definition.

The architectures touched by this commit are the following:
- amd64
- i386
- pc98
- arm
- ia64
- XEN

while the others are still missing.
Userland is believed to be fully converted with the changes contained
here.

Some technical notes:
- This commit may be considered an ABI nop for all the architectures
  different from amd64 and ia64 (and sparc64 in the future)
- per-cpu members, which are now converted to cpuset_t, needs to be
  accessed avoiding migration, because the size of cpuset_t should be
  considered unknown
- size of cpuset_t objects is different from kernel and userland (this is
  primirally done in order to leave some more space in userland to cope
  with KBI extensions). If you need to access kernel cpuset_t from the
  userland please refer to example in this patch on how to do that
  correctly (kgdb may be a good source, for example).
- Support for other architectures is going to be added soon
- Only MAXCPU for amd64 is bumped now

The patch has been tested by sbruno and Nicholas Esborn on opteron
4 x 12 pack CPUs. More testing on big SMP is expected to came soon.
pluknet tested the patch with his 8-ways on both amd64 and i386.

Tested by:	pluknet, sbruno, gianni, Nicholas Esborn
Reviewed by:	jeff, jhb, sbruno
2011-05-05 14:39:14 +00:00
Attilio Rao
1d221389b2 Remove the redefinition of MEMSTAT_MAXCPU and just use MAXCPU for that.
Reviewed by:	sbruno
2011-05-02 17:13:40 +00:00
Attilio Rao
77bdc950f4 MFC @ r221286 2011-05-01 00:48:03 +00:00
Joel Dahl
799162a628 Spelling fixes. 2010-08-03 17:40:09 +00:00
Sean Bruno
bf96595915 Add a new column to the output of vmstat -z to indicate the number
of times the system was forced to sleep when requesting a new allocation.

Expand the debugger hook, db_show_uma, to display these results as well.

This has proven to be very useful in out of memory situations when
it is not known why systems have become sluggish or fail in odd ways.

Reviewed by:	rwatson alc
Approved by:	scottl (mentor) peter
Obtained from:	Yahoo Inc.
2010-06-15 19:28:37 +00:00
Ulrich Spörlein
aa12cea2cc mdoc: order prologue macros consistently by Dd/Dt/Os
Although groff_mdoc(7) gives another impression, this is the ordering
most widely used and also required by mdocml/mandoc.

Reviewed by:	ru
Approved by:	philip, ed (mentors)
2010-04-14 19:08:06 +00:00
Ken Smith
3ca3047aee Bump the version of all non-symbol-versioned shared libraries in
preparation for 8.0-RELEASE.  Add the previous version of those
libraries to ObsoleteFiles.inc and bump __FreeBSD_Version.

Reviewed by:    kib
Approved by:    re (rwatson)
2009-07-19 17:25:24 +00:00
John Baldwin
7293f0e67c Update the KVM backend for malloc stats to catch up to the internal structure
BI change from the addition of DTrace malloc(9) probes.

Submitted by:	Ben Kelly  ben of wanderview dot com
2009-05-15 18:25:44 +00:00
Robert Watson
448036945e Make pointer argument to kread_string() const since the kernel structure
field is const, and then employ __DECONST before getting into the kvm
code.  This eliminates a gcc 4.2 warning about losing constification.

__DECONST advice from:	sam
2007-05-21 18:16:04 +00:00
Daniel Eischen
419ecd5dee Bump library versions in preparation for 7.0.
Ok'd by:	kan
2007-05-21 02:49:08 +00:00
Robert Watson
e6a4641532 Fix a comment in memstat.h: errors are associated with memory type lists,
not individual types.

Submitted by:	Bryan Venteicher <bryanv at daemoninthecloset dot org>
MFC after:	3 days
2007-03-15 10:44:18 +00:00
John Birrell
6358aecacd Increase the number of CPUs to 32 to suit sun4v.
Reviewed by: rwatson@
2006-07-26 07:46:32 +00:00
Robert Watson
10b037c1d9 Update copyright for 2006.
MFC after:	3 days
2006-02-11 19:21:39 +00:00
Robert Watson
1d90b80f28 The uma_zone data structure defines the size of its uz_cpu[] array as 1,
but then sizes the containing data structure at run-time to make room
for per-cpu cache data.  Modify libmemstat to separately allocate a
buffer to hold per-cpu cache data, sized based on the run-time mp_maxid
variable when using libkvm to access UMA data.  This avoids reading
invalid cache data from beyond the end of the uma_zone data structure
on the stack, which can result in invalid statistics and/or reads from
invalid kernel addresses.

Foot target practice by:	ps
MFC after:			3 days
2006-02-11 19:19:29 +00:00
Robert Watson
59e012a852 When reporting an error reading from UMA per-cpu cache pointers using KVM,
return a KVM error rather than an out of memory error, so that the caller
reports the KVM error state.  This replaces a misleading error message
with a more accurate although equally confusing one.

MFC after:	3 days
2006-02-11 18:55:03 +00:00
Robert Watson
3f374960e6 Read all_cpus variable out of kmem, and validate CPUs against the all_cpus
cpu mask before looking at the cache entries for the CPU.  For systems
with sparse CPU id arrays, this skips otherwise uninitialized cache
structures.

MFC after:	3 days
2006-02-11 18:44:37 +00:00
Robert Watson
ee4be9485c Correct a typo in the extraction of zone information from UMA using kmem:
bytes = allocated - freed, not bytes = allocated = freed.

MFC after:	3 days
2006-02-11 16:54:00 +00:00
Robert Watson
c21f7757d2 Remove unnecessary and undesirable 'static' from function-local keg
list, which could cause problems for multi-threaded applications
using libmemstat to monitor UMA in more than one thread
simultaneously.

MFC after:	3 days
2006-01-16 00:37:20 +00:00
Ruslan Ermilov
33d6b9fbe6 Tidy up markup and fix two bugs. 2005-11-21 17:18:34 +00:00
Robert Watson
be2cb7fae9 Add symlinks for kvm access methods for memstat(3).
MFC after:	3 days
2005-11-13 13:42:03 +00:00
Ruslan Ermilov
e4a93f1ef8 Add missing shared library interdependencies. 2005-11-10 18:07:07 +00:00
Robert Watson
33f23dc2fb The "Mbuf" zone was renamed "mbuf" to improve consistency, but the code
example in libmemstat.3 was not updated to take this rename into account.
Update the example.

PR:		84946
Submitted by:	Wojciech A. Koszek <dunstan at freebsd dot czest dot pl>
MFC after:	1 day
2005-08-15 10:24:20 +00:00
Robert Watson
513c89ced2 Document kvm(3)-related error constants, and correct minor formatting
nits.
2005-08-09 22:19:30 +00:00
Robert Watson
ba23fa9bd8 Teach libmemstat(3) how to extract malloc(9) statistics using kvm(3),
so that libmemstat can be used to view full memory statistics from
kernel core dumps and /dev/mem.  This is provided via a new query
function, memstat_kvm_malloc(), which is also automatically invoked
by memstat_kvm_all().  A kvm handle must be passed in.

This will allow malloc(9)-specific code to be removed from vmstat(8).
2005-08-06 13:54:03 +00:00
Robert Watson
2286854ff0 Define LIBMEMSTAT so that vm_page.h won't perform a nested include of
opt_vmpage.h.

Remove definition of _KERNEL, it is no longer required in order to
include uma_int.h, as the sensitive parts of uma_int.h (a number of
inlines depending on kernel-only constants) are now protected by
_KERNEL.
2005-08-04 10:06:39 +00:00
Robert Watson
33c20d188c Add memstat_kvm_uma(), an implementation of a libmemstat(3) query routine
that knows how to extract UMA(9) allocator statistics from a core dump or
live memory image using kvm(3).  The caller is expected to provide the
necessary kvm_t handle, which is then used by libmemstat(3).

With these changes, it is trivially straight forward to re-introduce
vmstat -z support on core dumps, which was lost when UMA was introduced.

In the short term, this requires including vm/ include files that are not
intended for extra-kernel use, requiring in turn some ugliness.
2005-08-01 19:07:39 +00:00
Robert Watson
22247a2a38 Correct two libmemstat(3) bugs:
- Move memory_type_list flushing logic from memstat_mtl_free() to
  _memstat_mtl_empty(), a libmemstat-internal function that can
  be called from other parts of the library.  Invoke
  _memstat_mtl_empty() from memstat_mtl_free(), which also frees
  the containing list structure.

  Invoke _memstat_mtl_empty() instead of memstat_mtl_free() in
  various error cases in memstat_malloc.c and memstat_uma.c, which
  previously resulted in the list being freed prematurely.

- Reverse the order of updating the mt_kegfree and mt_free fields
  of the memory_type in memstat_uma.c, otherwise keg free items
  won't be counted properly for non-secondary zones.

MFC after:	3 days
2005-08-01 13:18:21 +00:00
Robert Watson
7f6e27372b If a retrieved UMA zone is a secondary zone, don't report keg free items,
as they actually belong to the  primary zone, and maye otherwise be
reported more than once.

MFC after:	1 day
2005-07-25 09:52:59 +00:00
Robert Watson
e754c6bbb7 Having decided not to provide a libmemstat(3) error number to text
conversion routine, now change my mind and add one, memstat_strerror(3),
which returns a const char * pointer to a string describing the error,
to be used on the results of memstat_mtl_geterror().

While here, also correct a minor typo in the HISTORY man page.

Pointers on improving ease of internationalization would be
appreciated.

MFC after:	1 day
2005-07-24 01:41:47 +00:00
Robert Watson
70ee997ed4 Document additional aspects of libmemstat(3):
- Short description of each memory type access method.

- Descriptions of libmemstat(3) errors and memstat_mtl_geterror(3).

MFC after:	1 day
2005-07-24 01:29:30 +00:00
Robert Watson
345628080d Introduce more formal error handling for libmemstat(3):
- Define a set of libmemstat(3) error constants, which are used by all
  libmemstat(3) methods except for memstat_mtl_alloc(), which allocates
  a memory type list and may return ENOMEM via errno.

- Define a per-memory_type_list current error value, which is set when a
  call associated with a memory list fails.  This requires wrapping a
  structure around the queue(9) list head data structure, but this change
  is not visible to libmemstat(3) consumers due to using access methods.

- Add a new accessor method, memstat_mtl_geterror() to retrieve the error
  number.

- Consistently set the error number in a number of failure modes where
  previously some combination of setting errno and printf'ing error
  descriptions was used.  libmemstat(3) will now no longer print to stdio
  under any circumstances.  Returns of NULL/-1 for errors remain the
  same.

This avoids use of stdio, misuse of error numbers, and should make it
easier to program a libmemstat(3) consumer able to print useful error
messages.  Currently, no error-to-string function is provided, as I'm
unsure how to address internationalization concerns.

MFC after:	1 day
2005-07-24 01:28:54 +00:00
Robert Watson
ddefbc898a Prefix two non-static libmemstat(3) internal functions with '_' symbols, to
try and discourage use outside the library.

Remove duplicate declaration of memstat_mtl_free() from memstat_internal.h,
as it's not internal, and the memstat.h definition suffices.
2005-07-23 21:17:15 +00:00
Robert Watson
ca108fe268 UMA supports "secondary" zones, in which a second zone can be layered
on top of a primary zone, sharing the same allocation "keg".  When
reporting statistics for zones, do not report the free items in the
keg as part of the free items in the zone, or those free items will
be reported more than once: for the primary zone, and then any
secondary zones off the primary zone.  Separately record and maintain
a kegfree statistic, and export via memstat_get_kegfree(), which is
available for use if needed.  Since items free'd back to the keg are
not fully initialized, and hence may not actually be available (since
secondary zone ctor-time initialization can fail), this makes some
amount of sense.

This change corrects a bug made visible in the libmemstat(3)
modifications to netstat: mbufs freed back to the keg from the
packet zone would be counted twice, resulting in negative values
being printed in the mbuf free count.

Some further refinement of reporting relating to secondary zones may
still be required.

Reported by:	ssouhlal
MFC after:	3 days
2005-07-20 09:17:40 +00:00
Robert Watson
919bddddb6 Bump MEMSTAT_MAXCALLER to 16. memtop(8) seems to be able to happily
consume that many slots to track snapshot-to-snapshot changes and
running totals.  And 16 is a nice round number.

MFC after:	1 week
2005-07-18 14:14:17 +00:00
Robert Watson
449ce0e42f Add __BEGIN_DECLS and __END_DECLS to make libmemstat(3) more C++-friendly.
MFC after:	1 week
2005-07-17 13:54:46 +00:00
Robert Watson
d144359bde Teach libmemstat(3) about UMA(9) failure statistics.
Requested by:	victor cruceru <victor dot cruceru at gmail dot com>
MFC after:	1 week
2005-07-15 23:39:21 +00:00
Robert Watson
e86bb57bbf Provide more documentation on caller-owned storage in struct memory_type,
as well as documenting MEMSTAT_MAXCALLER.

MFC after:	1 week
2005-07-15 11:28:21 +00:00
Robert Watson
ccf4e07e83 Increase the number of caller memory storage slots from 2 or 4 to
MEMSTAT_MAXCALLER (8), and expose MEMSTAT_MAXCALLER via memstat.h so
that applications can check their assumptions about how many slots
are available.

Remove 'spare' memory storage in struct malloc_type, since we now
don't expose the data structure internals to applications and rely
on accessor methods, this approach to ABI stability isn't required.

MFC after:	7 days
2005-07-15 11:19:55 +00:00
Robert Watson
09df0a9a09 Add a section on the allocator name space and its interactions with
memstat_mtl_find().

MFC after:	10 days
2005-07-15 10:23:55 +00:00
Robert Watson
3ab4da680f Re-spell wronge less wrongly as wrong.
Submitted by:	jkoshy
MFC after:	1 week
2005-07-15 10:13:50 +00:00