Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: Use try_cmpxchg() in sb_init_done_wq()

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>
Link: https://lore.kernel.org/20250811132326.620521-1-ubizjak@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Uros Bizjak and committed by
Christian Brauner
ec6f613e 14498ca7

+5 -3
+5 -3
fs/super.c
··· 2318 2318 sb->s_id); 2319 2319 if (!wq) 2320 2320 return -ENOMEM; 2321 + 2322 + old = NULL; 2321 2323 /* 2322 2324 * This has to be atomic as more DIOs can race to create the workqueue 2323 2325 */ 2324 - old = cmpxchg(&sb->s_dio_done_wq, NULL, wq); 2325 - /* Someone created workqueue before us? Free ours... */ 2326 - if (old) 2326 + if (!try_cmpxchg(&sb->s_dio_done_wq, &old, wq)) { 2327 + /* Someone created workqueue before us? Free ours... */ 2327 2328 destroy_workqueue(wq); 2329 + } 2328 2330 return 0; 2329 2331 } 2330 2332 EXPORT_SYMBOL_GPL(sb_init_dio_done_wq);