Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern change m_defrag() to coalesce the chain to single m...



details:   https://anonhg.NetBSD.org/src/rev/fa36daec2541
branches:  trunk
changeset: 971462:fa36daec2541
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Fri Apr 24 22:07:12 2020 +0000

description:
change m_defrag() to coalesce the chain to single mbuf if it's short enough
and first mbuf doesn't use external storage

most fragmented packets end up with first short mbuf containing
frame + protocol header only, and second mbuf containing the data;
m_defrag() previously always returned chain of at least two mbufs,
now it should actually return all data in single mbuf for typical
mbuf chain with length < MCLBYTES

diffstat:

 sys/kern/uipc_mbuf.c |  38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diffs (59 lines):

diff -r 5302b424ab9b -r fa36daec2541 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c      Fri Apr 24 19:47:03 2020 +0000
+++ b/sys/kern/uipc_mbuf.c      Fri Apr 24 22:07:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_mbuf.c,v 1.237 2020/03/15 23:14:41 thorpej Exp $  */
+/*     $NetBSD: uipc_mbuf.c,v 1.238 2020/04/24 22:07:12 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1999, 2001, 2018 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.237 2020/03/15 23:14:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.238 2020/04/24 22:07:12 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
@@ -1672,6 +1672,40 @@
        if (m->m_next == NULL)
                return m;
 
+       /* Defrag to single mbuf if at all possible */
+       if ((m->m_flags & M_EXT) == 0) {
+               if (m->m_pkthdr.len <= MHLEN) {
+                       if (M_TRAILINGSPACE(m) < (m->m_pkthdr.len - m->m_len)) {
+                               KASSERT(M_LEADINGSPACE(m) >=
+                                   (m->m_pkthdr.len - m->m_len));
+                               memmove(m->m_pktdat, m->m_data, m->m_len);
+                               m->m_data = m->m_pktdat;
+                       }
+
+                       KASSERT(M_TRAILINGSPACE(m) >=
+                           (m->m_pkthdr.len - m->m_len));
+                       if (__predict_false(!m_ensure_contig(&m,
+                           m->m_pkthdr.len))) {
+                               panic("m_ensure_contig(%d) failed\n",
+                                   m->m_pkthdr.len);
+                       }
+                       return m;
+               } else if (m->m_pkthdr.len <= MCLBYTES) {
+                       void *odata = m->m_data;
+
+                       MCLGET(m, how);
+                       if ((m->m_flags & M_EXT) == 0)
+                               return NULL;
+                       memcpy(m->m_data, odata, m->m_len);
+                       if (m_pulldown(m, m->m_len, m->m_pkthdr.len - m->m_len,
+                           NULL) == NULL) {
+                               panic("m_pulldown(%d, %d) failed\n",
+                                   m->m_len, m->m_pkthdr.len - m->m_len);
+                       }
+                       return m;
+               }
+       }
+
        m0 = m_get(how, MT_DATA);
        if (m0 == NULL)
                return NULL;



Home | Main Index | Thread Index | Old Index