Date: Tue, 17 Jan 2012 12:13:37 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r230264 - head/sys/sys Message-ID: <201201171213.q0HCDbfj089892@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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. *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201171213.q0HCDbfj089892>