diff options
Diffstat (limited to 'sys')
| -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 548cd2834de2..ce86818527d3 100644 --- a/sys/vm/uma.h +++ b/sys/vm/uma.h @@ -443,6 +443,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 f7634500bf37..bd33def34571 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -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) { |
