Implemented "fast" mbuf macros. a small number of mbufs are cached in

a linked list for fast allocation/free. Improves TCP performance by
about 20%.

Submitted by:	John Dyson
This commit is contained in:
David Greenman 1994-08-06 11:26:16 +00:00
parent 539d9ba017
commit cf1344f6fc

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)mbuf.h 8.3 (Berkeley) 1/21/94
* $Id$
* $Id: mbuf.h,v 1.2 1994/08/02 07:53:12 davidg Exp $
*/
#ifndef M_WAITOK
@ -168,8 +168,19 @@ struct mbuf {
* allocates an mbuf and initializes it to contain a packet header
* and internal data.
*/
struct mbuf *mbuffree;
int mbuffreecnt;
#define MGET(m, how, type) { \
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
int s = splimp(); \
if (mbuffree == 0) { \
splx(s); \
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
} else { \
--mbuffreecnt; \
(m) = mbuffree; \
mbuffree = (m)->m_next; \
splx(s); \
} \
if (m) { \
(m)->m_type = (type); \
MBUFLOCK(mbstat.m_mtypes[type]++;) \
@ -182,7 +193,16 @@ struct mbuf {
}
#define MGETHDR(m, how, type) { \
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
int s = splimp(); \
if (mbuffree == 0) { \
splx(s); \
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
} else { \
--mbuffreecnt; \
(m) = mbuffree; \
mbuffree = (m)->m_next; \
splx(s); \
} \
if (m) { \
(m)->m_type = (type); \
MBUFLOCK(mbstat.m_mtypes[type]++;) \
@ -265,7 +285,15 @@ union mcluster {
MCLFREE((m)->m_ext.ext_buf); \
} \
(nn) = (m)->m_next; \
FREE((m), mbtypes[(m)->m_type]); \
if (mbuffreecnt < 256) { \
int s = splimp(); \
++mbuffreecnt; \
(m)->m_next = mbuffree; \
mbuffree = (m); \
splx(s); \
} else { \
FREE((m), mbtypes[(m)->m_type]); \
} \
}
#endif