From patchwork Tue Mar 19 01:32:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Spelvin X-Patchwork-Id: 1263270 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sdf.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 48qPkp3R8Dz9sR4 for ; Sun, 29 Mar 2020 03:46:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727173AbgC1Qqj (ORCPT ); Sat, 28 Mar 2020 12:46:39 -0400 Received: from mx.sdf.org ([205.166.94.20]:50263 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726389AbgC1QnO (ORCPT ); Sat, 28 Mar 2020 12:43:14 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02SGh9lk016292 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:09 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGh9vH007105; Sat, 28 Mar 2020 16:43:09 GMT Message-Id: <202003281643.02SGh9vH007105@sdf.org> From: George Spelvin Date: Mon, 18 Mar 2019 21:32:20 -0400 Subject: [RFC PATCH v1 08/50] fs/ext4/ialloc.c: Replace % with reciprocal_scale() TO BE VERIFIED To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: "Theodore Ts'o" , Andreas Dilger , linux-ext4@vger.kernel.org Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This came about as part of auditing prandom_u32() usage, but this is a special case: sometimes the starting value comes from prandom_u32, and sometimes it comes from a hash of a name. Does the name hash algorithm have to be stable? In that case, this change would alter it. But it appears to use s_hash_seed which is regenerated on "e2fsck -D", so maybe changing it isn't a big deal. Feedback needed. Signed-off-by: George Spelvin Cc: "Theodore Ts'o" Cc: Andreas Dilger Cc: linux-ext4@vger.kernel.org Reviewed-by: Andreas Dilger --- fs/ext4/ialloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 7db0c8814f2ec..a4ea89b3ed368 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -457,9 +457,8 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, grp = hinfo.hash; } else grp = prandom_u32(); - parent_group = (unsigned)grp % ngroups; - for (i = 0; i < ngroups; i++) { - g = (parent_group + i) % ngroups; + g = parent_group = reciprocal_scale(grp, ngroups); + for (i = 0; i < ngroups; i++, ++g == ngroups && (g = 0)) { get_orlov_stats(sb, g, flex_size, &stats); if (!stats.free_inodes) continue;