linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Huang Ying <ying.huang@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Minchan Kim <minchan@kernel.org>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm, swap: Use prandom_u32_max()
Date: Tue, 12 May 2020 08:50:49 +0200	[thread overview]
Message-ID: <20200512065049.GN29153@dhcp22.suse.cz> (raw)
In-Reply-To: <20200512064147.514493-1-ying.huang@intel.com>

On Tue 12-05-20 14:41:46, Huang Ying wrote:
> To improve the code readability and get random number with higher
> quality.

I understand the readability argument but why should prandom_u32_max
(which I was not aware of) provide a higher quality randomness?

> Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Tim Chen <tim.c.chen@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>

To the change itself
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/swapfile.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index a0a123e59ce6..2ec8b21201d6 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3220,7 +3220,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  		 * select a random position to start with to help wear leveling
>  		 * SSD
>  		 */
> -		p->cluster_next = 1 + (prandom_u32() % p->highest_bit);
> +		p->cluster_next = 1 + prandom_u32_max(p->highest_bit);
>  		nr_cluster = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER);
>  
>  		cluster_info = kvcalloc(nr_cluster, sizeof(*cluster_info),
> -- 
> 2.26.2

-- 
Michal Hocko
SUSE Labs


  reply	other threads:[~2020-05-12  6:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12  6:41 Huang Ying
2020-05-12  6:50 ` Michal Hocko [this message]
2020-05-12  7:14   ` Huang, Ying
2020-05-12  7:32     ` Michal Hocko
2020-05-12  7:38       ` Huang, Ying

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=20200512065049.GN29153@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=ying.huang@intel.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