Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 2020 01:59:56 +0000 (UTC)
From:      Jeff Roberson <jeff@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r358012 - head/sys/vm
Message-ID:  <202002170159.01H1xuKf094850@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jeff
Date: Mon Feb 17 01:59:55 2020
New Revision: 358012
URL: https://svnweb.freebsd.org/changeset/base/358012

Log:
  Add a simple accessor that returns the bytes of memory consumed by a zone.

Modified:
  head/sys/vm/uma.h
  head/sys/vm/uma_core.c

Modified: head/sys/vm/uma.h
==============================================================================
--- head/sys/vm/uma.h	Mon Feb 17 01:08:00 2020	(r358011)
+++ head/sys/vm/uma.h	Mon Feb 17 01:59:55 2020	(r358012)
@@ -671,6 +671,11 @@ void uma_prealloc(uma_zone_t zone, int itemcnt);
 int uma_zone_exhausted(uma_zone_t zone);
 
 /*
+ * Returns the bytes of memory consumed by the zone.
+ */
+size_t uma_zone_memory(uma_zone_t zone);
+
+/*
  * Common UMA_ZONE_PCPU zones.
  */
 extern uma_zone_t pcpu_zone_int;

Modified: head/sys/vm/uma_core.c
==============================================================================
--- head/sys/vm/uma_core.c	Mon Feb 17 01:08:00 2020	(r358011)
+++ head/sys/vm/uma_core.c	Mon Feb 17 01:59:55 2020	(r358012)
@@ -4681,6 +4681,27 @@ uma_prealloc(uma_zone_t zone, int items)
 	}
 }
 
+/*
+ * Returns a snapshot of memory consumption in bytes.
+ */
+size_t
+uma_zone_memory(uma_zone_t zone)
+{
+	size_t sz;
+	int i;
+
+	sz = 0;
+	if (zone->uz_flags & UMA_ZFLAG_CACHE) {
+		for (i = 0; i < vm_ndomains; i++)
+			sz += zone->uz_domain[i].uzd_nitems;
+		return (sz * zone->uz_size);
+	}
+	for (i = 0; i < vm_ndomains; i++)
+		sz += zone->uz_keg->uk_domain[i].ud_pages;
+
+	return (sz * PAGE_SIZE);
+}
+
 /* See uma.h */
 void
 uma_reclaim(int req)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002170159.01H1xuKf094850>