Re: Linux kernel, possible useless continue



Bin Chen wrote:
Below code I am curious in (A)'s continue will bring flow to (B) but
from (B) to (A) no code updates the value of both pfn and max_low_pfn.
So the condition of 'if' will always true. Is it useless?

Yes it is useless.

(B) for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
pmd = one_md_table_init(pgd);
if (pfn >= max_low_pfn)
(A) continue;
for (pmd_idx = 0;
pmd_idx < PTRS_PER_PMD && pfn < max_low_pfn;
pmd++, pmd_idx++) {
[...]
}
}

The if-comparison before (A) is the same as the second predicate for the
loop. The only thing this does additionally is set pmd_idx to zero, but if
that code relied on this side-effect of a loop variable it is broken
anyways and either needs to be rewritten or accurately documented.
However, it doesn't. Question is if the comparison in the loop is better
removed (i.e. if the comparison's outcome could change with an inner
iteration) or the outer.

Other than that, Iwo Mergler's comment that one_md_table_init() is called
with the next index indeed applies, and since max_low_pfn is not a local
variable to that function it could indeed be modified.


Uli

.



Relevant Pages

  • Re: Linux kernel, possible useless continue
    ... from to no code updates the value of both pfn and max_low_pfn. ... Yes it is useless. ... You removed an important part here, the inner loop: ...
    (comp.os.linux.development.system)
  • Re: [2.6.19 PATCH 1/7] ehea: interface to network stack
    ... > Useless cast. ... Not wrong per se but I'd rather move the label one line down. ... > Feels like a 0..4 loop is missing above. ... > Initialization and declaration can happen at the same time. ...
    (Linux-Kernel)
  • Re: measuring clock cycles per second
    ... In fact, I am not trying to convince you, I'm trying to find a reason why you would think it's useless. ... Let's assume that a program only executes a single loop and this loop ... Even if the average execution time of #1 is exactly 1/4 of the sampling interval and the average execution time of #2 is exactly 3/4 of the sampling interval, then, provided the standard deviation of the respective probability distributions of times is nonzero, the total time taken by the loop will, in general, be unequal to the sampling interval, even if by a mere 1%. ... Rather than the poor resolution, I find the fact that measurement itself leads to changes in timing more difficult to work with, especially when -g is used (not sure about the reason). ...
    (comp.os.linux.development.apps)
  • Re: How to create a limited set of instanceses of a class
    ... ainst being an extra reference to the instance ... Useless, gc.collectis synchronous *AND* only cleans up CYCLIC garbage ... loop because of unsatisfied condition - memory ... underscores instead of one, thus asking Python to name-mangle it to make ...
    (comp.lang.python)
  • Re: measuring clock cycles per second
    ... frequency makes it useless except on ancient hardware. ... Let's assume that a program only executes a single loop and this loop ... subroutine #1 is 1/4 of the sampling interval, the average execution ...
    (comp.os.linux.development.apps)