From: Stefan Fritsch Subject: Count m_pool_alloc() failures in netstat -m To: tech@openbsd.org Date: Tue, 10 Jun 2025 13:13:03 +0200 Hi, in netstat -m output, there are three counters that have been unused since 2002: 0 requests for memory denied 0 requests for memory delayed 0 calls to protocol drain routines This is confusing and one may think no out of memory situation occurred even if there actually was an mbuf shortage. I propose to use the first of these counters to count m_pool_alloc() failures. This is the sum of the fail counters of the mbufpl and mcl* pools, but having this information available in netstat -m makes debugging easier. I would also delete the other two counters. Diff below. Does one need to do something special when changing the sysctl structs? Comments, opinions? Cheers, Stefan diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index bf2a03ce683..088e30367cf 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -566,8 +566,6 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, mbs.m_mtypes[i] = counters[i]; mbs.m_drops = counters[MBSTAT_DROPS]; - mbs.m_wait = counters[MBSTAT_WAIT]; - mbs.m_drain = counters[MBSTAT_DRAIN]; mbs.m_defrag_alloc = counters[MBSTAT_DEFRAG_ALLOC]; mbs.m_prepend_alloc = counters[MBSTAT_PREPEND_ALLOC]; mbs.m_pullup_alloc = counters[MBSTAT_PULLUP_ALLOC]; diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index b962a4047f5..4f77f9d5906 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1467,6 +1467,7 @@ m_pool_alloc(struct pool *pp, int flags, int *slowdown) return (v); fail: + counters_inc(mbstat, MBSTAT_DROPS); atomic_sub_long(&mbuf_mem_alloc, pp->pr_pgsize); return (NULL); } diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 12afaeb398e..b39c0c5ac3f 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -363,15 +363,13 @@ u_int mextfree_register(void (*)(caddr_t, u_int, void *)); #define MBSTAT_TYPES MT_NTYPES #define MBSTAT_DROPS (MBSTAT_TYPES + 0) -#define MBSTAT_WAIT (MBSTAT_TYPES + 1) -#define MBSTAT_DRAIN (MBSTAT_TYPES + 2) -#define MBSTAT_DEFRAG_ALLOC (MBSTAT_TYPES + 3) -#define MBSTAT_PREPEND_ALLOC (MBSTAT_TYPES + 4) -#define MBSTAT_PULLUP_ALLOC (MBSTAT_TYPES + 5) -#define MBSTAT_PULLUP_COPY (MBSTAT_TYPES + 6) -#define MBSTAT_PULLDOWN_ALLOC (MBSTAT_TYPES + 7) -#define MBSTAT_PULLDOWN_COPY (MBSTAT_TYPES + 8) -#define MBSTAT_COUNT (MBSTAT_TYPES + 9) +#define MBSTAT_DEFRAG_ALLOC (MBSTAT_TYPES + 1) +#define MBSTAT_PREPEND_ALLOC (MBSTAT_TYPES + 2) +#define MBSTAT_PULLUP_ALLOC (MBSTAT_TYPES + 3) +#define MBSTAT_PULLUP_COPY (MBSTAT_TYPES + 4) +#define MBSTAT_PULLDOWN_ALLOC (MBSTAT_TYPES + 5) +#define MBSTAT_PULLDOWN_COPY (MBSTAT_TYPES + 6) +#define MBSTAT_COUNT (MBSTAT_TYPES + 7) /* * Mbuf statistics. @@ -380,8 +378,6 @@ u_int mextfree_register(void (*)(caddr_t, u_int, void *)); */ struct mbstat { u_long m_drops; /* times failed to find space */ - u_long m_wait; /* times waited for space */ - u_long m_drain; /* times drained protocols for space */ u_long m_mtypes[MBSTAT_TYPES]; /* type specific mbuf allocations */ u_long m_defrag_alloc; diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index 7660f832630..8663183d975 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -203,8 +203,6 @@ mbpr(void) "(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); printf("%lu defrag mbuf allocation\n", mbstat.m_defrag_alloc); printf("%lu prepend mbuf allocation\n", mbstat.m_prepend_alloc); printf("%lu pullup mbuf allocation\n", mbstat.m_pullup_alloc);