DPDK usage discussions
 help / color / mirror / Atom feed
* mbuf validity in conjunction with ref cnt
@ 2025-02-21  7:39 Lokesh Chakka
  2025-02-21 18:46 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Lokesh Chakka @ 2025-02-21  7:39 UTC (permalink / raw)
  To: users

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 1260 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mbuf validity in conjunction with ref cnt
  2025-02-21  7:39 mbuf validity in conjunction with ref cnt Lokesh Chakka
@ 2025-02-21 18:46 ` Stephen Hemminger
  2025-02-22  4:52   ` Lokesh Chakka
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2025-02-21 18:46 UTC (permalink / raw)
  To: Lokesh Chakka; +Cc: users

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mbuf validity in conjunction with ref cnt
  2025-02-21 18:46 ` Stephen Hemminger
@ 2025-02-22  4:52   ` Lokesh Chakka
  2025-02-22 16:18     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Lokesh Chakka @ 2025-02-22  4:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: users

[-- Attachment #1: Type: text/plain, Size: 1767 bytes --]

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.
>
>

[-- Attachment #2: Type: text/html, Size: 2767 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mbuf validity in conjunction with ref cnt
  2025-02-22  4:52   ` Lokesh Chakka
@ 2025-02-22 16:18     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2025-02-22 16:18 UTC (permalink / raw)
  To: Lokesh Chakka; +Cc: users

On Sat, 22 Feb 2025 10:22:51 +0530
Lokesh Chakka <lvenkatakumarchakka@gmail.com> wrote:

> 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 ?

For that kind of flood you need to get reference before tx_burst.
The driver will see mbuf with refcnt of 2 and decrement it to 1 when
done.

	mb = rte_pktmbuf_alloc();
	// setup the mbuf

	while (!stopped) {
		rte_mbuf_ref_update(mb, 1); // retain original
		... tx_burst
	}
	rte_pktmbuf_free(mb); // release original




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-22 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-21  7:39 mbuf validity in conjunction with ref cnt Lokesh Chakka
2025-02-21 18:46 ` Stephen Hemminger
2025-02-22  4:52   ` Lokesh Chakka
2025-02-22 16:18     ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).