From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chas Williams <3chas3@gmail.com> Subject: Re: [PATCH v2] mbuf: use refcnt = 0 when debugging Date: Thu, 07 Sep 2017 11:55:39 -0400 Message-ID: <1504799739.2192.21.camel@gmail.com> References: <1502120243-8902-1-git-send-email-ciwillia@brocade.com> <1502122274-15657-1-git-send-email-ciwillia@brocade.com> <1504694773.2192.9.camel@gmail.com> <2601191342CEEE43887BDE71AB9772584F248208@irsmsx105.ger.corp.intel.com> <1504706130.2192.11.camel@gmail.com> <2601191342CEEE43887BDE71AB9772584F2482B0@irsmsx105.ger.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: "olivier.matz@6wind.com" To: "Ananyev, Konstantin" , "Nicolau, Radu" , "dev@dpdk.org" Return-path: Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by dpdk.org (Postfix) with ESMTP id 4C4E32BFE for ; Thu, 7 Sep 2017 17:55:43 +0200 (CEST) Received: by mail-qt0-f194.google.com with SMTP id h21so72514qth.4 for ; Thu, 07 Sep 2017 08:55:43 -0700 (PDT) In-Reply-To: <2601191342CEEE43887BDE71AB9772584F2482B0@irsmsx105.ger.corp.intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Wed, 2017-09-06 at 14:53 +0000, Ananyev, Konstantin wrote: > > > -----Original Message----- > > From: Chas Williams [mailto:3chas3@gmail.com] > > Sent: Wednesday, September 6, 2017 2:56 PM > > To: Ananyev, Konstantin ; Nicolau, Radu ; dev@dpdk.org > > Cc: olivier.matz@6wind.com; cw817q@att.com > > Subject: Re: [dpdk-dev] [PATCH v2] mbuf: use refcnt = 0 when debugging > > > > On Wed, 2017-09-06 at 11:58 +0000, Ananyev, Konstantin wrote: > > > > > > > -----Original Message----- > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Chas Williams > > > > Sent: Wednesday, September 6, 2017 11:46 AM > > > > To: Nicolau, Radu ; dev@dpdk.org > > > > Cc: olivier.matz@6wind.com; cw817q@att.com > > > > Subject: Re: [dpdk-dev] [PATCH v2] mbuf: use refcnt = 0 when debugging > > > > > > > > [Note: My former email address is going away eventually. I am moving the > > > > conversation to my other email address which is a bit more permanent.] > > > > > > > > On Mon, 2017-09-04 at 15:27 +0100, Radu Nicolau wrote: > > > > > > > > > > On 8/7/2017 5:11 PM, Charles (Chas) Williams wrote: > > > > > > After commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool") is it > > > > > > much harder to detect a "double free". If the developer makes a copy > > > > > > of an mbuf pointer and frees it twice, this condition is never detected > > > > > > and the mbuf gets returned to the pool twice. > > > > > > > > > > > > Since this requires extra work to track, make this behavior conditional > > > > > > on CONFIG_RTE_LIBRTE_MBUF_DEBUG. > > > > > > > > > > > > Signed-off-by: Chas Williams > > > > > > --- > > > > > > > > > > > > @@ -1304,10 +1329,13 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > > > > > > m->next = NULL; > > > > > > m->nb_segs = 1; > > > > > > } > > > > > > +#ifdef RTE_LIBRTE_MBUF_DEBUG > > > > > > + rte_mbuf_refcnt_set(m, RTE_MBUF_UNUSED_CNT); > > > > > > +#endif > > > > > > > > > > > > return m; > > > > > > > > > > > > - } else if (rte_atomic16_add_return(&m->refcnt_atomic, -1) == 0) { > > > > > > + } else if (rte_mbuf_refcnt_update(m, -1) == 0) { > > > > > Why replace the use of atomic operation? > > > > > > > > It doesn't. rte_mbuf_refcnt_update() is also atomic(ish) but it slightly more > > > > optimal. This whole section is a little hazy actually. It looks like > > > > rte_pktmbuf_prefree_seg() unwraps rte_mbuf_refcnt_update() so they can avoid > > > > setting the refcnt when the refcnt is already the 'correct' value. > > > > > > You don't need to use refcnt_update() here - if you take that path it already means > > > that m->refcnt_atomic != 1. > > > In fact, I think using refcnt_update () here might be a bit slower - as it means extra read. > > > Konstantin > > > > Yes, that is somewhat the point. If a mbuf can have a refcnt of 0, > > then we want to go into rte_mbuf_refcnt_update() which detects 0 -> -1. > > Woulnd't __rte_mbuf_sanity_check(m, 0) at the start of prefree_seg() > already catch it? > Konstantin Yes! I didn't notice that so I will just drop change and issue a v3 today sometime. Thanks! > > I could explicitly check this in prefree_seg but I was just restored the > > previous call into refcnt_update. I could explicitly check for refcnt = > > 0 in prefree_seg() but since we do have a routine for this... > > > > > > > > > > > > > > > > > > > > if (RTE_MBUF_INDIRECT(m)) > > > > > > @@ -1317,7 +1345,7 @@ rte_pktmbuf_prefree_seg(struct rte_mbuf *m) > > > > > > m->next = NULL; > > > > > > m->nb_segs = 1; > > > > > > } > > > > > > - rte_mbuf_refcnt_set(m, 1); > > > > > > + rte_mbuf_refcnt_set(m, RTE_MBUF_UNUSED_CNT); > > > > > > > > > > > > return m; > > > > > > } > > > > > Reviewed-by: Radu Nicolau > > > > > > > > Thanks for the review.