<div dir="ltr"><div>My objective is to reuse mbuf unlimited number of times for a configurable amount of time.</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><br></div><div>rte_pktmbuf_alloc // after here refcnt is 1</div><div>refcnt_update ( , 1) //after here refcnt is 2</div><div>while( time still exists )</div><div>{</div><div> tx_burst</div><div>}</div><div dir="ltr"><br></div><div>Will this approach work with all drivers/cards ?</div><div dir="ltr"><br>Thanks & Regards<br>--<br>Lokesh Chakka.</div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, Feb 22, 2025 at 12:16 AM Stephen Hemminger <<a href="mailto:stephen@networkplumber.org">stephen@networkplumber.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 21 Feb 2025 13:09:34 +0530<br>
Lokesh Chakka <<a href="mailto:lvenkatakumarchakka@gmail.com" target="_blank">lvenkatakumarchakka@gmail.com</a>> wrote:<br>
<br>
> Hello,<br>
> <br>
> I've created mbuf using rte_pktmbuf_alloc.<br>
> Just after creating mbuf rte_mbuf_refcnt_read is giving 1.<br>
> <br>
> After rte_eth_tx_burst, rte_mbuf_refcnt_read is giving 1.<br>
> <br>
> Even<br>
> rte_eth_tx_burst<br>
> sleep(10);<br>
> rte_mbuf_refcnt_read<br>
> is still giving 1<br>
> <br>
> Even<br>
> rte_eth_tx_burst<br>
> sleep(10);<br>
> rte_mbuf_refcnt_read // is still giving 1<br>
> rte_pktmbuf_free<br>
> sleep(10);<br>
> rte_mbuf_refcnt_read // is still giving 1<br>
> <br>
> Does it mean mbuf can be reused like<br>
> while(1)<br>
> {<br>
> rte_eth_tx_burst<br>
> }<br>
> <br>
> <br>
> Thanks & Regards<br>
> --<br>
> Lokesh Chakka.<br>
<br>
Once you gave the mbuf to the driver, with a refcnt of 1 it<br>
means the driver will free it. Any later reference is a use after free.<br>
The driver will free it at an undetermined time after sending.<br>
Some drivers defer the free until a later reclaim cycle (next send).<br>
<br>
When mbuf is freed, the refcnt does not<br>
go to zero, it just moves into the mbuf free pool.<br>
Read the the source for more details.<br>
<br>
There is no callback in DPDK for when mbuf is actually sent or freed.<br>
<br>
</blockquote></div>