linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE
Date: Sun, 25 Oct 2020 17:14:11 -0700	[thread overview]
Message-ID: <20201025171411.20fce472df99bc43fce7156c@linux-foundation.org> (raw)
In-Reply-To: <20200921122224.7139-1-linmiaohe@huawei.com>

On Mon, 21 Sep 2020 08:22:24 -0400 Miaohe Lin <linmiaohe@huawei.com> wrote:

> We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead
> of a direct loop here to simplify the code. Also we can remove the local
> variable i and map this way.
> 
> ...
>
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
>  {
>  	unsigned long idx;
>  	struct swap_cluster_info *ci;
> -	unsigned long offset, i;
> -	unsigned char *map;
> +	unsigned long offset;
>  
>  	/*
>  	 * Should not even be attempting cluster allocations when huge
> @@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot)
>  	alloc_cluster(si, idx);
>  	cluster_set_count_flag(ci, SWAPFILE_CLUSTER, CLUSTER_FLAG_HUGE);
>  
> -	map = si->swap_map + offset;
> -	for (i = 0; i < SWAPFILE_CLUSTER; i++)
> -		map[i] = SWAP_HAS_CACHE;
> +	memset(si->swap_map + offset, SWAP_HAS_CACHE, SWAPFILE_CLUSTER);
>  	unlock_cluster(ci);
>  	swap_range_alloc(si, offset, SWAPFILE_CLUSTER);
>  	*slot = swp_entry(si->type, offset);

I suppose so.  But it does assume that the ->swapmap array has the type
char.  If we ever change that, breakage will ensue.


  reply	other threads:[~2020-10-26  0:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-21 12:22 [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE Miaohe Lin
2020-10-26  0:14 ` Andrew Morton [this message]
2020-10-07  2:49 linmiaohe
2020-10-26  3:03 linmiaohe

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=20201025171411.20fce472df99bc43fce7156c@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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;
as well as URLs for NNTP newsgroup(s).