From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jason A. Donenfeld via dev" Subject: Re: [f2fs-dev] [PATCH v1 3/5] treewide: use get_random_u32() when possible Date: Thu, 6 Oct 2022 06:33:15 -0600 Message-ID: References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> <20221006084331.4bdktc2zlvbaszym@quack3> Reply-To: "Jason A. Donenfeld" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 18BE86104C DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 210BB60F3D DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 1C547402BC DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 6C968402A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1665059607; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PDyor0OPorRMVekuFSJiAglRmrxBh1riIl1rICqIsks=; b=boaVkmFeWj/P/2mwQH9q1gX7LNlMIfDuuF/jF0E1iusdkGap18NZ9sMOKKXCenUfGu1kBs OsFuQiM99GfLC9GZQ0iQjPl+iTbCo2UXzxz3nN8lhLRAzO97rrmctM7VRTQNz+DRBcdhZZ cSGHfymmDp55cC4uDg3E8k04jFUD4XI= Content-Disposition: inline In-Reply-To: <20221006084331.4bdktc2zlvbaszym@quack3> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces-yBygre7rU0TnMu66kgdUjQ@public.gmane.org Sender: "dev" To: Jan Kara Cc: Andrew Lunn , "Darrick J . Wong" , linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Marcelo Ricardo Leitner , dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, Andrii Nakryiko , Hans Verkuil , linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Md . Haris Iqbal" , Miquel Raynal , Christoph Hellwig , Andy Gospodarek , Sergey Matyukevich , Rohit Maheshwari , Michael Ellerman , Christophe Leroy , Jozsef Kadlecsik , Nilesh Javali , Jean-Paul Roubelat , Dan Williams , Dick Kennedy , Jay Vosburgh , Potnuri Bharat Teja On Thu, Oct 06, 2022 at 10:43:31AM +0200, Jan Kara wrote: > The code here is effectively doing the > > parent_group = prandom_u32_max(ngroups); > > Similarly here we can use prandom_u32_max(ngroups) like: > > if (qstr) { > ... > parent_group = hinfo.hash % ngroups; > } else > parent_group = prandom_u32_max(ngroups); Nice catch. I'll move these to patch #1. > > diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c > > index 9af68a7ecdcf..588cb09c5291 100644 > > --- a/fs/ext4/mmp.c > > +++ b/fs/ext4/mmp.c > > @@ -265,7 +265,7 @@ static unsigned int mmp_new_seq(void) > > u32 new_seq; > > > > do { > > - new_seq = prandom_u32(); > > + new_seq = get_random_u32(); > > } while (new_seq > EXT4_MMP_SEQ_MAX); > > OK, here we again effectively implement prandom_u32_max(EXT4_MMP_SEQ_MAX + 1). > Just presumably we didn't want to use modulo here because EXT4_MMP_SEQ_MAX > is rather big and so the resulting 'new_seq' would be seriously > non-uniform. I'm not handling this during this patch set, but if in the course of review we find enough places that want actually uniformly bounded integers, I'll implement efficient rejection sampling to clean up these cases, with something faster and general, and add a new function for it. So far this is the first case to come up, but we'll probably eventually find others. So I'll make note of this. Jason