diff options
author | glebius <glebius@FreeBSD.org> | 2012-01-17 12:13:36 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2012-01-17 12:13:36 +0000 |
commit | 068b515b9c2bee0a6be1a03fa2b0b5f7724cf08f (patch) | |
tree | d921ccb92b85ca9d7c5414578adfa01dbb07836c | |
parent | 6a34de7c5a0e59d6349ce628792e19d793eeb2b4 (diff) | |
download | FreeBSD-src-068b515b9c2bee0a6be1a03fa2b0b5f7724cf08f.zip FreeBSD-src-068b515b9c2bee0a6be1a03fa2b0b5f7724cf08f.tar.gz |
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.
-rw-r--r-- | sys/sys/mbuf.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 936ceb4..2a6c8aa 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -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. * |