dev.dpdk.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mbuf: add comment explaining confusing code
@ 2015-03-26 21:14 Bruce Richardson
       [not found] ` <1427404494-27256-1-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Bruce Richardson @ 2015-03-26 21:14 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

The logic used in the condition check before freeing an mbuf is
sometimes confusing, so explain it in a proper comment.

Signed-off-by: Bruce Richardson <bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 lib/librte_mbuf/rte_mbuf.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 17ba791..0265172 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -764,6 +764,16 @@ __rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
 {
 	__rte_mbuf_sanity_check(m, 0);
 
+	/*
+	 * Check to see if this is the last reference to the mbuf.
+	 * Note: the double check here is deliberate. If the ref_cnt is "atomic"
+	 * the call to "refcnt_update" is a very expensive operation, so we
+	 * don't want to call it in the case where we know we are the holder
+	 * of the last reference to this mbuf i.e. ref_cnt == 1.
+	 * If however, ref_cnt != 1, it's still possible that we may still be
+	 * the final decrementer of the count, so we need to check that
+	 * result also, to make sure the mbuf is freed properly.
+	 */
 	if (likely (rte_mbuf_refcnt_read(m) == 1) ||
 			likely (rte_mbuf_refcnt_update(m, -1) == 0)) {
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-03-31 12:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-26 21:14 [PATCH] mbuf: add comment explaining confusing code Bruce Richardson
     [not found] ` <1427404494-27256-1-git-send-email-bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-26 21:31   ` Olivier MATZ
2015-03-27 10:29   ` Neil Horman
     [not found]     ` <20150327102956.GB5375-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-03-27 10:49       ` Ananyev, Konstantin
2015-03-27 11:32       ` Bruce Richardson
2015-03-27 12:42         ` Neil Horman
2015-03-27 14:07         ` Neil Horman
     [not found]           ` <20150327140735.GG5375-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-03-27 14:30             ` Bruce Richardson
2015-03-27 14:38               ` Neil Horman
     [not found]                 ` <20150327143841.GH5375-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-03-27 14:55                   ` Bruce Richardson
2015-03-27 16:43                     ` Neil Horman
     [not found]                       ` <20150327164358.GI5375-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2015-03-27 16:56                         ` Richardson, Bruce
     [not found]                           ` <59AF69C657FD0841A61C55336867B5B0344F112F-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-30 17:11                             ` Thomas Monjalon
2015-03-30 17:39                             ` Don Provan
     [not found]                               ` <CY1PR0101MB098798EEE9925C308B388CCDA0F50-elK4CTTmIKSdtLHx9EgMneS7vWlUgQib2Vl/xy9FO7SakBO8gow8eQ@public.gmane.org>
2015-03-30 18:15                                 ` Stephen Hemminger
2015-03-31 12:33                                 ` Zoltan Kiss
2015-03-30 19:39               ` Marc Sune
     [not found]                 ` <5519A661.6060202-kpkqNMk1I7M@public.gmane.org>
2015-03-30 20:26                   ` Neil Horman

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).