DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier MATZ <olivier.matz@6wind.com>
To: Bruce Richardson <bruce.richardson@intel.com>, dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] mbuf: add comment explaining confusing code
Date: Thu, 26 Mar 2015 22:31:01 +0100	[thread overview]
Message-ID: <55147A95.6060102@6wind.com> (raw)
In-Reply-To: <1427404494-27256-1-git-send-email-bruce.richardson@intel.com>

Hi Bruce,

On 03/26/2015 10:14 PM, 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@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)) {
>  
> 

Acked-by: Olivier Matz <olivier.matz@6wind.com>

Thanks!

  reply	other threads:[~2015-03-26 21:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26 21:14 Bruce Richardson
2015-03-26 21:31 ` Olivier MATZ [this message]
2015-03-27 10:29 ` Neil Horman
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
2015-03-27 14:30       ` Bruce Richardson
2015-03-27 14:38         ` Neil Horman
2015-03-27 14:55           ` Bruce Richardson
2015-03-27 16:43             ` Neil Horman
2015-03-27 16:56               ` Richardson, Bruce
2015-03-30 17:11                 ` Thomas Monjalon
2015-03-30 17:39                 ` Don Provan
2015-03-30 18:15                   ` Stephen Hemminger
2015-03-31 12:33                   ` Zoltan Kiss
2015-03-30 19:39         ` Marc Sune
2015-03-30 20:26           ` Neil Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55147A95.6060102@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).