From owner-dev-commits-src-main@freebsd.org Wed Aug 18 08:52:02 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E27676740B5; Wed, 18 Aug 2021 08:52:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GqM8f5vMcz3R4V; Wed, 18 Aug 2021 08:52:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B2CF35BFD; Wed, 18 Aug 2021 08:52:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17I8q2C8009886; Wed, 18 Aug 2021 08:52:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17I8q2Wl009885; Wed, 18 Aug 2021 08:52:02 GMT (envelope-from git) Date: Wed, 18 Aug 2021 08:52:02 GMT Message-Id: <202108180852.17I8q2Wl009885@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: a051ca72e281 - main - Introduce m_get3() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a051ca72e2815b9bbba1e422f5abf22bc2a01551 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Aug 2021 08:52:03 -0000 The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a051ca72e2815b9bbba1e422f5abf22bc2a01551 commit a051ca72e2815b9bbba1e422f5abf22bc2a01551 Author: Kristof Provost AuthorDate: 2021-08-07 18:02:21 +0000 Commit: Kristof Provost CommitDate: 2021-08-18 06:48:27 +0000 Introduce m_get3() Introduce m_get3() which is similar to m_get2(), but can allocate up to MJUM16BYTES bytes (m_get2() can only allocate up to MJUMPAGESIZE). This simplifies the bpf improvement in f13da24715. Suggested by: glebius Differential Revision: https://reviews.freebsd.org/D31455 --- share/man/man9/mbuf.9 | 11 ++++++++++- sys/kern/kern_mbuf.c | 38 ++++++++++++++++++++++++++++++++++++++ sys/net/bpf.c | 9 +-------- sys/sys/mbuf.h | 1 + 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/share/man/man9/mbuf.9 b/share/man/man9/mbuf.9 index f6361cdc7c06..ea3f66e3e218 100644 --- a/share/man/man9/mbuf.9 +++ b/share/man/man9/mbuf.9 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 8, 2021 +.Dd August 8, 2021 .Dt MBUF 9 .Os .\" @@ -73,6 +73,8 @@ .Ft struct mbuf * .Fn m_get2 "int size" "int how" "short type" "int flags" .Ft struct mbuf * +.Fn m_get3 "int size" "int how" "short type" "int flags" +.Ft struct mbuf * .Fn m_getm "struct mbuf *orig" "int len" "int how" "short type" .Ft struct mbuf * .Fn m_getjcl "int how" "short type" "int flags" "int size" @@ -577,6 +579,13 @@ with enough space to hold specified amount of data. If the size is is larger than .Dv MJUMPAGESIZE , NULL will be returned. +.It Fn m_get3 size how type flags +Allocate an +.Vt mbuf +with enough space to hold specified amount of data. +If the size is is larger than +.Dv MJUM16BYTES, NULL +will be returned. .It Fn m_getm orig len how type Allocate .Fa len diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index ae4aa7d7e96a..123985a7dec2 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -1371,6 +1371,44 @@ m_get2(int size, int how, short type, int flags) return (m); } +/* + * m_get3() allocates minimum mbuf that would fit "size" argument. + * Unlike m_get2() it can allocate clusters up to MJUM16BYTES. + */ +struct mbuf * +m_get3(int size, int how, short type, int flags) +{ + struct mb_args args; + struct mbuf *m, *n; + uma_zone_t zone; + + if (size <= MJUMPAGESIZE) + return (m_get2(size, how, type, flags)); + + if (size > MJUM16BYTES) + return (NULL); + + args.flags = flags; + args.type = type; + + m = uma_zalloc_arg(zone_mbuf, &args, how); + if (m == NULL) + return (NULL); + + if (size <= MJUM9BYTES) + zone = zone_jumbo9; + else + zone = zone_jumbo16; + + n = uma_zalloc_arg(zone_jumbop, m, how); + if (n == NULL) { + m_free_raw(m); + return (NULL); + } + + return (m); +} + /* * m_getjcl() returns an mbuf with a cluster of the specified size attached. * For size it takes MCLBYTES, MJUMPAGESIZE, MJUM9BYTES, MJUM16BYTES. diff --git a/sys/net/bpf.c b/sys/net/bpf.c index ff14152c086c..77c85cc91aae 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -644,14 +644,7 @@ bpf_movein(struct uio *uio, int linktype, struct ifnet *ifp, struct mbuf **mp, return (EMSGSIZE); /* Allocate a mbuf for our write, since m_get2 fails if len >= to MJUMPAGESIZE, use m_getjcl for bigger buffers */ - if (len < MJUMPAGESIZE) - m = m_get2(len, M_WAITOK, MT_DATA, M_PKTHDR); - else if (len <= MJUM9BYTES) - m = m_getjcl(M_WAITOK, MT_DATA, M_PKTHDR, MJUM9BYTES); - else if (len <= MJUM16BYTES) - m = m_getjcl(M_WAITOK, MT_DATA, M_PKTHDR, MJUM16BYTES); - else - m = NULL; + m = m_get3(len, M_WAITOK, MT_DATA, M_PKTHDR); if (m == NULL) return (EIO); m->m_pkthdr.len = m->m_len = len; diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 2936966f6acc..58ada4d0b7b2 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -829,6 +829,7 @@ struct mbuf *m_fragment(struct mbuf *, int, int); void m_freem(struct mbuf *); void m_free_raw(struct mbuf *); struct mbuf *m_get2(int, int, short, int); +struct mbuf *m_get3(int, int, short, int); struct mbuf *m_getjcl(int, short, int, int); struct mbuf *m_getm2(struct mbuf *, int, int, short, int); struct mbuf *m_getptr(struct mbuf *, int, int *);