From ca108fe268b738a363dde8e3cba5be3bbc2d9cc9 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Wed, 20 Jul 2005 09:17:40 +0000 Subject: 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 --- lib/libmemstat/libmemstat.3 | 2 ++ lib/libmemstat/memstat.c | 8 ++++++++ lib/libmemstat/memstat.h | 1 + lib/libmemstat/memstat_internal.h | 1 + lib/libmemstat/memstat_uma.c | 3 ++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/libmemstat/libmemstat.3 b/lib/libmemstat/libmemstat.3 index cfe4a2bd6188..a97d7baa7052 100644 --- a/lib/libmemstat/libmemstat.3 +++ b/lib/libmemstat/libmemstat.3 @@ -93,6 +93,8 @@ .Ft uint64_t .Fn memstat_get_zonefree "const struct memory_type *mtp" .Ft uint64_t +.Fn memstat_get_kegfree "const struct memory_type *mtp" +.Ft uint64_t .Fn memstat_get_percpu_memalloced "const struct memory_type *mtp" "int cpu" .Ft uint64_t .Fn memstat_get_percpu_memfreed "const struct memory_type *mtp" "int cpu" diff --git a/lib/libmemstat/memstat.c b/lib/libmemstat/memstat.c index f2764ff7bb08..cbab40aa62d3 100644 --- a/lib/libmemstat/memstat.c +++ b/lib/libmemstat/memstat.c @@ -143,6 +143,7 @@ memstat_mt_reset_stats(struct memory_type *mtp) mtp->mt_failures = 0; mtp->mt_zonefree = 0; + mtp->mt_kegfree = 0; for (i = 0; i < MEMSTAT_MAXCPU; i++) { mtp->mt_percpu_alloc[i].mtp_memalloced = 0; @@ -291,6 +292,13 @@ memstat_get_zonefree(const struct memory_type *mtp) return (mtp->mt_zonefree); } +uint64_t +memstat_get_kegfree(const struct memory_type *mtp) +{ + + return (mtp->mt_kegfree); +} + uint64_t memstat_get_percpu_memalloced(const struct memory_type *mtp, int cpu) { diff --git a/lib/libmemstat/memstat.h b/lib/libmemstat/memstat.h index 262c4df982b1..823338b2636b 100644 --- a/lib/libmemstat/memstat.h +++ b/lib/libmemstat/memstat.h @@ -119,6 +119,7 @@ uint64_t memstat_get_caller_uint64(const struct memory_type *mtp, void memstat_set_caller_uint64(struct memory_type *mtp, int index, uint64_t value); uint64_t memstat_get_zonefree(const struct memory_type *mtp); +uint64_t memstat_get_kegfree(const struct memory_type *mtp); uint64_t memstat_get_percpu_memalloced(const struct memory_type *mtp, int cpu); uint64_t memstat_get_percpu_memfreed(const struct memory_type *mtp, diff --git a/lib/libmemstat/memstat_internal.h b/lib/libmemstat/memstat_internal.h index 1e974df06d7d..61eb795a2675 100644 --- a/lib/libmemstat/memstat_internal.h +++ b/lib/libmemstat/memstat_internal.h @@ -85,6 +85,7 @@ struct memory_type { * global stats above. */ uint64_t mt_zonefree; /* Free items in zone. */ + uint64_t mt_kegfree; /* Free items in keg. */ /* * Per-CPU measurements fall into two categories: per-CPU allocation, diff --git a/lib/libmemstat/memstat_uma.c b/lib/libmemstat/memstat_uma.c index 20259310337e..740fe23ddf17 100644 --- a/lib/libmemstat/memstat_uma.c +++ b/lib/libmemstat/memstat_uma.c @@ -222,7 +222,8 @@ retry: mtp->mt_byteslimit = uthp->uth_limit * uthp->uth_size; mtp->mt_count = mtp->mt_numallocs - mtp->mt_numfrees; - mtp->mt_zonefree = uthp->uth_zone_free + uthp->uth_keg_free; + mtp->mt_zonefree = uthp->uth_zone_free; + mtp->mt_kegfree = uthp->uth_keg_free; mtp->mt_free += mtp->mt_zonefree; } -- cgit v1.3