svn commit: r230264 - head/sys/sys
Gleb Smirnoff
glebius at FreeBSD.org
Tue Jan 17 12:13:37 UTC 2012
Author: glebius
Date: Tue Jan 17 12:13:36 2012
New Revision: 230264
URL: http://svn.freebsd.org/changeset/base/230264
Log:
Provide a function m_get2() that allocates a minimal mbuf that
would fit specified size. Returned mbuf may be a single mbuf,
an mbuf with a cluster from packet zone, or an mbuf with jumbo
cluster of sufficient size.
Modified:
head/sys/sys/mbuf.h
Modified: head/sys/sys/mbuf.h
==============================================================================
--- head/sys/sys/mbuf.h Tue Jan 17 11:04:58 2012 (r230263)
+++ head/sys/sys/mbuf.h Tue Jan 17 12:13:36 2012 (r230264)
@@ -398,6 +398,8 @@ extern uma_zone_t zone_ext_refcnt;
static __inline struct mbuf *m_getcl(int how, short type, int flags);
static __inline struct mbuf *m_get(int how, short type);
+static __inline struct mbuf *m_get2(int how, short type, int flags,
+ int size);
static __inline struct mbuf *m_gethdr(int how, short type);
static __inline struct mbuf *m_getjcl(int how, short type, int flags,
int size);
@@ -544,6 +546,52 @@ m_getcl(int how, short type, int flags)
}
/*
+ * m_get2() allocates minimum mbuf that would fit "size" argument.
+ *
+ * XXX: This is rather large, should be real function maybe.
+ */
+static __inline struct mbuf *
+m_get2(int how, short type, int flags, int size)
+{
+ struct mb_args args;
+ struct mbuf *m, *n;
+ uma_zone_t zone;
+
+ args.flags = flags;
+ args.type = type;
+
+ if (size <= MHLEN || (size <= MLEN && (flags & M_PKTHDR) == 0))
+ return ((struct mbuf *)(uma_zalloc_arg(zone_mbuf, &args, how)));
+ if (size <= MCLBYTES)
+ return ((struct mbuf *)(uma_zalloc_arg(zone_pack, &args, how)));
+
+ if (size > MJUM16BYTES)
+ return (NULL);
+
+ m = uma_zalloc_arg(zone_mbuf, &args, how);
+ if (m == NULL)
+ return (NULL);
+
+#if MJUMPAGESIZE != MCLBYTES
+ if (size <= MJUMPAGESIZE)
+ zone = zone_jumbop;
+ else
+#endif
+ if (size <= MJUM9BYTES)
+ zone = zone_jumbo9;
+ else
+ zone = zone_jumbo16;
+
+ n = uma_zalloc_arg(zone, m, how);
+ if (n == NULL) {
+ uma_zfree(zone_mbuf, 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.
*
More information about the svn-src-head
mailing list