Subject: Nuking mbuf macros
To: None <tech-kern@NetBSD.org>
From: Bang Jun-Young <junyoung@NetBSD.org>
List: tech-kern
Date: 03/23/2004 15:07:41
--Boundary-00=_tQ9XAYaUPux7YKN
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

The attached patch turns mbuf macros into wrappers to real functions. With=
=20
the patch applied GENERIC/i386 kernel is 37KB smaller.

=46rom commit log of the same change made in DragonFly BSD:

=A0=A0Nuke=A0huge=A0mbuf=A0macros=A0stage=A01/2:=A0Remove=A0massive=A0inlin=
e=A0mbuf=A0macros=A0to=A0reduce
=A0=A0L1/L2=A0cache=A0pollution.=A0=A0Est.=A0performance=A0improvement=A0of=
=A04-6%=A0and=A0the=A0kernel
=A0=A0is=A042KB=A0smaller.

Is it okay?

Jun-Young

--Boundary-00=_tQ9XAYaUPux7YKN
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="mbuf-noinline.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="mbuf-noinline.diff"

Index: sys/mbuf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mbuf.h,v
retrieving revision 1.89
diff -u -r1.89 mbuf.h
--- sys/mbuf.h	10 Feb 2004 01:33:26 -0000	1.89
+++ sys/mbuf.h	23 Mar 2004 04:38:58 -0000
@@ -441,35 +441,12 @@
  */
 #define	MGET(m, how, type)						\
 do {									\
-	MBUFLOCK((m) = pool_cache_get(&mbpool_cache,			\
-	    (how) == M_WAIT ? PR_WAITOK|PR_LIMITFAIL : 0););		\
-	if (m) {							\
-		MBUFLOCK(mbstat.m_mtypes[type]++;			\
-		    _MOWNERINIT((m), (type)); );			\
-		(m)->m_type = (type);					\
-		(m)->m_next = (struct mbuf *)NULL;			\
-		(m)->m_nextpkt = (struct mbuf *)NULL;			\
-		(m)->m_data = (m)->m_dat;				\
-		(m)->m_flags = 0;					\
-	}								\
+	(m) = m_get((how), (type));					\
 } while (/* CONSTCOND */ 0)
 
 #define	MGETHDR(m, how, type)						\
 do {									\
-	MBUFLOCK((m) = pool_cache_get(&mbpool_cache,			\
-	    (how) == M_WAIT ? PR_WAITOK|PR_LIMITFAIL : 0););		\
-	if (m) {							\
-		MBUFLOCK(mbstat.m_mtypes[type]++;			\
-		    _MOWNERINIT((m), (type)); );			\
-		(m)->m_type = (type);					\
-		(m)->m_next = (struct mbuf *)NULL;			\
-		(m)->m_nextpkt = (struct mbuf *)NULL;			\
-		(m)->m_data = (m)->m_pktdat;				\
-		(m)->m_flags = M_PKTHDR;				\
-		(m)->m_pkthdr.csum_flags = 0;				\
-		(m)->m_pkthdr.csum_data = 0;				\
-		SLIST_INIT(&(m)->m_pkthdr.tags);			\
-	}								\
+	(m) = m_gethdr((how), (type));					\
 } while (/* CONSTCOND */ 0)
 
 #define	_M_
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.78
diff -u -r1.78 uipc_mbuf.c
--- kern/uipc_mbuf.c	9 Mar 2004 06:37:59 -0000	1.78
+++ kern/uipc_mbuf.c	23 Mar 2004 04:39:44 -0000
@@ -371,20 +371,45 @@
  * for critical paths.
  */
 struct mbuf *
-m_get(int nowait, int type)
+m_get(int how, int type)
 {
 	struct mbuf *m;
 
-	MGET(m, nowait, type);
+	MBUFLOCK(m = pool_cache_get(&mbpool_cache,
+	    how == M_WAIT ? PR_WAITOK|PR_LIMITFAIL : 0););
+	if (m) {
+		MBUFLOCK(mbstat.m_mtypes[type]++;
+		    _MOWNERINIT(m, type); );
+		m->m_type = type;
+		m->m_next = (struct mbuf *)NULL;
+		m->m_nextpkt = (struct mbuf *)NULL;
+		m->m_data = m->m_dat;
+		m->m_flags = 0;
+	}
+
 	return (m);
 }
 
 struct mbuf *
-m_gethdr(int nowait, int type)
+m_gethdr(int how, int type)
 {
 	struct mbuf *m;
 
-	MGETHDR(m, nowait, type);
+	MBUFLOCK(m = pool_cache_get(&mbpool_cache,
+	    how == M_WAIT ? PR_WAITOK|PR_LIMITFAIL : 0););
+	if (m) {
+		MBUFLOCK(mbstat.m_mtypes[type]++;
+		    _MOWNERINIT(m, type); );
+		m->m_type = type;
+		m->m_next = (struct mbuf *)NULL;
+		m->m_nextpkt = (struct mbuf *)NULL;
+		m->m_data = m->m_pktdat;
+		m->m_flags = M_PKTHDR;
+		m->m_pkthdr.csum_flags = 0;
+		m->m_pkthdr.csum_data = 0;
+		SLIST_INIT(&m->m_pkthdr.tags);
+	}
+
 	return (m);
 }
 

--Boundary-00=_tQ9XAYaUPux7YKN--