From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 6 14:41:54 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E7B33A88 for ; Wed, 6 Feb 2013 14:41:54 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id C1881F25 for ; Wed, 6 Feb 2013 14:41:54 +0000 (UTC) Received: from pakbsde14.localnet (unknown [38.105.238.108]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 06299B911; Wed, 6 Feb 2013 09:41:54 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org Subject: Re: Mbuf memory handling Date: Wed, 6 Feb 2013 08:36:55 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p22; KDE/4.5.5; amd64; ; ) References: <175CCF5F49938B4D99B2E3EF7F558EBE1C73F401F3@SC-VEXCH4.marvell.com> In-Reply-To: <175CCF5F49938B4D99B2E3EF7F558EBE1C73F401F3@SC-VEXCH4.marvell.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201302060836.55404.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 06 Feb 2013 09:41:54 -0500 (EST) Cc: Axel Fischer , Lino Sanfilippo , Markus Althoff X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Feb 2013 14:41:55 -0000 On Wednesday, February 06, 2013 4:50:39 am Lino Sanfilippo wrote: > > Hi all, > > I want to implement a device driver for a NIC which stores received data into chunks within > a page (>=4k) in host memory. One page shall be used for multiple packets and freed > after all mbufs linked to that page have been processed. So I would like to know what is the recommended way > to handle this in FreeBSD? Any hints are very appreciated. I think you can get what you want by allocating M_JUMBOP mbuf clusters for your receive buffers. When you want to split out a packet, allocate a new packet header mbuf and use m_split() to let it take over the rest of the 4k buffer and pass the original mbuf up to if_input() as the new packet. The new mbufs you attach to the cluster via m_split() will all hold a reference on the backing cluster and it won't be freed until all the mbufs are freed. -- John Baldwin