[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240221091028.123122-1-21cnbao@gmail.com>
Date: Wed, 21 Feb 2024 22:10:28 +1300
From: Barry Song <21cnbao@...il.com>
To: akpm@...ux-foundation.org,
linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org,
Barry Song <v-songbaohua@...o.com>
Subject: [PATCH] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases
From: Barry Song <v-songbaohua@...o.com>
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.
Signed-off-by: Barry Song <v-songbaohua@...o.com>
---
mm/swapfile.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 556ff7347d5f..17557003858c 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3320,6 +3320,9 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)
} else
err = -ENOENT; /* unused swap entry */
+ if (err)
+ goto unlock_out;
+
WRITE_ONCE(p->swap_map[offset], count | has_cache);
unlock_out:
--
2.34.1
Powered by blists - more mailing lists