The patch titled Subject: mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases has been added to the -mm mm-unstable branch. Its filename is mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Barry Song <21cnbao@xxxxxxxxx> Subject: mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases Date: Wed, 21 Feb 2024 22:10:28 +1300 The code is quite hard to read, we are still writing swap_map after errors happen. Though the written value is as before, has_cache = count & SWAP_HAS_CACHE; count &= ~SWAP_HAS_CACHE; [snipped] WRITE_ONCE(p->swap_map[offset], count | has_cache); It would be better to entirely drop the WRITE_ONCE for both performance and readability. Link: https://lkml.kernel.org/r/20240221091028.123122-1-21cnbao@xxxxxxxxx Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/swapfile.c | 3 +++ 1 file changed, 3 insertions(+) --- a/mm/swapfile.c~mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases +++ a/mm/swapfile.c @@ -3335,6 +3335,9 @@ static int __swap_duplicate(swp_entry_t } else err = -ENOENT; /* unused swap entry */ + if (err) + goto unlock_out; + WRITE_ONCE(p->swap_map[offset], count | has_cache); unlock_out: _ Patches currently in -mm which might be from 21cnbao@xxxxxxxxx are mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases.patch