Search code examples
networkinginteldpdkprefetch

How does DPDK prefetch the data in mbuf?


enter image description here

The valid data of the packet is placed in the red part of the mbuf in the figure. When the CPU wants to read the data in the packets, it will access the red part of the mbuf in the figure. So, I want to know how DPDK prefetches the mbuf, it will prefetch the whole mbuf to cache or only prefetch the data part(the red part in the figure).

In addition, it would be better if you could introduce the code of DPDK's prefetching mechanism (prefetch mbuf or RX descriptors) in detail.


Solution

  • DPDK uses architecture-specific prefetch instructions to prefetch data into the cache hierarchy. It also gives a uniform interface(e.g., rte_prefetch0) for convenient programming.

    You can find definitions of prefetch functions in arch-specific include directories:


    Prefetch functions accept only one argument: the memory address of prefetched data. Note that the effects of prefetch instructions are also architecture-specific. In x86 (I am more familiar with), prefetch instructions are merely hints, and hardware may ignore them. The amount of data to be prefetched is also uncertain, but it's typically one cacheline (64 Byte) in my experience.

    In practice, DPDK (and DPDK applications) rarely prefetch the whole mbuf or the whole data part. They only prefetch cachelines that are actually accessed, usually the first cacheline of the rte_mbuf struct, which contains the most frequently used fields, and the first cache line of the valid data, which usually contains headers of network packets.