svn commit: r214888 - in stable/7: share/man/man9 sys/vm
Lawrence Stewart
lstewart at FreeBSD.org
Sat Nov 6 15:21:46 UTC 2010
Author: lstewart
Date: Sat Nov 6 15:21:46 2010
New Revision: 214888
URL: http://svn.freebsd.org/changeset/base/214888
Log:
MFC r213910:
- Simplify implementation of uma_zone_get_max.
- Add uma_zone_get_cur which returns the current approximate occupancy of a
zone. This is useful for providing stats via sysctl amongst other things.
Sponsored by: FreeBSD Foundation
Reviewed by: gnn, jhb
Modified:
stable/7/share/man/man9/zone.9
stable/7/sys/vm/uma.h
stable/7/sys/vm/uma_core.c
Directory Properties:
stable/7/share/man/ (props changed)
stable/7/share/man/man1/ (props changed)
stable/7/share/man/man3/ (props changed)
stable/7/share/man/man4/ (props changed)
stable/7/share/man/man5/ (props changed)
stable/7/share/man/man7/ (props changed)
stable/7/share/man/man8/ (props changed)
stable/7/share/man/man9/ (props changed)
stable/7/sys/ (props changed)
stable/7/sys/cddl/contrib/opensolaris/ (props changed)
stable/7/sys/contrib/dev/acpica/ (props changed)
stable/7/sys/contrib/pf/ (props changed)
Modified: stable/7/share/man/man9/zone.9
==============================================================================
--- stable/7/share/man/man9/zone.9 Sat Nov 6 15:10:31 2010 (r214887)
+++ stable/7/share/man/man9/zone.9 Sat Nov 6 15:21:46 2010 (r214888)
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd June 19, 2008
+.Dd October 9, 2010
.Dt ZONE 9
.Os
.Sh NAME
@@ -35,7 +35,9 @@
.Nm uma_zfree ,
.Nm uma_zfree_arg ,
.Nm uma_zdestroy ,
-.Nm uma_zone_set_max
+.Nm uma_zone_set_max,
+.Nm uma_zone_get_max,
+.Nm uma_zone_get_cur
.Nd zone allocator
.Sh SYNOPSIS
.In sys/param.h
@@ -59,6 +61,10 @@
.Fn uma_zdestroy "uma_zone_t zone"
.Ft void
.Fn uma_zone_set_max "uma_zone_t zone" "int nitems"
+.Ft int
+.Fn uma_zone_get_max "uma_zone_t zone"
+.Ft int
+.Fn uma_zone_get_cur "uma_zone_t zone"
.Sh DESCRIPTION
The zone allocator provides an efficient interface for managing
dynamically-sized collections of items of similar size.
@@ -177,21 +183,36 @@ must have been freed with
.Fn uma_zfree
before.
.Pp
-The purpose of
+The
.Fn uma_zone_set_max
-is to limit the maximum amount of memory that the system can dedicated
-toward the zone specified by the
-.Fa zone
-argument.
+function limits the number of items
+.Pq and therefore memory
+that can be allocated to
+.Fa zone .
The
.Fa nitems
-argument gives the upper limit of items in the zone.
-This limits the total number of items in the zone which includes:
+argument specifies the requested upper limit number of items.
+The effective limit may end up being higher than requested, as the
+implementation will round up to ensure all memory pages allocated to the zone
+are utilised to capacity.
+The limit applies to the total number of items in the zone, which includes
allocated items, free items and free items in the per-cpu caches.
On systems with more than one CPU it may not be possible to allocate
the specified number of items even when there is no shortage of memory,
because all of the remaining free items may be in the caches of the
other CPUs when the limit is hit.
+.Pp
+The
+.Fn uma_zone_get_max
+function returns the effective upper limit number of items for a zone.
+.Pp
+The
+.Fn uma_zone_get_cur
+function returns the approximate current occupancy of the zone.
+The returned value is approximate because appropriate synchronisation to
+determine an exact value is not performend by the implementation.
+This ensures low overhead at the expense of potentially stale data being used
+in the calculation.
.Sh RETURN VALUES
The
.Fn uma_zalloc
Modified: stable/7/sys/vm/uma.h
==============================================================================
--- stable/7/sys/vm/uma.h Sat Nov 6 15:10:31 2010 (r214887)
+++ stable/7/sys/vm/uma.h Sat Nov 6 15:21:46 2010 (r214888)
@@ -443,6 +443,17 @@ void uma_zone_set_max(uma_zone_t zone, i
int uma_zone_get_max(uma_zone_t zone);
/*
+ * Obtains the approximate current number of items allocated from a zone
+ *
+ * Arguments:
+ * zone The zone to obtain the current allocation count from
+ *
+ * Return:
+ * int The approximate current number of items allocated from the zone
+ */
+int uma_zone_get_cur(uma_zone_t zone);
+
+/*
* The following two routines (uma_zone_set_init/fini)
* are used to set the backend init/fini pair which acts on an
* object as it becomes allocated and is placed in a slab within
Modified: stable/7/sys/vm/uma_core.c
==============================================================================
--- stable/7/sys/vm/uma_core.c Sat Nov 6 15:10:31 2010 (r214887)
+++ stable/7/sys/vm/uma_core.c Sat Nov 6 15:21:46 2010 (r214888)
@@ -2529,16 +2529,36 @@ uma_zone_get_max(uma_zone_t zone)
ZONE_LOCK(zone);
keg = zone->uz_keg;
- if (keg->uk_maxpages)
- nitems = keg->uk_maxpages * keg->uk_ipers;
- else
- nitems = 0;
+ nitems = keg->uk_maxpages * keg->uk_ipers;
ZONE_UNLOCK(zone);
return (nitems);
}
/* See uma.h */
+int
+uma_zone_get_cur(uma_zone_t zone)
+{
+ int64_t nitems;
+ u_int i;
+
+ ZONE_LOCK(zone);
+ nitems = zone->uz_allocs - zone->uz_frees;
+ CPU_FOREACH(i) {
+ /*
+ * See the comment in sysctl_vm_zone_stats() regarding the
+ * safety of accessing the per-cpu caches. With the zone lock
+ * held, it is safe, but can potentially result in stale data.
+ */
+ nitems += zone->uz_cpu[i].uc_allocs -
+ zone->uz_cpu[i].uc_frees;
+ }
+ ZONE_UNLOCK(zone);
+
+ return (nitems < 0 ? 0 : nitems);
+}
+
+/* See uma.h */
void
uma_zone_set_init(uma_zone_t zone, uma_init uminit)
{
More information about the svn-src-stable
mailing list