Skip to contentSkip to conversation

mbuf init questions

DISCUSSION Morten Brørup 2 participants 3 messages Dec 5, 2023

lore
Share & tools
lore
#0 lore raw

Why is m->nb_segs initialized in rte_pktmbuf_prefree_seg()?

It's part of the m->rearm_data, and will be initialized on RX descriptor rearm anyway.

Slightly related:

When built without RTE_IOVA_IN_MBUF, m->next lives in the first cache line.

Theoretically, it would improve performance to initialize m->next together with the RX descriptor rearm, when writing to the first cache line anyway, instead of in rte_pktmbuf_prefree_seg(), which requires another write to the first cache line. (In the case where m->next is non-NULL and m->refcnt is 1.)

Med venlig hilsen / Kind regards,
-Morten Brørup

#1 lore raw
Quoted 4 lines · Morten Brørup

Why is m->nb_segs initialized in rte_pktmbuf_prefree_seg()?

It's part of the m->rearm_data, and will be initialized on RX descriptor rearm anyway.

Presumably this is to have a sane default for apps that allocate buffers directly using mempool_get functions.

Overall, we probably need to document clearly for mbufs allocated using mempool apis rather than mbuf_alloc what fields are valid and what need to be initialized.

/Bruce

#2 lore raw
Quoted 4 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Tuesday, 5 December 2023 10.56

On Tue, Dec 05, 2023 at 10:07:56AM +0100, Morten Brørup wrote:

Quoted 8 lines
Quoted 3 lines

Why is m->nb_segs initialized in rte_pktmbuf_prefree_seg()?

It's part of the m->rearm_data, and will be initialized on RX

descriptor rearm anyway.

Quoted 1 line

Presumably this is to have a sane default for apps that allocate buffers
directly using mempool_get functions.

Ahh, yes... the great bypassing of the mbuf APIs!

Quoted 5 lines

Overall, we probably need to document clearly for mbufs allocated using mempool apis rather than mbuf_alloc what fields are valid and what need to
be initialized.

Good point. Since it has become customary - and generally accepted practice - to bypass the mbuf APIs and use the mempool APIs directly, we should document how to use the mempool APIs in an mbuf API context.

Spaghetti code, but everyone loves the performance benefits by doing it. Including myself. ;-)