Date: Wed, 6 Feb 2013 19:04:07 +0200 From: Jacques Fourie <jacques.fourie@gmail.com> To: John Baldwin <jhb@freebsd.org> Cc: Hackers freeBSD <freebsd-hackers@freebsd.org>, Axel Fischer <afischer@marvell.com>, Lino Sanfilippo <lsanfil@marvell.com>, Markus Althoff <malthoff@marvell.com> Subject: Re: Mbuf memory handling Message-ID: <CALX0vxCKqMm2PdK_5t1SdOO91LjpZ1bHz-oDskx6pEj5FPhvtg@mail.gmail.com> In-Reply-To: <201302061137.35651.jhb@freebsd.org> References: <175CCF5F49938B4D99B2E3EF7F558EBE1C73F401F3@SC-VEXCH4.marvell.com> <201302060836.55404.jhb@freebsd.org> <CALX0vxADMfWe1-_mOYnx0C-9cRxf-ETv6wOPn=%2B34NATNUbbKA@mail.gmail.com> <201302061137.35651.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 6, 2013 at 6:37 PM, John Baldwin <jhb@freebsd.org> wrote: > On Wednesday, February 06, 2013 10:20:50 am Jacques Fourie wrote: > > On Wed, Feb 6, 2013 at 3:36 PM, John Baldwin <jhb@freebsd.org> wrote: > > > > > 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. > > > > > > The resulting mbufs will not be writeable (M_WRITABLE() will evaluate > to > > 0), right? I don't know if this will be an issue in this particular > > application. > > No, they only propagate an existing M_RDONLY flag: > > n->m_flags |= m->m_flags & M_RDONLY; > > If the first mbuf is writable the splits remain writable from my reading > of the code. OTOH, I think in this case read-only buffers passed up to > the stack are probably fine since they are already contiguous so any > pullup should be a NOP, etc. > > I agree that read-only buffers may be ok in this case but would like to point out that the M_WRITABLE() macro will evaluate to 0 if the refcount on the cluster is >1, even if the M_RDONLY flag is not set. So the various parts of the networking code that uses M_WRITABLE() to decide if the mbuf is writeable will treat the mbuf as read-only. > -- > John Baldwin >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALX0vxCKqMm2PdK_5t1SdOO91LjpZ1bHz-oDskx6pEj5FPhvtg>