From patchwork Mon Dec 4 02:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feifei Wang X-Patchwork-Id: 134778 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4A76843666; Mon, 4 Dec 2023 03:39:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21026402AE; Mon, 4 Dec 2023 03:39:25 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id 100114026C for ; Mon, 4 Dec 2023 03:39:23 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 89F54165C; Sun, 3 Dec 2023 18:40:09 -0800 (PST) Received: from net-x86-dell-8268.shanghai.arm.com (net-x86-dell-8268.shanghai.arm.com [10.169.210.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D92823F6C4; Sun, 3 Dec 2023 18:39:20 -0800 (PST) From: Feifei Wang To: Cc: dev@dpdk.org, nd@arm.com, Feifei Wang , Ruifeng Wang Subject: [PATCH v1] mbuf: remove the redundant code for mbuf prefree Date: Mon, 4 Dec 2023 10:39:10 +0800 Message-Id: <20231204023910.1714667-1-feifei.wang2@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org For 'rte_pktmbuf_prefree_seg' function, 'rte_mbuf_refcnt_read(m) == 1' and '__rte_mbuf_refcnt_update(m, -1) == 0' are the same cases where mbuf's refcnt value should be 1. Thus we can simplify the code and remove the redundant part. Furthermore, according to [1], when the mbuf is stored inside the mempool, the m->refcnt value should be 1. And then it is detached from its parent for an indirect mbuf. Thus change the description of 'rte_pktmbuf_prefree_seg' function. [1] https://patches.dpdk.org/project/dpdk/patch/20170404162807.20157-4-olivier.matz@6wind.com/ Suggested-by: Ruifeng Wang Signed-off-by: Feifei Wang --- lib/mbuf/rte_mbuf.h | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h index 286b32b788..42e9b50d51 100644 --- a/lib/mbuf/rte_mbuf.h +++ b/lib/mbuf/rte_mbuf.h @@ -1328,7 +1328,7 @@ static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m) * * This function does the same than a free, except that it does not * return the segment to its pool. - * It decreases the reference counter, and if it reaches 0, it is + * It decreases the reference counter, and if it reaches 1, it is * detached from its parent for an indirect mbuf. * * @param m @@ -1358,25 +1358,9 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) 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; - rte_mbuf_refcnt_set(m, 1); - - return m; } + + __rte_mbuf_refcnt_update(m, -1); return NULL; }