From cf1344f6fcb8403b92fae89fcc2a4474501b06ad Mon Sep 17 00:00:00 2001 From: David Greenman Date: Sat, 6 Aug 1994 11:26:16 +0000 Subject: [PATCH] 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 --- sys/sys/mbuf.h | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 681b289e2d0..47ab7f5009c 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -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