Too many mbufs

Ruslan Ermilov ru at FreeBSD.org
Sat Nov 20 11:02:52 PST 2004


On Sat, Nov 20, 2004 at 10:57:30PM +1100, Bruce Evans wrote:
> On Fri, 19 Nov 2004, Ruslan Ermilov wrote:
> 
> > On Fri, Nov 19, 2004 at 03:21:44PM -0500, Chris McDermott wrote:
> > ...
> > > If I try and get the value with sysctlbyname() [copied from
> > > netstat/mbuf.c], it returns negative values for mbstat->m_mbufs. This
> > > negative value does fluctuate with network usage though...
> > >
> > > Test code:
> > > ...
> > > 	if (sysctlbyname("kern.ipc.mbstat", mbstat, &mlen, NULL, 0) < 0)
> > > 		perror("sysctl: retrieving mbstat");
> > >
> > > 	printf("mbufs: %d \nclusters: %d\n", mbstat->m_mbufs, mbstat->m_mclusts);
> > >
> > > 	return 0;
> > > }
> > >
> > Your code is broken.  Both m_mbufs and m_mclusts are of the type
> > u_long, so they should be printed with "%lu" specifier.  Fix your
> > program and try again.  (And you should see the same big number.)
> >
> > > Output:
> > >
> > > mbufs: -2240
> > > clusters: -2686
> > > ..
> > > codefactory# netstat -m
> > > 18446744073709549940 mbufs in use
> > > 18446744073709549630/17152 mbuf clusters in use (current/max)
> 
> The value is obviously negative (since 1844mumble is nearly 2^64),
> so the buggy program accidentally displays the correct value.
> 
Yes, sure.  ;)

> I can't see why the count would be decremented below 0 more on 64-bit
> machines than on 32-bit ones.
> 
I glanced at the kern_mbuf.c code yesterday responsible for mbstat
maintenance, and if it's supposed to be re-entrant (e.g., by multiple
CPUs), then there's a problem as accesses to mbstat aren't arbitrated.
I may be equally wrong on this.  ;)


Cheers,
-- 
Ruslan Ermilov
ru at FreeBSD.org
FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-amd64/attachments/20041120/17dcb5a6/attachment.bin


More information about the freebsd-amd64 mailing list