mbuf headroom question
Olivier Matz
olivier.matz at 6wind.com
Thu Jan 6 10:48:41 CET 2022
Hi Morten,
On Thu, Jan 06, 2022 at 10:29:11AM +0100, Morten Brørup wrote:
> Hi Olivier,
>
> The data_room_size parameter description for the mbuf pool creation functions says:
> "Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM."
>
> Furthermore, both rte_mbuf_data_iova_default() and rte_mbuf_data_addr_default() simply add RTE_PKTMBUF_HEADROOM to the return value.
>
> Based on the above, I would think that it is impossible for m->buf_len to be smaller than RTE_PKTMBUF_HEADROOM.
>
> So why does rte_pktmbuf_reset_headroom() use RTE_MIN(m->buf_len, RTE_PKTMBUF_HEADROOM), instead of just RTE_PKTMBUF_HEADROOM? What am I missing here?
It is legal to create a packet pool that has no data buffer: this pool
can be used to allocate packets clones that will be attached to mbufs
containing data. There is an example in test_mbuf.c.
It is also technically possible to create a packet pool with small
mbufs (whose buffer length is less than RTE_PKTMBUF_HEADROOM). These
mbufs cannot be used by drivers which use rte_mbuf_data_iova_default(),
but they could be used internally.
To create valid mbufs in these 2 cases, this is why RTE_MIN(m->buf_len,
RTE_PKTMBUF_HEADROOM) is used ; "valid" means that headroom is not larger
than buffer length.
Olivier
More information about the dev
mailing list