diff options
author | lstewart <lstewart@FreeBSD.org> | 2010-10-16 04:14:45 +0000 |
---|---|---|
committer | lstewart <lstewart@FreeBSD.org> | 2010-10-16 04:14:45 +0000 |
commit | 2770ad22da37ff641831366d79c70e90f0c0c858 (patch) | |
tree | 60814622ef6a50dfe36a1c033e23281a8d0a66fa /sys/vm | |
parent | 86cfb1d139775d0e932f69a5c2c6bc4b7269ec4b (diff) | |
download | FreeBSD-src-2770ad22da37ff641831366d79c70e90f0c0c858.zip FreeBSD-src-2770ad22da37ff641831366d79c70e90f0c0c858.tar.gz |
- 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
MFC after: 2 weeks
Diffstat (limited to 'sys/vm')
-rw-r--r-- | sys/vm/uma.h | 11 | ||||
-rw-r--r-- | sys/vm/uma_core.c | 28 |
2 files changed, 35 insertions, 4 deletions
diff --git a/sys/vm/uma.h b/sys/vm/uma.h index f0522b0..6ab515e 100644 --- a/sys/vm/uma.h +++ b/sys/vm/uma.h @@ -471,6 +471,17 @@ void uma_zone_set_max(uma_zone_t zone, int nitems); 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 diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c index 23b88ee..94b12e5 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -2805,16 +2805,36 @@ uma_zone_get_max(uma_zone_t zone) ZONE_LOCK(zone); keg = zone_first_keg(zone); - 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) { |