2010-07-09 06:52:56

by KOSAKI Motohiro

[permalink] [raw]
Subject: [PATCH] vmscan: protect to read reclaim_stat by lru_lock

Rik van Riel pointed out reading reclaim_stat should be protected
lru_lock, otherwise vmscan might sweep 2x much pages.

This fault was introduced by followint commit.

commit 4f98a2fee8acdb4ac84545df98cccecfd130f8db
Author: Rik van Riel <[email protected]>
Date: Sat Oct 18 20:26:32 2008 -0700

vmscan: split LRU lists into anon & file sets

Split the LRU lists in two, one set for pages that are backed by real file
systems ("file") and one for pages that are backed by memory and swap
("anon"). The latter includes tmpfs.

The advantage of doing this is that the VM will not have to scan over lots
of anonymous pages (which we generally do not want to swap out), just to
find the page cache pages that it should evict.

This patch has the infrastructure and a basic policy to balance how much
we scan the anon lists and how much we scan the file lists. The big
policy changes are in separate patches.

Cc: Rik van Riel <[email protected]>
Cc: Minchan Kim <[email protected]>
Signed-off-by: KOSAKI Motohiro <[email protected]>
---
mm/vmscan.c | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 0f9f624..5a377e6 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1581,6 +1581,13 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
}

/*
+ * With swappiness at 100, anonymous and file have the same priority.
+ * This scanning priority is essentially the inverse of IO cost.
+ */
+ anon_prio = sc->swappiness;
+ file_prio = 200 - sc->swappiness;
+
+ /*
* OK, so we have swap space and a fair amount of page cache
* pages. We use the recently rotated / recently scanned
* ratios to determine how valuable each cache is.
@@ -1591,28 +1598,18 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,
*
* anon in [0], file in [1]
*/
+ spin_lock_irq(&zone->lru_lock);
if (unlikely(reclaim_stat->recent_scanned[0] > anon / 4)) {
- spin_lock_irq(&zone->lru_lock);
reclaim_stat->recent_scanned[0] /= 2;
reclaim_stat->recent_rotated[0] /= 2;
- spin_unlock_irq(&zone->lru_lock);
}

if (unlikely(reclaim_stat->recent_scanned[1] > file / 4)) {
- spin_lock_irq(&zone->lru_lock);
reclaim_stat->recent_scanned[1] /= 2;
reclaim_stat->recent_rotated[1] /= 2;
- spin_unlock_irq(&zone->lru_lock);
}

/*
- * With swappiness at 100, anonymous and file have the same priority.
- * This scanning priority is essentially the inverse of IO cost.
- */
- anon_prio = sc->swappiness;
- file_prio = 200 - sc->swappiness;
-
- /*
* The amount of pressure on anon vs file pages is inversely
* proportional to the fraction of recently scanned pages on
* each list that were recently referenced and in active use.
@@ -1622,6 +1619,7 @@ static void get_scan_count(struct zone *zone, struct scan_control *sc,

fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
fp /= reclaim_stat->recent_rotated[1] + 1;
+ spin_unlock_irq(&zone->lru_lock);

fraction[0] = ap;
fraction[1] = fp;
--
1.6.5.2



2010-07-09 08:26:06

by Minchan Kim

[permalink] [raw]
Subject: Re: [PATCH] vmscan: protect to read reclaim_stat by lru_lock

On Fri, Jul 9, 2010 at 3:52 PM, KOSAKI Motohiro
<[email protected]> wrote:
> Rik van Riel pointed out reading reclaim_stat should be protected
> lru_lock, otherwise vmscan might sweep 2x much pages.
>
> This fault was introduced by followint commit.
>
> ?commit 4f98a2fee8acdb4ac84545df98cccecfd130f8db
> ?Author: Rik van Riel <[email protected]>
> ?Date: ? Sat Oct 18 20:26:32 2008 -0700
>
> ? ?vmscan: split LRU lists into anon & file sets
>
> ? ?Split the LRU lists in two, one set for pages that are backed by real file
> ? ?systems ("file") and one for pages that are backed by memory and swap
> ? ?("anon"). ?The latter includes tmpfs.
>
> ? ?The advantage of doing this is that the VM will not have to scan over lots
> ? ?of anonymous pages (which we generally do not want to swap out), just to
> ? ?find the page cache pages that it should evict.
>
> ? ?This patch has the infrastructure and a basic policy to balance how much
> ? ?we scan the anon lists and how much we scan the file lists. ?The big
> ? ?policy changes are in separate patches.
>
> Cc: Rik van Riel <[email protected]>
> Cc: Minchan Kim <[email protected]>
> Signed-off-by: KOSAKI Motohiro <[email protected]>
Reviewed-by: Minchan Kim <[email protected]>

Thanks, Kosaki. I have forgotten this issue.

--
Kind regards,
Minchan Kim