All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Burkov <boris@bur.io>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Subject: Re: [PATCH] fs/btrfs: Use atomic_try_cmpxchg in free_extent_buffer
Date: Mon, 15 Aug 2022 14:36:25 -0700	[thread overview]
Message-ID: <Yvq8WaTZzWWusB25@zen> (raw)
In-Reply-To: <20220809163633.8255-1-ubizjak@gmail.com>

On Tue, Aug 09, 2022 at 06:36:33PM +0200, Uros Bizjak wrote:
> Use `atomic_try_cmpxchg(ptr, &old, new)` instead of
> `atomic_cmpxchg(ptr, old, new) == old` in free_extent_buffer. This
> has two benefits:
> 
> - The x86 cmpxchg instruction returns success in the ZF flag, so this
>   change saves a compare after cmpxchg, as well as a related move
>   instruction in the front of cmpxchg.
> 
> - atomic_try_cmpxchg implicitly assigns the *ptr value to &old when
>   cmpxchg fails, enabling further code simplifications.
> 
> This patch has no functional change.
> 
> Cc: Chris Mason <clm@fb.com>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: David Sterba <dsterba@suse.com>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Boris Burkov <boris@bur.io>
> ---
>  fs/btrfs/extent_io.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index bfae67c593c5..15ff196cbd6d 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -6328,18 +6328,16 @@ static int release_extent_buffer(struct extent_buffer *eb)
>  void free_extent_buffer(struct extent_buffer *eb)
>  {
>  	int refs;
> -	int old;
>  	if (!eb)
>  		return;
>  
> +	refs = atomic_read(&eb->refs);
>  	while (1) {
> -		refs = atomic_read(&eb->refs);
>  		if ((!test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) && refs <= 3)
>  		    || (test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags) &&
>  			refs == 1))
>  			break;
> -		old = atomic_cmpxchg(&eb->refs, refs, refs - 1);
> -		if (old == refs)
> +		if (atomic_try_cmpxchg(&eb->refs, &refs, refs - 1))
>  			return;
>  	}
>  
> -- 
> 2.37.1
> 

  reply	other threads:[~2022-08-16  1:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 16:36 [PATCH] fs/btrfs: Use atomic_try_cmpxchg in free_extent_buffer Uros Bizjak
2022-08-15 21:36 ` Boris Burkov [this message]
2022-08-18 17:14 ` David Sterba

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=Yvq8WaTZzWWusB25@zen \
    --to=boris@bur.io \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ubizjak@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.