Re: [PATCH] mmtom: Prevent shrinking of active anon lru list in case of no swap space V3

From: Johannes Weiner
Date: Thu May 14 2009 - 12:24:49 EST


On Thu, May 14, 2009 at 11:39:49PM +0900, Minchan Kim wrote:
> On Thu, May 14, 2009 at 11:27 PM, KOSAKI Motohiro
> <kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
> >> Âmm/vmscan.c | Â Â2 +-
> >> Â1 files changed, 1 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/mm/vmscan.c b/mm/vmscan.c
> >> index 2f9d555..621708f 100644
> >> --- a/mm/vmscan.c
> >> +++ b/mm/vmscan.c
> >> @@ -1577,7 +1577,7 @@ static void shrink_zone(int priority, struct zone *zone,
> >> Â Â Â Â * Even if we did not try to evict anon pages at all, we want to
> >> Â Â Â Â * rebalance the anon lru active/inactive ratio.
> >> Â Â Â Â */
> >> - Â Â Â if (inactive_anon_is_low(zone, sc))
> >> + Â Â Â if (inactive_anon_is_low(zone, sc) && nr_swap_pages > 0)
> >> Â Â Â Â Â Â Â Âshrink_active_list(SWAP_CLUSTER_MAX, zone, sc, priority, 0);
> >
> >
> > Â Â Â if (nr_swap_pages > 0 && inactive_anon_is_low(zone, sc))
> >
> > is better?
> > compiler can't swap evaluate order around &&.
>
> If GCC optimizes away that branch with CONFIG_SWAP=n as Rik mentioned,
> we don't have a concern.

It can only optimize it away when the condition is a compile time
constant.

But inactive_anon_is_low() contains atomic operations which the
compiler is not allowed to drop and so the && semantics lead to

atomic_read() && 0

emitting the read while still knowing the whole expression is 0 at
compile-time, optimizing away only the branch itself but leaving the
read in place!

Compared to

0 && atomic_read()

where the && short-circuitry leads to atomic_read() not being
executed. And since the 0 is a compile time constant, no code has to
be emitted for the read.

So KOSAKI-san's is right. Your version results in bigger object code.

Hannes
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/