Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1175235ybb; Sat, 28 Mar 2020 21:02:42 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt8nM1XAD9WmIr06kMJUJx+5lN/ANIqQ1o4mraXdvCAt8NPoUkrIPdXMFpefxLky9S/vK9R X-Received: by 2002:aca:3196:: with SMTP id x144mr3996627oix.77.1585454562287; Sat, 28 Mar 2020 21:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585454562; cv=none; d=google.com; s=arc-20160816; b=L5FleoCQWl/OseH2G0hwiwNAoJwULxDvUhCVAkMnzuGJxQA+436yDZzW4IMs78cAmy 2PzqnceNld1W0wsZOsVMGmsZP5FKW1M3sPYmWG4OQ76TrcidhtnBiPIxrFk7PcahaaEo nWrzXbliOPZ2U33XeJz2W4RQAJCveRSR0qpIJxnw5MW+o2eSS+xfmTEQU+0K593Spjqx 9NGNGM2VHCqfb676y2WIuZWAXbvxy8+N++GmgRTgAev6/sCRV418YTFC8FTLdW2/Na4C lXpfP8LWDDNUArKuVwCQNQBMeBw6SdvzD7ozmDxQcxz42XooGPfpOM67d+JvLZZKU02Q 41lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=TvWZkwbSr5AGEw1CQvfz96Onvxts/TVNHShqo6hbDQo=; b=ElJ8I/pT3XjhEUwP6Uscw/k3QT3WHN1oBGzpRR6RrYgxMiIrkizOnJxZ5MNPS13jx+ JPnz3CrIZaODk8ZahjOWH7SQa7TzcnmirYSC1lXw+2qXj7hsavOMZ1WCA2b4MWuHVPhT 5arcA+BH2YGokLjkn/u/8bykFAhsbz/qacnV6O+cIxkug3fzY90G+kOAOnA0FEkZjDkV qMMJhbKz6SL2Zs02r+ETj0R3GgkO2gHnMjlunIQftIAbAbTUmiCUZ/t1g2L5lfZh0Xn7 N7ZRyL+zZxXZYGYOL812Mm3vZ0Wu1yY8NwPsvOuN2nYh+sO3ZLGmcw8N8g/SVSOWuYMZ YSAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 184si4079774oig.33.2020.03.28.21.02.18; Sat, 28 Mar 2020 21:02:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725813AbgC2EAQ (ORCPT + 99 others); Sun, 29 Mar 2020 00:00:16 -0400 Received: from mx.sdf.org ([205.166.94.20]:52679 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725379AbgC2EAQ (ORCPT ); Sun, 29 Mar 2020 00:00:16 -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 02T40C6E028586 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sun, 29 Mar 2020 04:00:13 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02T40CNt013009; Sun, 29 Mar 2020 04:00:12 GMT Date: Sun, 29 Mar 2020 04:00:12 +0000 From: George Spelvin To: Andreas Dilger Cc: Linux Kernel Mailing List , "Theodore Ts'o" , linux-ext4 , lkml@sdf.org Subject: Re: [RFC PATCH v1 08/50] fs/ext4/ialloc.c: Replace % with reciprocal_scale() TO BE VERIFIED Message-ID: <20200329040012.GB11951@SDF.ORG> References: <202003281643.02SGh9vH007105@sdf.org> <9A60C390-349E-4A90-A812-F04EB5A82136@dilger.ca> <20200328231536.GA11951@SDF.ORG> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sat, Mar 28, 2020 at 06:10:11PM -0600, Andreas Dilger wrote: > On Mar 28, 2020, at 5:15 PM, George Spelvin wrote: >> Also, we could, if desired, eliminate the i variable entirely >> using the fact that we have a copy of the starting position cached >> in parent_group. I.e. >> >> g = parent_group = reciprocal_scale(grp, ngroups); >> - for (i = 0; i < ngroups; i++, ++g == ngroups && (g = 0)) { >> + do { >> ... >> - } >> + if (++g == ngroups) >> + g = 0; >> + } while (g != parent_group); > I was looking at whether we could use a for-loop without "i"? Something like: > > for (g = parent_group + 1; g != parent_group; ++g >= ngroups && (g = 0)) > > The initial group is parent_group + 1, to avoid special-casing when the > initial parent_group = 0 (which would prevent the loop from terminating). That's the first option I presented, above. Since a for() loop tests before each iteration, if the counter is strictly modulo ngroups, there's no way to execute the loop body more than ngroups-1 times. That's why I changed to do{}while(), which has a minimum of 1 (it can't handle ngroups == 0), but can mimic the current loop's execution perfectly (no initial +1 offset).