lkml.org 
[lkml]   [2020]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH v1 08/50] fs/ext4/ialloc.c: Replace % with reciprocal_scale() TO BE VERIFIED
On Sat, Mar 28, 2020 at 06:10:11PM -0600, Andreas Dilger wrote:
> On Mar 28, 2020, at 5:15 PM, George Spelvin <lkml@SDF.ORG> 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).

\
 
 \ /
  Last update: 2020-03-29 06:00    [W:0.075 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site