mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Barry Song <21cnbao@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>
Subject: Re: [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases
Date: Mon, 11 Mar 2024 15:37:22 +0100	[thread overview]
Message-ID: <3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com> (raw)
In-Reply-To: <20240221210845.13488-1-21cnbao@gmail.com>

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>

-- 
Cheers,

David / dhildenb


  reply	other threads:[~2024-03-11 14:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 21:08 Barry Song
2024-03-11 14:37 ` David Hildenbrand [this message]
2024-03-11 23:14   ` Barry Song

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=3439a693-753e-4293-a0fe-eefd7b3cdf53@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --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

all inboxes | Powered by JetHome®