[dpdk-dev] [PATCH] mbuf: add comment explaining confusing code
Ananyev, Konstantin
konstantin.ananyev at intel.com
Fri Mar 27 11:49:58 CET 2015
> -----Original Message-----
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Neil Horman
> Sent: Friday, March 27, 2015 10:30 AM
> To: Richardson, Bruce
> Cc: dev at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing code
>
> On Thu, Mar 26, 2015 at 09:14:54PM +0000, Bruce Richardson wrote:
> > 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 at intel.com>
> > ---
> > 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
> >
> >
>
> NAK
> the comment is incorrect, a return code of 1 from rte_mbuf_refcnt_read doesn't
> guarantee you are the last holder of the buffer if two contexts have a pointer
> to it.
Comment is absolutely correct.
Zoltan's 'fix' will introduce unnecessary slowdown.
Acked-by: Konstantin Ananyev <konstantin.ananyev at intel.com>
>
> Zoltans patch is the correct solution here, expensive or not. I wrote up my
> explination in this thread:
> http://dpdk.org/ml/archives/dev/2015-March/015839.html
>
More information about the dev
mailing list