From: Andreas Dilger <adilger@dilger.ca>
To: George Spelvin <lkml@SDF.ORG>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Theodore Ts'o <tytso@mit.edu>,
linux-ext4 <linux-ext4@vger.kernel.org>
Subject: Re: [RFC PATCH v1 08/50] fs/ext4/ialloc.c: Replace % with reciprocal_scale() TO BE VERIFIED
Date: Sat, 28 Mar 2020 18:10:11 -0600 [thread overview]
Message-ID: <EC88E8EB-7303-45FB-85B9-A007FBE5F5A0@dilger.ca> (raw)
In-Reply-To: <20200328231536.GA11951@SDF.ORG>
[-- Attachment #1: Type: text/plain, Size: 1870 bytes --]
On Mar 28, 2020, at 5:15 PM, George Spelvin <lkml@SDF.ORG> wrote:
>
> On Sat, Mar 28, 2020 at 04:56:17PM -0600, Andreas Dilger wrote:
>>
>> So I think the current patch is fine. The for-loop construct of
>> using "++g == ngroups && (g = 0)" to wrap "g" around is new to me,
>> but looks correct.
>>
>> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
>
> Thank you. Standing back and looking from higher altitude, I missed
> a second modulo at fallback_retry: which should be made consistent,
> so I need a one re-spin.
>
> 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);
>
> Or perhaps the following would be simpler, replacing the modulo
> with a conditional subtract:
>
> - g = parent_group = reciprocal_scale(grp, ngroups);
> + parent_group = reciprocal_scale(grp, ngroups);
> - for (i = 0; i < ngroups; i++, ++g == ngroups && (g = 0)) {
> + for (i = 0; i < ngroups; i++) {
> + g = parent_group + i;
> + if (g >= ngroups)
> + g -= ngroups;
>
> The conditional branch starts out always false, and ends up always true,
> but except for a few bobbles when it switches, branch prediction should
> handle it very well.
>
> Any preference?
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).
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
next prev parent reply other threads:[~2020-03-29 0:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 1:32 [RFC PATCH v1 08/50] fs/ext4/ialloc.c: Replace % with reciprocal_scale() TO BE VERIFIED George Spelvin
2020-03-28 22:56 ` Andreas Dilger
2020-03-28 23:15 ` George Spelvin
2020-03-29 0:10 ` Andreas Dilger [this message]
2020-03-29 4:00 ` George Spelvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EC88E8EB-7303-45FB-85B9-A007FBE5F5A0@dilger.ca \
--to=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkml@SDF.ORG \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).