mbufs & EXT_EXTREF

Benjamin Close Benjamin.Close at clearchain.com
Fri May 4 14:56:05 UTC 2007


Hi All,
    I'm working on a driver and am trying to use external storage 
previously allocated attached to mbufs.
However, I'm finding the extracted example below seems to decrement the 
system mbuf usage count below zero, causing thing like vmstat -z to wrap 
negatively.

void myfreefunc( void *, void * )
{}
...

struct mbuf *m;
m = m_getcl(M_DONTWAIT, MT_HEADER, M_EXT);
                if (m == NULL) {
                        device_printf(sc->sc_dev,
                            "could not allocate rx mbuf\n");
                        error = ENOBUFS;
                        goto fail;
                }


  /* attach mybuffer to mbuf */
MEXTADD(m, mybuffer, MYBUFFERSIZE,myfreefunc, NULL,0,EXT_EXTREF);
if ((m->m_flags & M_EXT) == 0) {
                    m_freem(m);
                    m=NULL;
                    error = ENOBUFS;
                    goto fail;
                }

/* Free the cluster */
m_freem(m);

Output from vmstat -z after running a equivilant example (this is after 
a number of runs, but even one run decrements from 1 alarge number)


mbuf_packet:              256,        0,      321,      319,    
22923,        0
mbuf:                     256,        0, 18446744073709551553,      
323,    95191,        0
mbuf_cluster:            2048,    25600,      640,       12,      
640,        0
mbuf_jumbo_pagesize:     4096,        0,        1,       43,    
26396,        0
mbuf_jumbo_9k:           9216,        0,        0,        0,        
0,        0
mbuf_jumbo_16k:         16384,        0,        0,        0,        
0,        0
mbuf_ext_refcnt:            4,        0,        0,        0,        
0,        0

Originally I tried m_get as apposed to m_getcl but that panics the 
kernel in m_extadd+0x15
Can anyone shed some light on what I'm missing?

I did notice whilst trying to trace this down, that m_getcl adds to 
zone_pack whilst mb_free_ext (called from m_free) frees from zone_mbuf 
for type EXT_EXTREF and thought that was odd.

Cheers,
    Benjamin


More information about the freebsd-current mailing list