My objective is to reuse mbuf unlimited number of times for a configurable amount of time.

rte_pktmbuf_alloc // after here refcnt is 1
refcnt_update ( , 1) //after here refcnt is 2
while( time still exists )
{
      tx_burst
}

Will this approach work with all drivers/cards ?

Thanks & Regards
--
Lokesh Chakka.


On Sat, Feb 22, 2025 at 12:16 AM Stephen Hemminger <stephen@networkplumber.org> wrote:
On Fri, 21 Feb 2025 13:09:34 +0530
Lokesh Chakka <lvenkatakumarchakka@gmail.com> wrote:

> Hello,
>
> I've created mbuf using rte_pktmbuf_alloc.
> Just after creating mbuf rte_mbuf_refcnt_read is giving 1.
>
> After rte_eth_tx_burst, rte_mbuf_refcnt_read is giving 1.
>
> Even
>       rte_eth_tx_burst
>       sleep(10);
>        rte_mbuf_refcnt_read
> is still giving 1
>
> Even
>       rte_eth_tx_burst
>       sleep(10);
>        rte_mbuf_refcnt_read // is still giving 1
>        rte_pktmbuf_free
>       sleep(10);
>        rte_mbuf_refcnt_read // is still giving 1
>
> Does it mean mbuf can be reused like
>         while(1)
>         {
>                   rte_eth_tx_burst
>         }
>
>
> Thanks & Regards
> --
> Lokesh Chakka.

Once you gave the mbuf to the driver, with a refcnt of 1 it
means the driver will free it. Any later reference is a use after free.
The driver will free it at an undetermined time after sending.
Some drivers defer the free until a later reclaim cycle (next send).

When mbuf is freed, the refcnt does not
go to zero, it just moves into the mbuf free pool.
Read the the source for more details.

There is no callback in DPDK for when mbuf is actually sent or freed.