Mbuf memory handling

Jacques Fourie jacques.fourie at gmail.com
Wed Feb 6 15:20:52 UTC 2013


On Wed, Feb 6, 2013 at 3:36 PM, John Baldwin <jhb at 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.

> --
> John Baldwin
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>


More information about the freebsd-hackers mailing list