DPDK usage discussions
 help / color / mirror / Atom feed
From: "Van Haaren, Harry" <harry.van.haaren@intel.com>
To: Antonio Di Bacco <a.dibacco.ks@gmail.com>,
	"users@dpdk.org" <users@dpdk.org>
Subject: RE: Prevent rte_eth_tx_burst from freeing mbufs
Date: Fri, 31 Mar 2023 08:26:06 +0000	[thread overview]
Message-ID: <BN0PR11MB57127363B539415E4613FDE5D78F9@BN0PR11MB5712.namprd11.prod.outlook.com> (raw)
In-Reply-To: <CAO8pfFmSa_eZa_NQ1akz-oMrLwrevVLgFnzue8cwC7F6mfi8cA@mail.gmail.com>

> -----Original Message-----
> From: Antonio Di Bacco <a.dibacco.ks@gmail.com>
> Sent: Thursday, March 30, 2023 10:11 PM
> To: users@dpdk.org
> Subject: Prevent rte_eth_tx_burst from freeing mbufs

Hi Antonio,

> Is it possibile to take full control of mbuf and avoid the mbuf to be
> freed after it has been sent?

Yes it is; technically the TX of DPDK's ethdev doesn't *free* the packet, it decreases the mbuf refcnt by 1.
If that happened to be the last user of that mbuf, then the mbuf will be freed (so returned to the mempool it came from).

So in order to keep the mbuf "around" while also TX-ing it, you can update its "refcnt" value.
There is a helper function to do this correctly (e.g, walk chains for multi segment mbufs!):
https://doc.dpdk.org/api/rte__mbuf_8h.html#a7ac5629940550649a2ef40029f5ad21a

Just adding 1 to the refcnt will keep the packet "in use" and not return it to the mempool, until the code where you own the "added refcnt" calls rte_pktmbuf_free(), which will reduce the refcnt from 1 -> 0, and return to the mempool then.

Please note; updating the refcnt keeps access to the *same* packet memory - it is NOT a copy. If you modify the packet after calling rte_eth_tx_burst(), you have a race condition. The TX on the NIC may take some time to complete (depends on NIC descriptor ring size, link-speed, TXQ schedulers etc..). I recommend to consider the "refcnt updated" packet handle a "read only" mbuf.

Hope that helps, -Harry



      reply	other threads:[~2023-03-31  8:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 21:10 Antonio Di Bacco
2023-03-31  8:26 ` Van Haaren, Harry [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN0PR11MB57127363B539415E4613FDE5D78F9@BN0PR11MB5712.namprd11.prod.outlook.com \
    --to=harry.van.haaren@intel.com \
    --cc=a.dibacco.ks@gmail.com \
    --cc=users@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).