From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1F3DC54E4A for ; Tue, 12 May 2020 07:38:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89C2420733 for ; Tue, 12 May 2020 07:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89C2420733 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E798A90009D; Tue, 12 May 2020 03:38:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E2B19900036; Tue, 12 May 2020 03:38:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D408890009D; Tue, 12 May 2020 03:38:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id C0951900036 for ; Tue, 12 May 2020 03:38:20 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 825812C93 for ; Tue, 12 May 2020 07:38:20 +0000 (UTC) X-FDA: 76807263960.05.night76_e778cbac1a12 X-HE-Tag: night76_e778cbac1a12 X-Filterd-Recvd-Size: 4180 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 May 2020 07:38:19 +0000 (UTC) IronPort-SDR: 4VsrtZ4PAfKLQjzfvbsjS89bk9pBKrpEp5QjvT165fBaezqDvNnTkAY4BJptOkg80fRYSB5S/M UP1OEuHCZXLw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2020 00:38:17 -0700 IronPort-SDR: 1rEXtJMuvdkrWmA6k28YWcp6P3hqkvVZK8/QsWRLXlw21KcJ+8Rao1SctLUdR+R3kKn/2USR56 LbCri8J4ii1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,383,1583222400"; d="scan'208";a="340816099" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by orsmga001.jf.intel.com with ESMTP; 12 May 2020 00:38:16 -0700 From: "Huang\, Ying" To: Michal Hocko Cc: Andrew Morton , , , Minchan Kim , Tim Chen , Hugh Dickins Subject: Re: [PATCH] mm, swap: Use prandom_u32_max() References: <20200512064147.514493-1-ying.huang@intel.com> <20200512065049.GN29153@dhcp22.suse.cz> <875zd1pqu1.fsf@yhuang-dev.intel.com> <20200512073236.GQ29153@dhcp22.suse.cz> Date: Tue, 12 May 2020 15:38:15 +0800 In-Reply-To: <20200512073236.GQ29153@dhcp22.suse.cz> (Michal Hocko's message of "Tue, 12 May 2020 09:32:36 +0200") Message-ID: <87wo5hob6g.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Michal Hocko writes: > On Tue 12-05-20 15:14:46, Huang, Ying wrote: >> Michal Hocko writes: >> >> > 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? >> >> I am not expert on random number generator. I have heard about that the >> randomness of the low order bits of some random number generator isn't >> good enough. Anyway, by using the common implementation, the real >> random number generator expert can fix the possible issue once for all >> users. > > Please drop the quality argument if you cannot really justify it. This > will likely just confuse future readers the same way it confused me > here. Because prandom_u32_max uses the same source of randomness the > only difference is the way how modulo vs. u64 overflow arithmetic is > used for distributing values. I am not aware the later would be > a way to achieve a higher quality randomness. If the interval > distribution is better with the later then it would be great to have it > documented. OK. Fair enough. Best Regards, Huang, Ying >> >> Signed-off-by: "Huang, Ying" >> >> Cc: Michal Hocko >> >> Cc: Minchan Kim >> >> Cc: Tim Chen >> >> Cc: Hugh Dickins >> > >> > To the change itself >> > Acked-by: Michal Hocko >> >> Thanks! >> >> Best Regards, >> Huang, Ying >> >> >> --- >> >> 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