Skip to content

Commit

Permalink
mbuf: remove the redundant code for mbuf prefree
Browse files Browse the repository at this point in the history
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 <ruifeng.wang@arm.com>
Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
Feifeiarm authored and ovsrobot committed Dec 4, 2023
1 parent c858f00 commit a2550ff
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions lib/mbuf/rte_mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a2550ff

Please sign in to comment.