summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikeb <mikeb@openbsd.org>2017-10-28 15:25:20 +0000
committermikeb <mikeb@openbsd.org>2017-10-28 15:25:20 +0000
commit06d39c1b2d073f0f441b3d12633e732facd74174 (patch)
tree9ab76d6a5d7fbb9ce95dff94119e354755348049
parentAdd the compat-mode setup for wsmouse. (diff)
downloadwireguard-openbsd-06d39c1b2d073f0f441b3d12633e732facd74174.tar.xz
wireguard-openbsd-06d39c1b2d073f0f441b3d12633e732facd74174.zip
Bring "netstat -m" output up to speed with the kernel
The kernel no longer sets watermarks on cluster pools rendering "max" values useless. Instead, there's now a global limit on how much memory all cluster pools combined together can allocate from the system. The limit is set to kern.maxclusters number of 2Kb increments which allows us to display current, peak and maximum total memory used by the network. OK claudio, millert
-rw-r--r--usr.bin/netstat/mbuf.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c
index f7970a57c32..13ac8e78c11 100644
--- a/usr.bin/netstat/mbuf.c
+++ b/usr.bin/netstat/mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.c,v 1.39 2017/02/04 13:17:08 jsg Exp $ */
+/* $OpenBSD: mbuf.c,v 1.40 2017/10/28 15:25:20 mikeb Exp $ */
/* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */
/*
@@ -87,9 +87,8 @@ bool seen[256]; /* "have we seen this type yet?" */
void
mbpr(void)
{
- unsigned long totmem, totused, totmbufs;
- int totpct;
- int i, mib[4], npools;
+ unsigned long totmem, totpeak, totmbufs;
+ int i, maxclusters, mib[4], npools;
struct kinfo_pool pool;
struct mbtypes *mp;
size_t size;
@@ -102,6 +101,16 @@ mbpr(void)
}
mib[0] = CTL_KERN;
+ mib[1] = KERN_MAXCLUSTERS;
+ size = sizeof(maxclusters);
+
+ if (sysctl(mib, 2, &maxclusters, &size, NULL, 0) < 0) {
+ printf("Can't retrieve value of maxclusters from the "
+ "kernel: %s\n", strerror(errno));
+ return;
+ }
+
+ mib[0] = CTL_KERN;
mib[1] = KERN_MBSTAT;
size = sizeof(mbstat);
@@ -176,23 +185,21 @@ mbpr(void)
plural(mbstat.m_mtypes[i]), i);
}
totmem = (mbpool.pr_npages * mbpool.pr_pgsize);
- totused = mbpool.pr_nout * mbpool.pr_size;
+ totpeak = mbpool.pr_hiwat * mbpool.pr_pgsize;
for (i = 0; i < mclp; i++) {
- printf("%u/%lu/%lu mbuf %d byte clusters in use"
- " (current/peak/max)\n",
+ printf("%u/%lu mbuf %d byte clusters in use"
+ " (current/peak)\n",
mclpools[i].pr_nout,
(unsigned long)
(mclpools[i].pr_hiwat * mclpools[i].pr_itemsperpage),
- (unsigned long)
- (mclpools[i].pr_maxpages * mclpools[i].pr_itemsperpage),
mclpools[i].pr_size);
totmem += (mclpools[i].pr_npages * mclpools[i].pr_pgsize);
- totused += mclpools[i].pr_nout * mclpools[i].pr_size;
+ totpeak += mclpools[i].pr_hiwat * mclpools[i].pr_pgsize;
}
- totpct = (totmem == 0) ? 0 : (totused/(totmem / 100));
- printf("%lu Kbytes allocated to network (%d%% in use)\n",
- totmem / 1024, totpct);
+ printf("%lu/%lu/%lu Kbytes allocated to network "
+ "(current/peak/max)\n", totmem / 1024, totpeak / 1024,
+ (unsigned long)(maxclusters * MCLBYTES) / 1024);
printf("%lu requests for memory denied\n", mbstat.m_drops);
printf("%lu requests for memory delayed\n", mbstat.m_wait);
printf("%lu calls to protocol drain routines\n", mbstat.m_drain);