Memory reserves or lack thereof

Andre Oppermann andre at freebsd.org
Mon Nov 12 15:23:47 UTC 2012


On 12.11.2012 15:47, Ian Lepore wrote:
> On Mon, 2012-11-12 at 13:18 +0100, Andre Oppermann wrote:
>>> Well, what's the current set of best practices for allocating mbufs?
>>
>> If an allocation is driven by user space then you can use M_WAITOK.
>>
>> If an allocation is driven by the driver or kernel (callout and so on)
>> you do M_NOWAIT and handle a failure by trying again later either
>> directly by rescheduling the callout or by the upper layer retransmit
>> logic.
>>
>> On top of that individual mbuf allocation or stitching mbufs and
>> clusters together manually is deprecated.  If every possible you
>> should use m_getm2().
>
> root at pico:/root # man m_getm2
> No manual entry for m_getm2

Oops... Have to fix that.

> So when you say manually stitching mbufs together is deprecated, I take
> you mean in the case where you're letting the mbuf routines allocate the
> actual buffer space for you?

I mean allocating an mbuf, a cluster and then stitching them together.
You can it in one with m_getcl().

> I've got an ethernet driver on an ARM SoC in which the hardware receives
> into a series of buffers fixed at 128 bytes.  Right now the code is
> allocating a cluster and then looping using m_append() to reassemble
> these buffers back into a full contiguous frame in a cluster.  I was
> going to have a shot at using MEXTADD() to manually string the series of
> hardware/dma buffers together without copying the data.  Is that sort of
> usage still a good idea?  (And would it actually be a performance win?

That really depends on the particular usage.  Attaching the 128 byte
buffers to mbufs probably isn't much of a win considering an mbuf is
256 bytes in size.  You could just as well copy each 128 buf into the
data section.  Allocating a 2K cluster and copying into it is more
efficient on the overall system.

> If I hand it off to the net stack and an m_pullup() or similar is going
> to happen along the way anyway, I might as well do it at driver level.)

If you properly m_align() the mbuf cluster before you copy into it
there shouldn't be any m_pullup's happening.

-- 
Andre



More information about the freebsd-hackers mailing list