-/* $OpenBSD: kern_sysctl.c,v 1.445 2024/08/26 08:24:25 mvs Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.446 2024/08/29 10:44:40 bluhm Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
return (sysctl_rdstruct(oldp, oldlenp, newp, &bt, sizeof bt));
}
case KERN_MBSTAT: {
- extern struct cpumem *mbstat;
uint64_t counters[MBSTAT_COUNT];
struct mbstat mbs;
unsigned int 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];
+ mbs.m_pullup_copy = counters[MBSTAT_PULLUP_COPY];
+ mbs.m_pulldown_alloc = counters[MBSTAT_PULLDOWN_ALLOC];
+ mbs.m_pulldown_copy = counters[MBSTAT_PULLDOWN_COPY];
return (sysctl_rdstruct(oldp, oldlenp, newp,
&mbs, sizeof(mbs)));
-/* $OpenBSD: uipc_mbuf.c,v 1.290 2024/03/05 18:52:41 bluhm Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.291 2024/08/29 10:44:40 bluhm Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
m_get(int nowait, int type)
{
struct mbuf *m;
- struct counters_ref cr;
- uint64_t *counters;
int s;
KASSERT(type >= 0 && type < MT_NTYPES);
return (NULL);
s = splnet();
- counters = counters_enter(&cr, mbstat);
- counters[type]++;
- counters_leave(&cr, mbstat);
+ counters_inc(mbstat, type);
splx(s);
m->m_type = type;
m_gethdr(int nowait, int type)
{
struct mbuf *m;
- struct counters_ref cr;
- uint64_t *counters;
int s;
KASSERT(type >= 0 && type < MT_NTYPES);
return (NULL);
s = splnet();
- counters = counters_enter(&cr, mbstat);
- counters[type]++;
- counters_leave(&cr, mbstat);
+ counters_inc(mbstat, type);
splx(s);
m->m_type = type;
m_free(struct mbuf *m)
{
struct mbuf *n;
- struct counters_ref cr;
- uint64_t *counters;
int s;
if (m == NULL)
return (NULL);
s = splnet();
- counters = counters_enter(&cr, mbstat);
- counters[m->m_type]--;
- counters_leave(&cr, mbstat);
+ counters_dec(mbstat, m->m_type);
splx(s);
n = m->m_next;
KASSERT(m->m_flags & M_PKTHDR);
+ counters_inc(mbstat, MBSTAT_DEFRAG_ALLOC);
if ((m0 = m_gethdr(how, m->m_type)) == NULL)
return (ENOBUFS);
if (m->m_pkthdr.len > MHLEN) {
m->m_data -= len;
m->m_len += len;
} else {
+ counters_inc(mbstat, MBSTAT_PREPEND_ALLOC);
MGET(mn, how, m->m_type);
if (mn == NULL) {
m_freem(m);
memmove(head, mtod(m0, caddr_t), m0->m_len);
m0->m_data = head;
}
-
len -= m0->m_len;
+ counters_inc(mbstat, MBSTAT_PULLUP_COPY);
} else {
/* the first mbuf is too small or read-only, make a new one */
space = adj + len;
m0->m_next = m;
m = m0;
+ counters_inc(mbstat, MBSTAT_PULLUP_ALLOC);
MGET(m0, M_DONTWAIT, m->m_type);
if (m0 == NULL)
goto bad;
-/* $OpenBSD: uipc_mbuf2.c,v 1.45 2020/12/12 11:48:54 jan Exp $ */
+/* $OpenBSD: uipc_mbuf2.c,v 1.46 2024/08/29 10:44:40 bluhm Exp $ */
/* $KAME: uipc_mbuf2.c,v 1.29 2001/02/14 13:42:10 itojun Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/pool.h>
+#include <sys/percpu.h>
#include <sys/mbuf.h>
extern struct pool mtagpool;
if (len <= n->m_len - off) {
struct mbuf *mlast;
+ counters_inc(mbstat, MBSTAT_PULLDOWN_ALLOC);
o = m_dup1(n, off, n->m_len - off, M_DONTWAIT);
if (o == NULL) {
m_freem(m);
*/
if ((off == 0 || offp) && m_trailingspace(n) >= tlen &&
!sharedcluster) {
+ counters_inc(mbstat, MBSTAT_PULLDOWN_COPY);
m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len);
n->m_len += tlen;
m_adj(n->m_next, tlen);
!sharedcluster && n->m_next->m_len >= tlen) {
n->m_next->m_data -= hlen;
n->m_next->m_len += hlen;
+ counters_inc(mbstat, MBSTAT_PULLDOWN_COPY);
memmove(mtod(n->m_next, caddr_t), mtod(n, caddr_t) + off, hlen);
n->m_len -= hlen;
n = n->m_next;
m_freem(m);
return (NULL);
}
+ counters_inc(mbstat, MBSTAT_PULLDOWN_ALLOC);
MGET(o, M_DONTWAIT, m->m_type);
if (o && len > MLEN) {
MCLGETL(o, M_DONTWAIT, len);
-/* $OpenBSD: mbuf.h,v 1.263 2024/04/14 20:46:27 bluhm Exp $ */
+/* $OpenBSD: mbuf.h,v 1.264 2024/08/29 10:44:40 bluhm Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
/* length to m_copy to copy all */
#define M_COPYALL 1000000000
-#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_COUNT (MBSTAT_TYPES + 3)
+#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)
/*
* Mbuf statistics.
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_COUNT];
+ u_long m_mtypes[MBSTAT_TYPES];
/* type specific mbuf allocations */
+ u_long m_defrag_alloc;
+ u_long m_prepend_alloc;
+ u_long m_pullup_alloc;
+ u_long m_pullup_copy;
+ u_long m_pulldown_alloc;
+ u_long m_pulldown_copy;
};
#include <sys/mutex.h>
extern int max_linkhdr; /* largest link-level header */
extern int max_protohdr; /* largest protocol header */
extern int max_hdr; /* largest link+protocol header */
+extern struct cpumem *mbstat; /* mbuf statistics counter */
void mbinit(void);
void mbcpuinit(void);
-/* $OpenBSD: mbuf.c,v 1.45 2023/07/16 03:01:31 yasuoka Exp $ */
+/* $OpenBSD: mbuf.c,v 1.46 2024/08/29 10:44:40 bluhm Exp $ */
/* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */
/*
};
int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(u_long);
-bool seen[MBSTAT_COUNT]; /* "have we seen this type yet?" */
+bool seen[MBSTAT_TYPES]; /* "have we seen this type yet?" */
/*
* Print mbuf statistics.
struct mbtypes *mp;
size_t size;
- if (nmbtypes != MBSTAT_COUNT) {
+ if (nmbtypes != MBSTAT_TYPES) {
fprintf(stderr,
"%s: unexpected change to mbstat; check source\n",
__progname);
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);
+ printf("%lu pullup memory copy\n", mbstat.m_pullup_copy);
+ printf("%lu pulldown mbuf allocation\n", mbstat.m_pulldown_alloc);
+ printf("%lu pulldown memory copy\n", mbstat.m_pulldown_copy);
}