Commit 4817730c authored by Barry Song's avatar Barry Song Committed by Euler
Browse files

mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases

mainline inclusion
from mainline-v6.12-rc1
commit e26f0b939df49d17bda8d5faa4813a255734e8c8
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAOMRL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e26f0b939df49d17bda8d5faa4813a255734e8c8

--------------------------------

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.

[akpm@linux-foundation.org: avoid using goto]
Link: https://lkml.kernel.org/r/20240221091028.123122-1-21cnbao@gmail.com


Signed-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarWang Lian <dev01404@linx-info.com>
---
parent 808068da
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3524,6 +3524,7 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)
	} else
		err = -ENOENT;			/* unused swap entry */

	if (!err)
		WRITE_ONCE(p->swap_map[offset], count | has_cache);

unlock_out: