small tun(4) improvement
Gleb Smirnoff
glebius at cell.sick.ru
Thu Oct 14 10:42:29 PDT 2004
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
-------------- next part --------------
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 = ⊤
@@ -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) {
More information about the freebsd-net
mailing list