git: a051ca72e281 - main - Introduce m_get3()
Kristof Provost
kp at FreeBSD.org
Wed Aug 18 08:52:03 UTC 2021
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=a051ca72e2815b9bbba1e422f5abf22bc2a01551
commit a051ca72e2815b9bbba1e422f5abf22bc2a01551
Author: Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-08-07 18:02:21 +0000
Commit: Kristof Provost <kp at FreeBSD.org>
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 *);
More information about the dev-commits-src-main
mailing list