o Introduce a new external mbuf type, EXT_EXTREF.

o Allow callers of m_extadd() to allocate their own reference
m_ext.ref_cnt pointer, rather than having the mbuf system allocate it
with a malloc() in the critical path.  This speeds m_extadd() up, and
also simplifies locking (malloc() may need Giant).

A driver or subsystem wishing to take use its own ref counter must
initialize m_ext.ref_cnt to point to its ref counter prior to
calling m_extadd(), and it must use EXT_EXTREF as its external type.

Eg:
	 m->m_ext.ref_cnt =  my_ref_cnt_ptr;
	 m_extadd(.....,EXT_EXTREF);

Reviewed by: bosko
This commit is contained in:
Andrew Gallatin 2003-01-02 21:16:50 +00:00
parent d3951ad162
commit 1f88bad30a
2 changed files with 9 additions and 3 deletions

View File

@ -1062,7 +1062,8 @@ mb_reclaim(void)
(((uintptr_t)(cl) - (uintptr_t)cl_refcntmap) >> MCLSHIFT)
#define _mext_dealloc_ref(m) \
free((m)->m_ext.ref_cnt, M_MBUF)
if ((m)->m_ext.ext_type != EXT_EXTREF) \
free((m)->m_ext.ref_cnt, M_MBUF)
/******************************************************************************
* Internal routines.
@ -1508,9 +1509,13 @@ void
m_extadd(struct mbuf *mb, caddr_t buf, u_int size,
void (*freef)(void *, void *), void *args, int flags, int type)
{
u_int *ref_cnt = NULL;
_mext_init_ref(mb, ((type != EXT_CLUSTER) ?
NULL : &cl_refcntmap[cl2ref(mb->m_ext.ext_buf)]));
if (type == EXT_CLUSTER)
ref_cnt = &cl_refcntmap[cl2ref(mb->m_ext.ext_buf)];
else if (type == EXT_EXTREF)
ref_cnt = mb->m_ext.ref_cnt;
_mext_init_ref(mb, ref_cnt);
if (mb->m_ext.ref_cnt != NULL) {
mb->m_flags |= (M_EXT | flags);
mb->m_ext.ext_buf = buf;

View File

@ -173,6 +173,7 @@ struct mbuf {
#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */
#define EXT_MOD_TYPE 200 /* custom module's ext_buf type */
#define EXT_DISPOSABLE 300 /* can throw this buffer away w/page flipping */
#define EXT_EXTREF 400 /* has externally maintained ref_cnt ptr*/
/*
* Flags copied when copying m_pkthdr.