diff options
author | dg <dg@FreeBSD.org> | 1994-08-06 11:26:16 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1994-08-06 11:26:16 +0000 |
commit | 93fcce5ec97be58d5f738a585817848bf93afbcc (patch) | |
tree | b9cb82bf59a4aabdab29c92009f9affde6487dee | |
parent | 4c3dd171d4247fdb02d70d887556a5bc3f8c70c4 (diff) | |
download | FreeBSD-src-93fcce5ec97be58d5f738a585817848bf93afbcc.zip FreeBSD-src-93fcce5ec97be58d5f738a585817848bf93afbcc.tar.gz |
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
-rw-r--r-- | sys/sys/mbuf.h | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 681b289..47ab7f5 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 |