From: Stephen Hemminger <stephen@networkplumber.org>
To: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Cc: "Morten Brørup" <mb@smartsharesystems.com>,
"Feifei Wang" <feifei.wang2@arm.com>,
"dev@dpdk.org" <dev@dpdk.org>, "nd@arm.com" <nd@arm.com>,
"Ruifeng Wang" <ruifeng.wang@arm.com>
Subject: Re: [PATCH v1] mbuf: remove the redundant code for mbuf prefree
Date: Tue, 5 Dec 2023 10:50:32 -0800 [thread overview]
Message-ID: <20231205105032.4b81e3da@hermes.local> (raw)
In-Reply-To: <f86c58a6521142c6add96b8ff17bac65@huawei.com>
On Mon, 4 Dec 2023 11:07:08 +0000
Konstantin Ananyev <konstantin.ananyev@huawei.com> wrote:
> > > 2.25.1
> >
> > NAK.
> >
> > This patch is not race safe.
>
> +1, It is a bad idea.
The patch does raise a couple of issues that could be addressed by
rearranging. There is duplicate code, and there are no comments
to explain the rationale.
Maybe something like the following (untested):
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index 286b32b788a5..b43c055fbe3f 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -1342,42 +1342,32 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
{
__rte_mbuf_sanity_check(m, 0);
- if (likely(rte_mbuf_refcnt_read(m) == 1)) {
-
- if (!RTE_MBUF_DIRECT(m)) {
- rte_pktmbuf_detach(m);
- if (RTE_MBUF_HAS_EXTBUF(m) &&
- RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
- __rte_pktmbuf_pinned_extbuf_decref(m))
- return NULL;
- }
-
- if (m->next != NULL)
- m->next = NULL;
- if (m->nb_segs != 1)
- m->nb_segs = 1;
-
- return m;
-
- } else if (__rte_mbuf_refcnt_update(m, -1) == 0) {
-
- if (!RTE_MBUF_DIRECT(m)) {
- rte_pktmbuf_detach(m);
- if (RTE_MBUF_HAS_EXTBUF(m) &&
- RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
- __rte_pktmbuf_pinned_extbuf_decref(m))
- return NULL;
- }
-
- if (m->next != NULL)
- m->next = NULL;
- if (m->nb_segs != 1)
- m->nb_segs = 1;
+ if (likely(rte_mbuf_refcnt_read(m) != 1) ) {
+ /* If this is the only reference to the mbuf it can just
+ * be setup for reuse without modifying reference count.
+ */
+ } else if (unlikely(__rte_mbuf_refcnt_update(m, -1) == 0)) {
+ /* This was last reference reset to 1 for recycling/free. */
rte_mbuf_refcnt_set(m, 1);
+ } else {
+ /* mbuf is still in use */
+ return NULL;
+ }
- return m;
+ if (!RTE_MBUF_DIRECT(m)) {
+ rte_pktmbuf_detach(m);
+ if (RTE_MBUF_HAS_EXTBUF(m) &&
+ RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
+ __rte_pktmbuf_pinned_extbuf_decref(m))
+
+ return NULL;
}
- return NULL;
+
+ if (m->next != NULL)
+ m->next = NULL;
+ if (m->nb_segs != 1)
+ m->nb_segs = 1;
+ return m;
}
/**
next prev parent reply other threads:[~2023-12-05 18:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 2:39 [PATCH v1] mbuf: remove the redundant code for mbuf prefree Feifei Wang
2023-12-04 7:41 ` Morten Brørup
2023-12-04 11:07 ` Konstantin Ananyev
2023-12-05 18:50 ` Stephen Hemminger [this message]
2023-12-06 10:12 ` Bruce Richardson
2023-12-06 10:21 ` Konstantin Ananyev
2023-12-05 3:13 ` Feifei Wang
2023-12-05 8:04 ` Morten Brørup
2023-12-05 9:53 ` Bruce Richardson
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=20231205105032.4b81e3da@hermes.local \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=feifei.wang2@arm.com \
--cc=konstantin.ananyev@huawei.com \
--cc=mb@smartsharesystems.com \
--cc=nd@arm.com \
--cc=ruifeng.wang@arm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.