Re: [PATCH] make __section_nr more efficient

From: Dave Hansen
Date: Wed Jul 20 2016 - 17:36:11 EST


On 07/19/2016 09:18 PM, Zhou Chengming wrote:
> When CONFIG_SPARSEMEM_EXTREME is disabled, __section_nr can get
> the section number with a subtraction directly.

Does this actually *do* anything?

It was a long time ago, but if I remember correctly, the entire loop in
__section_nr() goes away because root_nr==NR_SECTION_ROOTS, so
root_nr=1, and the compiler optimizes away the entire subtraction.

So this basically adds an #ifdef and gets us nothing, although it makes
the situation much more explicit. Perhaps the comment should say that
this works *and* is efficient because the compiler can optimize all the
extreme complexity away.