Date: Sun, 9 Jul 2000 21:31:26 +0100 (BST) From: iedowse@maths.tcd.ie To: FreeBSD-gnats-submit@freebsd.org Cc: iedowse@maths.tcd.ie, bmilekic@dsuper.net Subject: kern/19809: Make mbstat.m_mtypes[] u_long instead of u_short Message-ID: <200007092131.aa41223@walton.maths.tcd.ie>
next in thread | raw e-mail | index | archive | help
>Number: 19809
>Category: kern
>Synopsis: Make mbstat.m_mtypes[] u_long instead of u_short
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sun Jul 09 13:40:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Ian Dowse
>Release: FreeBSD 4.0-STABLE i386
>Organization:
School of Mathematics
Trinity College Dublin
>Environment:
All versions of FreeBSD
>Description:
The mbstat.m_mtypes[] array, which is used to store mbuf type
statistics, is declared with type u_short. For most people
this is large enough, but large systems with more than 64k
mbufs configured are becoming quite common now.
On these systems, overflows can occur, causing meaningless
values to appear int the output of "netstat -m".
A related problem, which looks like it has always existed in
FreeBSD, is that the m_mtypes[MT_FREE] counter is not incremented
when new mbufs are allocated, so it does not reflect the number
of free mbufs.
>How-To-Repeat:
Configure a system with more than 64k mbufs, and notice that
the 'XX mbufs allocated to data' output from netstat wraps
around at 64k.
The m_mtypes[MT_FREE] bug can be observed by typing
print mbstat.m_mtypes[0]
from a kgdb session; the number printed will generally be around
65500 on a quiet system with only a few mbufs allocated.
>Fix:
Apply the following patch. This fixes both of the above
issues, and removes some assumptions within netstat(1) about
the size of the m_mtypes[] array.
The patch also reduces the size of the m_mtypes[] array from
256 to 32. Currently there are only 16 mbuf types defined, and
the definitions of 9 of these are #if 0'd out, so we are unlikely
to reach 32 types anytime soon. This reduces the kernel bss size
by a few hundred bytes.
Index: sys/kern/uipc_mbuf.c
===================================================================
RCS file: /home/iedowse/CVS/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.52
diff -u -r1.52 uipc_mbuf.c
--- sys/kern/uipc_mbuf.c 2000/07/04 16:35:03 1.52
+++ sys/kern/uipc_mbuf.c 2000/07/09 17:54:30
@@ -184,6 +184,7 @@
p += MSIZE;
}
mbstat.m_mbufs += nmb;
+ mbstat.m_mtypes[MT_FREE] += nmb;
return (1);
}
Index: sys/sys/mbuf.h
===================================================================
RCS file: /home/iedowse/CVS/src/sys/sys/mbuf.h,v
retrieving revision 1.51
diff -u -r1.51 mbuf.h
--- sys/sys/mbuf.h 2000/07/04 16:35:15 1.51
+++ sys/sys/mbuf.h 2000/07/09 17:55:26
@@ -191,7 +191,7 @@
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_short m_mtypes[256]; /* type specific mbuf allocations */
+ u_long m_mtypes[32]; /* type specific mbuf allocations */
u_long m_mcfail; /* times m_copym failed */
u_long m_mpfail; /* times m_pullup failed */
u_long m_msize; /* length of an mbuf */
Index: usr.bin/netstat/mbuf.c
===================================================================
RCS file: /home/iedowse/CVS/src/usr.bin/netstat/mbuf.c,v
retrieving revision 1.17
diff -u -r1.17 mbuf.c
--- usr.bin/netstat/mbuf.c 1999/12/28 06:38:37 1.17
+++ usr.bin/netstat/mbuf.c 2000/07/09 20:26:37
@@ -91,8 +91,8 @@
{ 0, 0 }
};
-int nmbtypes = sizeof(mbstat.m_mtypes) / sizeof(short);
-bool seen[256]; /* "have we seen this type yet?" */
+#define NMBTYPES (sizeof(mbstat.m_mtypes) / sizeof(mbstat.m_mtypes[0]))
+bool seen[NMBTYPES]; /* "have we seen this type yet?" */
/*
* Print mbuf statistics.
@@ -133,11 +133,6 @@
#undef MCLBYTES
#define MCLBYTES (mbstat.m_mclbytes)
- if (nmbtypes != 256) {
- warnx("unexpected change to mbstat; check source");
- return;
- }
-
totmbufs = 0;
for (mp = mbtypes; mp->mt_name; mp++)
totmbufs += mbstat.m_mtypes[mp->mt_type];
@@ -146,13 +141,13 @@
for (mp = mbtypes; mp->mt_name; mp++)
if (mbstat.m_mtypes[mp->mt_type]) {
seen[mp->mt_type] = YES;
- printf("\t%u mbufs allocated to %s\n",
+ printf("\t%lu mbufs allocated to %s\n",
mbstat.m_mtypes[mp->mt_type], mp->mt_name);
}
seen[MT_FREE] = YES;
- for (i = 0; i < nmbtypes; i++)
+ for (i = 0; i < NMBTYPES; i++)
if (!seen[i] && mbstat.m_mtypes[i]) {
- printf("\t%u mbufs allocated to <mbuf type %d>\n",
+ printf("\t%lu mbufs allocated to <mbuf type %d>\n",
mbstat.m_mtypes[i], i);
}
printf("%lu/%lu/%u mbuf clusters in use (current/peak/max)\n",
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007092131.aa41223>
