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=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 1E197C54E4B for ; Tue, 12 May 2020 07:32:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE011206B7 for ; Tue, 12 May 2020 07:32:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE011206B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5084690009C; Tue, 12 May 2020 03:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B94F900036; Tue, 12 May 2020 03:32:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A77290009C; Tue, 12 May 2020 03:32:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 1F3DF900036 for ; Tue, 12 May 2020 03:32:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D5002180AD811 for ; Tue, 12 May 2020 07:32:39 +0000 (UTC) X-FDA: 76807249638.25.ink68_6e876a031523e X-HE-Tag: ink68_6e876a031523e X-Filterd-Recvd-Size: 4730 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 May 2020 07:32:39 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id l17so472193wrr.4 for ; Tue, 12 May 2020 00:32:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rjR0xAaaRoHPNCmqXbAIef0LNkXJSTuZB54tpgVRD5I=; b=G3BI0ncw8g0IFK1fbAr9MSiuJIDiPGtfg3krKRNseI7pFwlYDCPRvS4GZkMaNy4tpG ZKE/TecRF7BnGO/CB2/uHNNZbcHNv0vOIhVKLMt2dJ+a3RJQ2S/ODlDTKhQW/3xbOWu9 ptYRRlz/r8nVhH5pPROhx/+Qzwx+nr0chY+a4yQpccOH3L22zZ4DBDXUJoxC2EVTkX8D 5vES3kGmqhB01TLP0dr7FyY5r+eSiD7rMgqhliumAMr1qo7loHGCFzYAa39eUIINFsAM Dc7eYJA8kVukkPL0FmQGLNmNWkgX5o23UgjOfk8caRtfE0ygLLs6YM58oXKd75jrNcWB XZHw== X-Gm-Message-State: AGi0PuZPHI7S0p744oVbuIRXDwvLdKfcKLFOd/mbpVVHcpwzEAEx5y8X IWl1TL3Z9gcb7u5kJ8PNscZDalgD X-Google-Smtp-Source: APiQypLQZqtnJSFzH38WJbvuO0r2ggsc2I3KPEMHsxbCyIRP9qoAd4tmtHbEOkaztWDe6d+0TdgOvg== X-Received: by 2002:adf:a74b:: with SMTP id e11mr21891062wrd.99.1589268758442; Tue, 12 May 2020 00:32:38 -0700 (PDT) Received: from localhost (ip-37-188-140-86.eurotel.cz. [37.188.140.86]) by smtp.gmail.com with ESMTPSA id m3sm5751648wrn.96.2020.05.12.00.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 00:32:37 -0700 (PDT) Date: Tue, 12 May 2020 09:32:36 +0200 From: Michal Hocko To: "Huang, Ying" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Tim Chen , Hugh Dickins Subject: Re: [PATCH] mm, swap: Use prandom_u32_max() Message-ID: <20200512073236.GQ29153@dhcp22.suse.cz> References: <20200512064147.514493-1-ying.huang@intel.com> <20200512065049.GN29153@dhcp22.suse.cz> <875zd1pqu1.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875zd1pqu1.fsf@yhuang-dev.intel.com> 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: 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. > >> 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 -- Michal Hocko SUSE Labs