linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Andrea Arcangeli <andrea@suse.de>
Cc: linux-mm@kvack.org, Nick Piggin <npiggin@suse.de>
Subject: Re: make swappiness safer to use
Date: Tue, 31 Jul 2007 15:12:44 -0700	[thread overview]
Message-ID: <20070731151244.3395038e.akpm@linux-foundation.org> (raw)
In-Reply-To: <20070731215228.GU6910@v2.random>

On Tue, 31 Jul 2007 23:52:28 +0200
Andrea Arcangeli <andrea@suse.de> wrote:

> +		swap_tendency += zone_page_state(zone, NR_ACTIVE) /
> +			(zone_page_state(zone, NR_INACTIVE) + 1)
> +			* (vm_swappiness + 1) / 100
> +			* mapped_ratio / 100;

I must say, that's a pretty ugly-looking statement.  For a start, the clause

			* (vm_swappiness + 1) / 100

always evaluates to zero.  The L->R associativity prevents that, but the
layout is super-misleading, no?

And it matters - the potential for overflow and rounding errors here is
considerable.  Let's go through it.  Probably 32-bit is the problem.


	zone_page_state(zone, NR_ACTIVE) /

	0 -> 8,000,000

		(zone_page_state(zone, NR_INACTIVE) + 1)

min: 1, max: 8,000,000

		* (vm_swappiness + 1)

min: 1, max: 101

total min: 1, total max: 800,000,000

	/ 100


total min: 0, total max: 8,000,000

		* mapped_ratio

total min: 0, total max: 800,000,000

		/ 100;

total min: 0, total max: 8,000,000

then we divide zone_page_state(zone, NR_ACTIVE) by this value.

We can get a divide-by-zero if zone_page_state(zone, NR_INACTIVE) is
sufficiently small, I think?  At least, it isn't obvious that we cannot.

I suspect that we can get a value >100, too.  Especially when we add it to
the existing value of swap_tendency, but I didn't think about it too hard.

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?

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2007-07-31 22:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-31 21:52 Andrea Arcangeli
2007-07-31 22:12 ` Andrew Morton [this message]
2007-07-31 22:40   ` Andrea Arcangeli
2007-07-31 22:51     ` Andrew Morton
2007-07-31 23:02       ` Andrea Arcangeli
     [not found]         ` <20070801011925.GB20109@mail.ustc.edu.cn>
2007-08-01  1:19           ` Fengguang Wu
     [not found]           ` <20070801012222.GA20565@mail.ustc.edu.cn>
2007-08-01  1:22             ` Fengguang Wu
     [not found]             ` <20070801013208.GA20085@mail.ustc.edu.cn>
2007-08-01  1:32               ` Fengguang Wu
2007-08-01  2:33               ` Andrea Arcangeli
2007-08-06 18:21                 ` Andrew Morton
     [not found]                   ` <20070807050032.GA16179@mail.ustc.edu.cn>
2007-08-07  5:00                     ` Fengguang Wu
2007-11-12  2:07                     ` YAMAMOTO Takashi
2007-08-01  2:30           ` Andrea Arcangeli
2007-07-31 23:09 ` Andrew Morton
2007-07-31 23:23   ` Andrea Arcangeli
2007-07-31 23:32   ` Martin Bligh
2007-07-31 23:49     ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070731151244.3395038e.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andrea@suse.de \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox