* [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases
@ 2024-02-21 21:08 Barry Song
[not found] ` <3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com>
0 siblings, 1 reply; 2+ messages in thread
From: Barry Song @ 2024-02-21 21:08 UTC (permalink / raw)
To: akpm, linux-mm; +Cc: linux-kernel, Barry Song
From: Barry Song <v-songbaohua@oppo.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@oppo.com>
---
-v2: drop goto according to Andrew, Thanks!
mm/swapfile.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 556ff7347d5f..7cb6d9a2d51d 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3320,7 +3320,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);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread[parent not found: <3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com>]
* Re: [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases [not found] ` <3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com> @ 2024-03-11 23:14 ` Barry Song 0 siblings, 0 replies; 2+ messages in thread From: Barry Song @ 2024-03-11 23:14 UTC (permalink / raw) To: David Hildenbrand; +Cc: akpm, linux-mm, linux-kernel, Barry Song On Mon, Mar 11, 2024 at 10:37 PM David Hildenbrand <david@redhat.com> wrote: > > On 21.02.24 22:08, Barry Song wrote: > > From: Barry Song <v-songbaohua@oppo.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@oppo.com> > > --- > > -v2: drop goto according to Andrew, Thanks! > > > > mm/swapfile.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 556ff7347d5f..7cb6d9a2d51d 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3320,7 +3320,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); > > Maybe too late, but LGTM > > Reviewed-by: David Hildenbrand <david@redhat.com> David, thanks! Though it is probably too late as this one has been in mm-stable for a long time. > > -- > Cheers, > > David / dhildenb Thanks Barry ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-11 23:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21 21:08 [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases Barry Song
[not found] ` <3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com>
2024-03-11 23:14 ` Barry Song
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox