Re: make swappiness safer to use

Andrew Morton
2007-07-31T22:51:09Z

On Wed, 1 Aug 2007 00:40:52 +0200
Andrea Arcangeli <andrea@suse.de> wrote:

> > Want to see if we can present that expression in a more logical fashion, and
> > be more careful about the underflows and overflows, and fix the potential
> > divide-by-zero?
>
> I may be missing something,

Yeah, I misread the paranthesisation. sorry.

I nice way of coding this would be:

/*
* comment goes here
*/
adjust = zone_page_state(zone, NR_ACTIVE) /
(zone_page_state(zone, NR_INACTIVE) + 1);

/*
* comment goes here
*/
adjust *= (vm_swappiness + 1) / 100;

/*
* comment goes here
*/
adjust *= mapped_ratio / 100;

/*
* comment goes here
*/
swap_tendency += adjust;

so there's no confusion over parenthesisation or associativity, and the
reader can see the logic as it unfolds. The compiler should do exactly the
same thing.

It is worth expending the extra effort and screen space for clarity in that
part of the kernel, given the amount of trouble it causes, and the amount
of time people spend sweating over it. Those would want to be good
comments, too.