Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Oct 2004 21:42:25 +0400
From:      Gleb Smirnoff <glebius@cell.sick.ru>
To:        net@freebsd.org
Subject:   small tun(4) improvement
Message-ID:  <20041014174225.GB49508@cell.sick.ru>

next in thread | raw e-mail | index | archive | help

--Qxx1br4bt0+wmkIi
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline

  Collegues,

  any objections about commiting this improvement to tun(4)?
In my ng_device I have a similar function ngdwrite(), which was
cut-n-pasted from tunwrite(). And my tests with a patched ng_device have
shown 30% speedup on large writes. I don't think it will help tun(4)
to be a much faster, since tunwrite() isn't a bottleneck, but I think
it is worth considering. The patch was tested on a production PPPoE access
concentrator (RELENG_4 however).      

-- 
Totus tuus, Glebius.
GLEBIUS-RIPN GLEB-RIPE

--Qxx1br4bt0+wmkIi
Content-Type: text/plain; charset=koi8-r
Content-Disposition: attachment; filename="if_tun.mcl.diff"

Index: if_tun.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_tun.c,v
retrieving revision 1.145
diff -u -r1.145 if_tun.c
--- if_tun.c	11 Oct 2004 07:28:36 -0000	1.145
+++ if_tun.c	12 Oct 2004 19:28:02 -0000
@@ -760,10 +760,15 @@
 	tlen = uio->uio_resid;
 
 	/* get a header mbuf */
-	MGETHDR(m, M_DONTWAIT, MT_DATA);
+	if (uio->uio_resid > MINCLSIZE) { 
+		m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
+		mlen = MCLBYTES;
+	} else {
+		MGETHDR(m, M_DONTWAIT, MT_DATA);
+		mlen = MHLEN;
+	}
 	if (m == NULL)
 		return (ENOBUFS);
-	mlen = MHLEN;
 
 	top = NULL;
 	mp = &top;
@@ -773,12 +778,17 @@
 		*mp = m;
 		mp = &m->m_next;
 		if (uio->uio_resid > 0) {
-			MGET (m, M_DONTWAIT, MT_DATA);
+			if (uio->uio_resid > MINCLSIZE) {
+				m = m_getcl(M_DONTWAIT, MT_DATA, 0);
+				mlen = MCLBYTES;
+			} else {
+				MGET (m, M_DONTWAIT, MT_DATA);
+				mlen = MLEN;
+			}
 			if (m == 0) {
 				error = ENOBUFS;
 				break;
 			}
-			mlen = MLEN;
 		}
 	}
 	if (error) {

--Qxx1br4bt0+wmkIi--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041014174225.GB49508>