aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorBarry Song <v-songbaohua@oppo.com>2024-02-21 22:10:28 +1300
committerAndrew Morton <akpm@linux-foundation.org>2024-02-23 17:48:34 -0800
commite26f0b939df49d17bda8d5faa4813a255734e8c8 (patch)
tree03699017182abedce2961344e422ade45e9ceca5 /mm
parentb4d3de57cab266fcb536007bf51f42249af364c3 (diff)
downloadlinux-e26f0b939df49d17bda8d5faa4813a255734e8c8.tar.gz
mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases
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: Barry Song <v-songbaohua@oppo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/swapfile.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index d1bd8d1e17bd30..2b3a2d85e350ba 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3335,7 +3335,8 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)
} else
err = -ENOENT; /* unused swap entry */
- WRITE_ONCE(p->swap_map[offset], count | has_cache);
+ if (!err)
+ WRITE_ONCE(p->swap_map[offset], count | has_cache);
unlock_out:
unlock_cluster_or_swap_info(p, ci);