From owner-svn-src-all@FreeBSD.ORG  Tue Jan 17 12:13:37 2012
Return-Path: <owner-svn-src-all@FreeBSD.ORG>
Delivered-To: svn-src-all@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 8A8D3106564A;
	Tue, 17 Jan 2012 12:13:37 +0000 (UTC)
	(envelope-from glebius@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 5EE5C8FC15;
	Tue, 17 Jan 2012 12:13:37 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0HCDbor089894;
	Tue, 17 Jan 2012 12:13:37 GMT (envelope-from glebius@svn.freebsd.org)
Received: (from glebius@localhost)
	by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0HCDbfj089892;
	Tue, 17 Jan 2012 12:13:37 GMT (envelope-from glebius@svn.freebsd.org)
Message-Id: <201201171213.q0HCDbfj089892@svn.freebsd.org>
From: Gleb Smirnoff <glebius@FreeBSD.org>
Date: Tue, 17 Jan 2012 12:13:37 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-head@freebsd.org
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r230264 - head/sys/sys
X-BeenThere: svn-src-all@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: "SVN commit messages for the entire src tree \(except for &quot;
	user&quot; and &quot; projects&quot; \)" <svn-src-all.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-all>,
	<mailto:svn-src-all-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-all>
List-Post: <mailto:svn-src-all@freebsd.org>
List-Help: <mailto:svn-src-all-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-all>,
	<mailto:svn-src-all-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 17 Jan 2012 12:13:37 -0000

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.
  *