linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq()
@ 2025-08-11 13:23 Uros Bizjak
  2025-08-22 14:20 ` Jan Kara
  2025-08-25 12:09 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Uros Bizjak @ 2025-08-11 13:23 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: Uros Bizjak, Alexander Viro, Christian Brauner, Jan Kara

Use !try_cmpxchg() instead of cmpxchg(*ptr, old, new) != old.

The x86 CMPXCHG instruction returns success in the ZF flag,
so this change saves a compare after CMPXCHG.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
---
 fs/super.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/super.c b/fs/super.c
index 7f876f32343a..e91718017701 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -2318,13 +2318,15 @@ int sb_init_dio_done_wq(struct super_block *sb)
 						      sb->s_id);
 	if (!wq)
 		return -ENOMEM;
+
+	old = NULL;
 	/*
 	 * This has to be atomic as more DIOs can race to create the workqueue
 	 */
-	old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
-	/* Someone created workqueue before us? Free ours... */
-	if (old)
+	if (!try_cmpxchg(&sb->s_dio_done_wq, &old, wq)) {
+		/* Someone created workqueue before us? Free ours... */
 		destroy_workqueue(wq);
+	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(sb_init_dio_done_wq);
-- 
2.50.1


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

* Re: [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq()
  2025-08-11 13:23 [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq() Uros Bizjak
@ 2025-08-22 14:20 ` Jan Kara
  2025-08-25 12:09 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2025-08-22 14:20 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: linux-fsdevel, linux-kernel, Alexander Viro, Christian Brauner,
	Jan Kara

On Mon 11-08-25 15:23:03, Uros Bizjak wrote:
> Use !try_cmpxchg() instead of cmpxchg(*ptr, old, new) != old.
> 
> The x86 CMPXCHG instruction returns success in the ZF flag,
> so this change saves a compare after CMPXCHG.
> 
> No functional change intended.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Jan Kara <jack@suse.cz>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/super.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 7f876f32343a..e91718017701 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -2318,13 +2318,15 @@ int sb_init_dio_done_wq(struct super_block *sb)
>  						      sb->s_id);
>  	if (!wq)
>  		return -ENOMEM;
> +
> +	old = NULL;
>  	/*
>  	 * This has to be atomic as more DIOs can race to create the workqueue
>  	 */
> -	old = cmpxchg(&sb->s_dio_done_wq, NULL, wq);
> -	/* Someone created workqueue before us? Free ours... */
> -	if (old)
> +	if (!try_cmpxchg(&sb->s_dio_done_wq, &old, wq)) {
> +		/* Someone created workqueue before us? Free ours... */
>  		destroy_workqueue(wq);
> +	}
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(sb_init_dio_done_wq);
> -- 
> 2.50.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq()
  2025-08-11 13:23 [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq() Uros Bizjak
  2025-08-22 14:20 ` Jan Kara
@ 2025-08-25 12:09 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2025-08-25 12:09 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, Uros Bizjak
  Cc: Christian Brauner, Alexander Viro, Jan Kara

On Mon, 11 Aug 2025 15:23:03 +0200, Uros Bizjak wrote:
> Use !try_cmpxchg() instead of cmpxchg(*ptr, old, new) != old.
> 
> The x86 CMPXCHG instruction returns success in the ZF flag,
> so this change saves a compare after CMPXCHG.
> 
> No functional change intended.
> 
> [...]

Applied to the vfs-6.18.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.18.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.18.misc

[1/1] fs: Use try_cmpxchg() in sb_init_done_wq()
      https://git.kernel.org/vfs/vfs/c/ec6f613ef376

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

end of thread, other threads:[~2025-08-25 12:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 13:23 [PATCH] fs: Use try_cmpxchg() in sb_init_done_wq() Uros Bizjak
2025-08-22 14:20 ` Jan Kara
2025-08-25 12:09 ` Christian Brauner

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