From: Andrew Morton <akpm@linux-foundation.org>
To: Barry Song <21cnbao@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Barry Song <v-songbaohua@oppo.com>
Subject: Re: [PATCH] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases
Date: Wed, 21 Feb 2024 12:36:09 -0800 [thread overview]
Message-ID: <20240221123609.3cd20c3dc2d6adeaf5d3ffc8@linux-foundation.org> (raw)
In-Reply-To: <20240221091028.123122-1-21cnbao@gmail.com>
On Wed, 21 Feb 2024 22:10:28 +1300 Barry Song <21cnbao@gmail.com> 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.
>
> ...
>
> --- 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:
I agree, but why add the goto?
--- a/mm/swapfile.c~mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases-fix
+++ a/mm/swapfile.c
@@ -3335,10 +3335,8 @@ 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);
+ if (!err)
+ WRITE_ONCE(p->swap_map[offset], count | has_cache);
unlock_out:
unlock_cluster_or_swap_info(p, ci);
_
prev parent reply other threads:[~2024-02-21 20:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 9:10 Barry Song
2024-02-21 20:36 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221123609.3cd20c3dc2d6adeaf5d3ffc8@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=21cnbao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=v-songbaohua@oppo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox