From: Stephen Hemminger <stephen@networkplumber.org>
To: "Lombardo, Ed" <Ed.Lombardo@netscout.com>
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
"users@dpdk.org" <users@dpdk.org>
Subject: Re: mbuf refcnt issue
Date: Wed, 9 Apr 2025 09:24:18 -0700 [thread overview]
Message-ID: <20250409092418.70c5eb3d@hermes.local> (raw)
In-Reply-To: <CH3PR01MB847053D8D0F5F9E17DF72DCC8FB42@CH3PR01MB8470.prod.exchangelabs.com>
On Wed, 9 Apr 2025 04:46:09 +0000
"Lombardo, Ed" <Ed.Lombardo@netscout.com> wrote:
> Hi Stephen,
> I am looking a the rte_mbuf.h file for rte_pktmbuf_free() and it is not clear to me that it checks if the mbuf refcnt is 1 before decrementing it and allowing the mbuf and segments (if any) to be returned to free pool.
>
> Could my application issue be I have tx threads that transmit packets and does rte_pktmbuf_free(), while one other thread will perform rte_pktmbuf_free() on the same mbuf? I ensured I bump the mbuf refcnt to 2 before other threads can process the same mbuf.
>
> Thanks,
> Ed
It doesn't need to check refcnt there. The check is done later (since mbuf can be multi segment).
rte_pktmbuf_free
-> rte_pktmbuf_free_seg
-> rte_pktmbuf_prefree_seg
static __rte_always_inline struct rte_mbuf *
rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
__rte_mbuf_sanity_check(m, 0);
if (likely(rte_mbuf_refcnt_read(m) == 1)) {
normal fast path. breaks the chain.
} else if (__rte_mbuf_refcnt_update(m, -1) == 0) {
refcnt > 1 logic
Note, the refcnt doesn't always go to zero when the mbuf is put back in the pool.
The refcnt for a freed mbuf (in the pool) doesn't matter, it is free, it is dead.
The refcnt is reset to 1 when mbuf is extracted from the pool.
next prev parent reply other threads:[~2025-04-09 16:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 22:00 Lombardo, Ed
2025-04-04 22:29 ` Dmitry Kozlyuk
2025-04-07 19:53 ` Lombardo, Ed
2025-04-08 22:33 ` Lombardo, Ed
2025-04-09 3:53 ` Stephen Hemminger
2025-04-09 4:46 ` Lombardo, Ed
2025-04-09 16:24 ` Stephen Hemminger [this message]
2025-04-09 23:22 ` Lombardo, Ed
2025-04-10 3:25 ` Stephen Hemminger
2025-04-10 3:58 ` Lombardo, Ed
2025-04-10 21:15 ` Lombardo, Ed
2025-04-15 13:10 ` Lombardo, Ed
2025-04-16 0:01 ` Stephen Hemminger
2025-04-16 3:51 ` Lombardo, Ed
2025-04-09 16:15 ` Lombardo, Ed
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=20250409092418.70c5eb3d@hermes.local \
--to=stephen@networkplumber.org \
--cc=Ed.Lombardo@netscout.com \
--cc=dmitry.kozliuk@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).