Skip to contentSkip to conversation

vmscan: handle underflow for get_scan_ratio

PATCH In review Shaohua Li 7 participants 49 messages Mar 30, 2010 – Apr 15, 2010

Subsystems (3)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 vmscan: handle underflow for get_scan_ratio

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

mm/vmscan.c +12 -0
index 79c8098..d5cc34e 100644
@@ -1604,6 +1604,18 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	/* Normalize to percentages */
 	percent[0] = 100 * ap / (ap + fp + 1);
 	percent[1] = 100 - percent[0];
+	/*
+	 * if percent[x] is small and rounded to 0, this case doesn't mean we
+	 * should skip scan. Give it at least 1% share.
+	 */
+	if (percent[0] == 0) {
+		percent[0] = 1;
+		percent[1] = 99;
+	}
+	if (percent[1] == 0) {
+		percent[0] = 99;
+		percent[1] = 1;
+	}
 }
 
 /*

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

#1 lore raw

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

author
#2 lore raw
Quoted 13 lines · KOSAKI Motohiro

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 1 line

Can you please post your /proc/meminfo

attached.

Quoted 1 line

and reproduce program? I'll digg it.

our test is quite sample. mount tmpfs with double memory size and store several copies (memory size * 2/G) of kernel in tmpfs, and then do kernel build. for example, there is 3G memory and then tmpfs size is 6G and there is 6 kernel copy.

Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

can you elaborate this?
Completely restore previous behavior (do full scan with priority 0) is ok too.

MemTotal:        3078372 kB
MemFree:           34612 kB
Buffers:             960 kB
Cached:          2577644 kB
SwapCached:        24580 kB
Active:          2125712 kB
Inactive:         541972 kB
Active(anon):    2120276 kB
Inactive(anon):   534696 kB
Active(file):       5436 kB
Inactive(file):     7276 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       6297472 kB
SwapFree:        6184988 kB
Dirty:              1720 kB
Writeback:         24024 kB
AnonPages:         64888 kB
Mapped:             3996 kB
Shmem:           2566004 kB
Slab:             290416 kB
SReclaimable:     113840 kB
SUnreclaim:       176576 kB
KernelStack:        3072 kB
PageTables:         6832 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     7836656 kB
Committed_AS:    2811564 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      289724 kB
VmallocChunk:   34359444080 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       10240 kB
DirectMap2M:     3127296 kB
#3 lore raw
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 7 lines
Quoted 1 line

Can you please post your /proc/meminfo

attached.

Quoted 1 line

and reproduce program? I'll digg it.

our test is quite sample. mount tmpfs with double memory size and store several copies (memory size * 2/G) of kernel in tmpfs, and then do kernel build. for example, there is 3G memory and then tmpfs size is 6G and there is 6 kernel copy.

Wow, tmpfs size > memsize!

Quoted 5 lines
Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

can you elaborate this?
Completely restore previous behavior (do full scan with priority 0) is ok too.

This is a option. but we need to know the root cause anyway. if not, we might reintroduce this issue again in the future.

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

author
#4 lore raw
Quoted 25 lines · KOSAKI Motohiro
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 7 lines
Quoted 1 line

Can you please post your /proc/meminfo

attached.

Quoted 1 line

and reproduce program? I'll digg it.

our test is quite sample. mount tmpfs with double memory size and store several copies (memory size * 2/G) of kernel in tmpfs, and then do kernel build. for example, there is 3G memory and then tmpfs size is 6G and there is 6 kernel copy.

Wow, tmpfs size > memsize!

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

can you elaborate this?
Completely restore previous behavior (do full scan with priority 0) is ok too.

This is a option. but we need to know the root cause anyway.

I thought I mentioned the root cause in first mail. My debug shows recent_rotated[0] is big, but recent_rotated[1] is almost zero, which makes percent[0] 0. But you can double check too.

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

#5 lore raw
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

can you elaborate this?
Completely restore previous behavior (do full scan with priority 0) is ok too.

This is a option. but we need to know the root cause anyway.

I thought I mentioned the root cause in first mail. My debug shows recent_rotated[0] is big, but recent_rotated[1] is almost zero, which makes percent[0] 0. But you can double check too.

To revert can save percent[0]==0 && priority==0 case. but it shouldn't happen, I think. It mean to happen big latency issue.

Can you please try following patch? Also, I'll prepare reproduce environment soon.

---
 mm/vmscan.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
mm/vmscan.c +8 -4
index 79c8098..abf7f79 100644
@@ -1571,15 +1571,19 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	 */
 	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;
+		while (reclaim_stat->recent_scanned[0] > anon / 4) {
+			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;
+		while (reclaim_stat->recent_scanned[1] > file / 4) {
+			reclaim_stat->recent_scanned[1] /= 2;
+			reclaim_stat->recent_rotated[1] /= 2;
+		}
 		spin_unlock_irq(&zone->lru_lock);
 	}
 
Signature · 11 lines
1.6.5.2





--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#6 lore raw
Quoted 7 lines · KOSAKI Motohiro
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

can you elaborate this?
Completely restore previous behavior (do full scan with priority 0) is ok too.

This is a option. but we need to know the root cause anyway.

Quoted 8 lines
Quoted 3 lines

I thought I mentioned the root cause in first mail. My debug shows recent_rotated[0] is big, but recent_rotated[1] is almost zero, which makes percent[0] 0. But you can double check too.

To revert can save percent[0]==0 && priority==0 case. but it shouldn't happen, I think. It mean to happen big latency issue.

Can you please try following patch? Also, I'll prepare reproduce environment soon.

still oom with the patch.

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

#46 lore raw
In reply to Shaohua Li
Quoted 27 lines · Shaohua Li

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

mm/vmscan.c +5 -0
index 79c8098..d5cc34e 100644
@@ -1604,6 +1604,18 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
        /* Normalize to percentages */
        percent[0] = 100 * ap / (ap + fp + 1);
        percent[1] = 100 - percent[0];
+       /*
+        * if percent[x] is small and rounded to 0, this case doesn't mean we
+        * should skip scan. Give it at least 1% share.
+        */
+       if (percent[0] == 0) {

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1621

Quoted 10 lines
mm/vmscan.c +7 -0
+               percent[0] = 1;
+               percent[1] = 99;
+       }
+       if (percent[1] == 0) {
+               percent[0] = 99;
+               percent[1] = 1;
+       }
  }
 
  /*

Yes. It made subtle change.
But we should not depend that change.
Current logic seems to be good and clear than old.
I think you were lucky at that time by not-good and not-clear logic.

BTW, How about this?

mm/vmscan.c +0 -5
index 79c8098..f0df563 100644
@@ -1646,11 +1646,6 @@ static void shrink_zone(int priority, struct zone *zone,
                int file = is_file_lru(l);
                unsigned long scan;
 
-               if (percent[file] == 0) {
-                       nr[l] = 0;
-                       continue;
-               }
-
                scan = zone_nr_lru_pages(zone, sc, l);
                if (priority) {
                        scan >>= priority;
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#47 lore raw
Quoted 6 lines

Yes. It made subtle change.
But we should not depend that change.
Current logic seems to be good and clear than old.
I think you were lucky at that time by not-good and not-clear logic.

BTW, How about this?

Unfortunatelly, memcg need your removed code. if removed, swapping out might happen although sc->may_swap==0 when priority==0.

Please give me little investigate time.

Quoted 29 lines
mm/vmscan.c +0 -5
index 79c8098..f0df563 100644
@@ -1646,11 +1646,6 @@ static void shrink_zone(int priority, struct zone *zone,
                int file = is_file_lru(l);
                unsigned long scan;
 
-               if (percent[file] == 0) {
-                       nr[l] = 0;
-                       continue;
-               }
-
                scan = zone_nr_lru_pages(zone, sc, l);
                if (priority) {
                        scan >>= priority;
Signature · 9 lines
-- 
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a hrefmailto:"[email protected]"> [email protected] </a>

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

#48 lore raw
In reply to Shaohua Li
Quoted 25 lines · Shaohua Li

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

mm/vmscan.c +4 -0
index 79c8098..d5cc34e 100644
@@ -1604,6 +1604,18 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
        /* Normalize to percentages */
        percent[0] = 100 * ap / (ap + fp + 1);
        percent[1] = 100 - percent[0];
+       /*
+        * if percent[x] is small and rounded to 0, this case doesn't mean we
+        * should skip scan. Give it at least 1% share.
+        */

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1620

Quoted 10 lines
mm/vmscan.c +8 -0
+       if (percent[0] == 0) {
+               percent[0] = 1;
+               percent[1] = 99;
+       }
+       if (percent[1] == 0) {
+               percent[0] = 99;
+               percent[1] = 1;
+       }
  }
 

Can you please post the meminfo before and after the changes (diff maybe?). Can you also please share the ap and fp data from which the percent figures are being calculated Is your swappiness set to 60? Can you please share the OOM/panic message as well.

Balbir

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

author
#7 lore raw
In reply to KOSAKI Motohiro
Quoted 13 lines · KOSAKI Motohiro

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned.

mm/vmscan.c +56 -51
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

#8 lore raw
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 5 lines
Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

Quoted 170 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned.

mm/vmscan.c +56 -51
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {
#45 lore raw
In reply to Shaohua Li
Quoted 20 lines · Shaohua
Quoted 13 lines · KOSAKI Motohiro

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

Quoted 7 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned.

The changelog can be improved. For example, to describe these items in separate paragraphs:

- the behavior change introduced by 84b18490d1f (which claims to be cleanup)
- the tmpfs test case
- the root cause
- the solution
- test result

Quoted 28 lines
mm/vmscan.c +18 -0
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}

mm/vmscan.c static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, · line 1547

Quoted 10 lines
mm/vmscan.c +3 -2
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned

typo: scanned

mm/vmscan.c static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, · line 1556

Quoted 11 lines
mm/vmscan.c +3 -2
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];

The denominator is shared, so one scaler would be sufficient. Also ap, fp can be removed and to use fraction[] directly.

And it's better to retain this comment:

                                        /* anon @ 0; file @ 1 */
Quoted 63 lines
mm/vmscan.c +19 -25
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1647

Quoted 10 lines
mm/vmscan.c +8 -1
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);
			scan = (scan * fraction[file]) / denominator[file];

Thanks,
Fengguang

Quoted 30 lines
mm/vmscan.c +4 -15
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {

mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1669

Quoted 10 lines
mm/vmscan.c +1 -6
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

#9 lore raw
In reply to KOSAKI Motohiro

KOSAKI-san,

Quoted 18 lines · KOSAKI Motohiro
Quoted 18 lines · KOSAKI Motohiro
Quoted 17 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

Quoted 8 lines
Quoted 1 line

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

I tend to regard this patch as a general improvement for both .33-stable and .34.

I do agree with you that it's desirable to do more test&analyze and check further for possibly hidden problems.

Thanks,
Fengguang

Quoted 170 lines
Quoted 170 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned.

mm/vmscan.c +56 -51
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
Quoted 4 lines

mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1669

Quoted 2 lines
mm/vmscan.c +0 -0
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

#16 lore raw
In reply to KOSAKI Motohiro
Quoted 16 lines
Quoted 16 lines · KOSAKI Motohiro
Quoted 15 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Anyway, I'm digging this issue.

Quoted 3 lines

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

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

#10 lore raw
In reply to Wu Fengguang
Quoted 27 lines

KOSAKI-san,

Quoted 24 lines · KOSAKI Motohiro
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 5 lines
Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Quoted 8 lines
Quoted 2 lines

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

I tend to regard this patch as a general improvement for both .33-stable and .34.

I do agree with you that it's desirable to do more test&analyze and check further for possibly hidden problems.

Yeah, I don't want ignore .33-stable too. if I can't find the root cause in 2-3 days, I'll revert guilty patch anyway.

#11 lore raw
Quoted 30 lines · KOSAKI Motohiro
Quoted 30 lines

KOSAKI-san,

Quoted 26 lines · KOSAKI Motohiro
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 5 lines
Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

Quoted 8 lines
Quoted 5 lines

I tend to regard this patch as a general improvement for both .33-stable and .34.

I do agree with you that it's desirable to do more test&analyze and check further for possibly hidden problems.

Yeah, I don't want ignore .33-stable too. if I can't find the root cause in 2-3 days, I'll revert guilty patch anyway.

OK, thank you!

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

maintainer
#12 lore raw
In reply to KOSAKI Motohiro
Quoted 30 lines · On Wed, 31 Mar 2010 15:00:52 +0900 (JST) KOSAKI Motohiro…
Quoted 30 lines

KOSAKI-san,

Quoted 26 lines · KOSAKI Motohiro
Quoted 14 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 5 lines
Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

perhaps I'll take your patch for stable tree. but we need to attack the root cause. iow, I guess we need to fix scan ratio equation itself.

Quoted 9 lines
Quoted 5 lines

I tend to regard this patch as a general improvement for both .33-stable and .34.

I do agree with you that it's desirable to do more test&analyze and check further for possibly hidden problems.

Yeah, I don't want ignore .33-stable too. if I can't find the root cause in 2-3 days, I'll revert guilty patch anyway.

It's a good idea to avoid fixing a bug one-way-in-stable, other-way-in-mainline. Because then we have new code in both trees which is different. And the -stable guys sensibly like to see code get a bit of a shakedown in mainline before backporting it.

So it would be better to merge the "simple" patch into mainline, tagged for -stable backporting. Then we can later implement the larger fix in mainline, perhaps starting by reverting the "simple" fix.

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

author
#17 lore raw
In reply to KOSAKI Motohiro
Quoted 20 lines · KOSAKI Motohiro
Quoted 20 lines
Quoted 19 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Commit 84b18490d introduces a regression. With it, our tmpfs test always oom. The test uses a 6G tmpfs in a system with 3G memory. In the tmpfs, there are 6 copies of kernel source and the test does kbuild for each copy. My investigation shows the test has a lot of rotated anon pages and quite few file pages, so get_scan_ratio calculates percent[0] to be zero. Actually the percent[0] shoule be a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scan pages for < 1% percent. With this fix, my test doesn't oom any more.

Note, this patch doesn't really change logics, but just increase precise. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will say one anon page swapped. The 16G is calculated as PAGE_SIZE * priority(4096) * (fp/ap). fp/ap is assumed to be 1024 which is common in this workload. So the impact sounds not a big deal.

mm/vmscan.c +56 -51
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

#13 lore raw
In reply to Andrew Morton
Quoted 4 lines
Quoted 3 lines

Yeah, I don't want ignore .33-stable too. if I can't find the root cause in 2-3 days, I'll revert guilty patch anyway.

Quoted 8 lines

It's a good idea to avoid fixing a bug one-way-in-stable, other-way-in-mainline. Because then we have new code in both trees which is different. And the -stable guys sensibly like to see code get a bit of a shakedown in mainline before backporting it.

So it would be better to merge the "simple" patch into mainline, tagged for -stable backporting. Then we can later implement the larger fix in mainline, perhaps starting by reverting the "simple" fix.

.....ok. I don't have to prevent your code maintainship. although I still think we need to fix the issue completely.

===================================================================
From 52358cbccdfe94e0381974cd6e937bcc6b1c608b Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Fri, 2 Apr 2010 17:13:48 +0900
Subject: [PATCH] Revert "vmscan: get_scan_ratio() cleanup"

Shaohua Li reported his tmpfs streaming I/O test can lead to make oom. The test uses a 6G tmpfs in a system with 3G memory. In the tmpfs, there are 6 copies of kernel source and the test does kbuild for each copy. His investigation shows the test has a lot of rotated anon pages and quite few file pages, so get_scan_ratio calculates percent[0] (i.e. scanning percent for anon) to be zero. Actually the percent[0] shoule be a big value, but our calculation round it to zero.

Although before commit 84b18490, we have the same sick too. but the old logic can rescue percent[0]==0 case only when priority==0. It had hided the real issue. I didn't think merely streaming io can makes percent[0]==0 && priority==0 situation. but I was wrong.

So, definitely we have to fix such tmpfs streaming io issue. but anyway I revert the regression commit at first.

This reverts commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26.

---
 mm/vmscan.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)
mm/vmscan.c +9 -14
index 79c8098..cb3947e 100644
@@ -1535,13 +1535,6 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
 
-	/* If we have no swap space, do not bother scanning anon pages. */
-	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
-	}
-
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
 		zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON);
 	file  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_FILE) +
@@ -1639,20 +1632,22 @@ static void shrink_zone(int priority, struct zone *zone,
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	int noswap = 0;
 
-	get_scan_ratio(zone, sc, percent);
+	/* If we have no swap space, do not bother scanning anon pages. */
+	if (!sc->may_swap || (nr_swap_pages <= 0)) {
+		noswap = 1;
+		percent[0] = 0;
+		percent[1] = 100;
+	} else
+		get_scan_ratio(zone, sc, percent);
 
 	for_each_evictable_lru(l) {
 		int file = is_file_lru(l);
 		unsigned long scan;
 
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
 		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {
+		if (priority || noswap) {
 			scan >>= priority;
 			scan = (scan * percent[file]) / 100;
 		}
Signature · 11 lines
1.6.5.2





--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw
In reply to Shaohua Li
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

thanks.

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

author
#19 lore raw
Quoted 8 lines · KOSAKI Motohiro
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Quoted 8 lines
Quoted 3 lines

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

Thanks,
Shaohua

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

#20 lore raw
Quoted 13 lines · KOSAKI Motohiro
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Quoted 6 lines
Quoted 4 lines

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

If we can remove the streaming io corner case by another patch, this patch can be considered to merge.

thanks.

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

#31 lore raw
In reply to Shaohua Li
Quoted 43 lines · Shaohua
Quoted 20 lines · KOSAKI Motohiro
Quoted 20 lines
Quoted 19 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Commit 84b18490d introduces a regression. With it, our tmpfs test always oom. The test uses a 6G tmpfs in a system with 3G memory. In the tmpfs, there are 6 copies of kernel source and the test does kbuild for each copy. My investigation shows the test has a lot of rotated anon pages and quite few file pages, so get_scan_ratio calculates percent[0] to be zero. Actually the percent[0] shoule be a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.

Quoted 8 lines

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scan pages for < 1% percent. With this fix, my test doesn't oom any more.

Note, this patch doesn't really change logics, but just increase precise. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will say one anon page

see?

Quoted 32 lines

swapped. The 16G is calculated as PAGE_SIZE * priority(4096) * (fp/ap). fp/ap is assumed to be 1024 which is common in this workload. So the impact sounds not a big deal.

mm/vmscan.c +18 -0
index 79c8098..80a7ed5 100644
@@ -1519,27 +1519,50 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}

mm/vmscan.c static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, · line 1547

Quoted 10 lines
mm/vmscan.c +3 -2
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[x] specifies how many pages should be scaned

The new comment loses information..

mm/vmscan.c static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, · line 1556

Quoted 11 lines
mm/vmscan.c +3 -2
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+				unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	unsigned long fraction[2], denominator[2];

denominator[2] can be reduced to denominator. because denominator[0] == denominator[1] always holds.

Quoted 63 lines
mm/vmscan.c +19 -25
+	enum lru_list l;
 
 	/* If we have no swap space, do not bother scanning anon pages. */
 	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		percent[0] = 0;
-		percent[1] = 100;
-		return;
+		fraction[0] = 0;
+		denominator[0] = 1;
+		fraction[1] = 1;
+		denominator[1] = 1;
+		goto out;
 	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
@@ -1552,9 +1575,11 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			denominator[0] = 1;
+			fraction[1] = 0;
+			denominator[1] = 1;
+			goto out;
 		}
 	}
 
@@ -1601,29 +1626,29 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
+	fraction[0] = ap;
+	denominator[0] = ap + fp + 1;
+	fraction[1] = fp;
+	denominator[1] = ap + fp + 1;
 
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1647

Quoted 10 lines
mm/vmscan.c +8 -1
+		if (fraction[file] == 0) {
+			nr[l] = 0;
+			continue;
+		}
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);

The "()" is not necessary here, or better end it here^

Thanks,
Fengguang

Quoted 30 lines
mm/vmscan.c +4 -15
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1634,31 +1659,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-
-	get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		if (percent[file] == 0) {
-			nr[l] = 0;
-			continue;
-		}
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority) {

mm/vmscan.c static void shrink_zone(int priority, struct zone *zone, · line 1669

Quoted 10 lines
mm/vmscan.c +1 -6
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

Acked-by
#14 lore raw
In reply to KOSAKI Motohiro
Quoted 6 lines

===================================================================

Quoted 1 line

From 52358cbccdfe94e0381974cd6e937bcc6b1c608b Mon Sep 17 00:00:00 2001

From: KOSAKI Motohiro <[email protected]>
Date: Fri, 2 Apr 2010 17:13:48 +0900
Subject: [PATCH] Revert "vmscan: get_scan_ratio() cleanup"

Quoted 7 lines

Shaohua Li reported his tmpfs streaming I/O test can lead to make oom. The test uses a 6G tmpfs in a system with 3G memory. In the tmpfs, there are 6 copies of kernel source and the test does kbuild for each copy. His investigation shows the test has a lot of rotated anon pages and quite few file pages, so get_scan_ratio calculates percent[0] (i.e. scanning percent for anon) to be zero. Actually the percent[0] shoule be a big value, but our calculation round it to zero.

should small :)

Thanks,
Fengguang

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

author
#21 lore raw
In reply to KOSAKI Motohiro
Quoted 13 lines · KOSAKI Motohiro
Quoted 13 lines · KOSAKI Motohiro
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

Thanks,
Shaohua

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

author
#32 lore raw
In reply to Wu Fengguang
Quoted 48 lines · Fengguang
Quoted 47 lines · Shaohua
Quoted 20 lines · KOSAKI Motohiro
Quoted 20 lines
Quoted 19 lines · KOSAKI Motohiro
Quoted 13 lines

Hi

Quoted 10 lines

Commit 84b18490d1f1bc7ed5095c929f78bc002eb70f26 introduces a regression. With it, our tmpfs test always oom. The test has a lot of rotated anon pages and cause percent[0] zero. Actually the percent[0] is a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.
An option is if percent[x] is zero in get_scan_ratio(), forces it to 1. See below patch.
But the offending commit still changes behavior. Without the commit, we scan all pages if priority is zero, below patch doesn't fix this. Don't know if It's required to fix this too.

Quoted 4 lines

Can you please post your /proc/meminfo and reproduce program? I'll digg it.

Very unfortunately, this patch isn't acceptable. In past time, vmscan had similar logic, but 1% swap-out made lots bug reports.

if 1% is still big, how about below patch?

Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Commit 84b18490d introduces a regression. With it, our tmpfs test always oom. The test uses a 6G tmpfs in a system with 3G memory. In the tmpfs, there are 6 copies of kernel source and the test does kbuild for each copy. My investigation shows the test has a lot of rotated anon pages and quite few file pages, so get_scan_ratio calculates percent[0] to be zero. Actually the percent[0] shoule be a very small value, but our calculation round it to zero. The commit makes vmscan completely skip anon pages and cause oops.

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scan pages for < 1% percent. With this fix, my test doesn't oom any more.

Quoted 6 lines
Quoted 4 lines

Note, this patch doesn't really change logics, but just increase precise. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will say one anon page

see?

Thanks, will send a updated against -mm since we reverted the offending patch.

Thanks,
Shaohua

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

#22 lore raw
In reply to Shaohua Li
Quoted 16 lines · KOSAKI Motohiro
Quoted 15 lines
Quoted 15 lines · KOSAKI Motohiro
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

there is. I had received exactly opposite claim. because shrink_zone() is not called only once. it is called very much time.

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

#23 lore raw
In reply to Shaohua Li
Quoted 18 lines · Shaohua
Quoted 17 lines · KOSAKI Motohiro
Quoted 17 lines · KOSAKI Motohiro
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

1 anon page scanned for every N file pages scanned?

Is N a _huge_ enough ratio so that the anon list will be very light scanned?

Rik: here is a little background.

Under streaming IO, the current get_scan_ratio() will get a percent[0] that is (much) less than 1, so underflows to 0.

It has the bad effect of completely disabling the scan of anon list, which leads to OOM in Shaohua's test case. OTOH, it also has the good side effect of keeping anon pages in memory and totally prevent swap IO.

Shaohua's patch improves the computation precision by computing nr[] directly in get_scan_ratio(). This is good in general, however will enable light scan of the anon list on streaming IO.

Thanks,
Fengguang

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

#24 lore raw
Quoted 24 lines · Shaohua
Quoted 22 lines · KOSAKI Motohiro
Quoted 21 lines
Quoted 13 lines · KOSAKI Motohiro
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Quoted 6 lines
Quoted 4 lines

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

Quoted 8 lines
Quoted 2 lines

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

1 anon page scanned for every N file pages scanned?

Is N a _huge_ enough ratio so that the anon list will be very light scanned?

Rik: here is a little background.

The problem is, the VM are couteniously discarding no longer used file cache. if we are scan extra anon 1 page, we will observe tons swap usage after few days.

please don't only think benchmark.

Quoted 11 lines

Under streaming IO, the current get_scan_ratio() will get a percent[0] that is (much) less than 1, so underflows to 0.

It has the bad effect of completely disabling the scan of anon list, which leads to OOM in Shaohua's test case. OTOH, it also has the good side effect of keeping anon pages in memory and totally prevent swap IO.

Shaohua's patch improves the computation precision by computing nr[] directly in get_scan_ratio(). This is good in general, however will enable light scan of the anon list on streaming IO.

In such case, percent[0] should be big. I think underflowing is not point. His test case is merely streaming io copy, why can't we drop tmpfs cached page? his /proc/meminfo describe his machine didn't have droppable file cache. so, big percent[1] value seems makes no sense. no?

I'm not sure we need either below detection. I need more investigate.
1) detect no discardable file cache
2) detect streaming io on tmpfs (as regular file)

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

#25 lore raw
Quoted 31 lines · KOSAKI Motohiro
Quoted 31 lines · Shaohua
Quoted 18 lines · KOSAKI Motohiro
Quoted 17 lines
Quoted 17 lines · KOSAKI Motohiro
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

1 anon page scanned for every N file pages scanned?

Is N a _huge_ enough ratio so that the anon list will be very light scanned?

Quoted 7 lines
Quoted 1 line

Rik: here is a little background.

The problem is, the VM are couteniously discarding no longer used file cache. if we are scan extra anon 1 page, we will observe tons swap usage after few days.

please don't only think benchmark.

OK the days-of-streaming-io typically happen in file servers. Suppose a file server with 16GB memory, 1GB of which is consumed by anonymous pages, others are for page cache.

Assume that the exact file:anon ratio computed by the get_scan_ratio() algorithm is 1000:1. In that case percent[0]=0.1 and is rounded down to 0, which keeps the anon pages in memory for the few days.

Now with Shaohua's patch, nr[0] = (262144/4096)/1000 = 0.06 will also be rounded down to 0. It only becomes >=1 when
- reclaim runs into trouble and priority goes low
- anon list goes huge

So I guess Shaohua's patch still has reasonable "underflow" threshold :)

Thanks,
Fengguang

Quoted 13 lines
Quoted 4 lines

Under streaming IO, the current get_scan_ratio() will get a percent[0] that is (much) less than 1, so underflows to 0.

Quoted 8 lines

It has the bad effect of completely disabling the scan of anon list, which leads to OOM in Shaohua's test case. OTOH, it also has the good side effect of keeping anon pages in memory and totally prevent swap IO.

Shaohua's patch improves the computation precision by computing nr[] directly in get_scan_ratio(). This is good in general, however will enable light scan of the anon list on streaming IO.

Quoted 11 lines

In such case, percent[0] should be big. I think underflowing is not point. His test case is merely streaming io copy, why can't we drop tmpfs cached page? his /proc/meminfo describe his machine didn't have droppable file cache. so, big percent[1] value seems makes no sense. no?

I'm not sure we need either below detection. I need more investigate.
1) detect no discardable file cache
2) detect streaming io on tmpfs (as regular file)

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

#26 lore raw
Quoted 48 lines · KOSAKI Motohiro
Quoted 31 lines
Quoted 31 lines · Shaohua
Quoted 18 lines · KOSAKI Motohiro
Quoted 17 lines
Quoted 17 lines · KOSAKI Motohiro
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

1 anon page scanned for every N file pages scanned?

Is N a _huge_ enough ratio so that the anon list will be very light scanned?

Quoted 7 lines
Quoted 1 line

Rik: here is a little background.

The problem is, the VM are couteniously discarding no longer used file cache. if we are scan extra anon 1 page, we will observe tons swap usage after few days.

please don't only think benchmark.

OK the days-of-streaming-io typically happen in file servers. Suppose a file server with 16GB memory, 1GB of which is consumed by anonymous pages, others are for page cache.

Assume that the exact file:anon ratio computed by the get_scan_ratio() algorithm is 1000:1. In that case percent[0]=0.1 and is rounded down to 0, which keeps the anon pages in memory for the few days.

Quoted 6 lines

Now with Shaohua's patch, nr[0] = (262144/4096)/1000 = 0.06 will also be rounded down to 0. It only becomes >=1 when
- reclaim runs into trouble and priority goes low
- anon list goes huge

So I guess Shaohua's patch still has reasonable "underflow" threshold :)

Again, I didn't said his patch is no worth. I only said we don't have to ignore the downside.

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

#27 lore raw
Quoted 53 lines · KOSAKI Motohiro
Quoted 53 lines · KOSAKI Motohiro
Quoted 31 lines
Quoted 31 lines · Shaohua
Quoted 18 lines · KOSAKI Motohiro
Quoted 17 lines
Quoted 17 lines · KOSAKI Motohiro
Quoted 16 lines
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

This patch makes a lot of sense than previous. however I think <1% anon ratio shouldn't happen anyway because file lru doesn't have reclaimable pages. <1% seems no good reclaim rate.

Oops, the above mention is wrong. sorry. only 1 page is still too big. because under streaming io workload, the number of scanning anon pages should be zero. this is very strong requirement. if not, backup operation will makes a lot of swapping out.

Sounds there is no big impact for the workload which you mentioned with the patch. please see below descriptions.
I updated the description of the patch as fengguang suggested.

Umm.. sorry, no.

"one fix but introduce another one bug" is not good deal. instead, I'll revert the guilty commit at first as akpm mentioned.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Even we revert the commit, the patch still has its benefit, as it increases calculation precision, right?

no, you shouldn't ignore the regression case.

I don't think this is serious. In my calculation, there is only 1 page swapped out for 6G anonmous memory. 1 page should haven't any performance impact.

1 anon page scanned for every N file pages scanned?

Is N a _huge_ enough ratio so that the anon list will be very light scanned?

Quoted 7 lines
Quoted 1 line

Rik: here is a little background.

The problem is, the VM are couteniously discarding no longer used file cache. if we are scan extra anon 1 page, we will observe tons swap usage after few days.

please don't only think benchmark.

OK the days-of-streaming-io typically happen in file servers. Suppose a file server with 16GB memory, 1GB of which is consumed by anonymous pages, others are for page cache.

Assume that the exact file:anon ratio computed by the get_scan_ratio() algorithm is 1000:1. In that case percent[0]=0.1 and is rounded down to 0, which keeps the anon pages in memory for the few days.

Now with Shaohua's patch, nr[0] = (262144/4096)/1000 = 0.06 will also be rounded down to 0. It only becomes >=1 when
- reclaim runs into trouble and priority goes low
- anon list goes huge

Quoted 4 lines
Quoted 1 line

So I guess Shaohua's patch still has reasonable "underflow" threshold :)

Again, I didn't said his patch is no worth. I only said we don't have to ignore the downside.

Right, we should document both the upside and downside.

The main difference happens when file:anon scan ratio > 100:1.

For the current percent[] based computing, percent[0]=0 hence nr[0]=0 which disables anon list scan unconditionally, for good or for bad.

For the direct nr[] computing,
- nr[0] will be 0 for typical file servers, because with priority=12 and anon lru size < 1.6GB, nr[0] = (anon_size/4096)/100 < 0
- nr[0] will be non-zero when priority=1 and anon_size > 100 pages, this stops OOM for Shaohua's test case, however may not be enough to guarantee safety (your previous reverting patch can provide this guarantee).

I liked Shaohua's patch a lot -- it adapts well to both the file-server case and the mostly-anon-pages case :)

Thanks,
Fengguang

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

Acked-by
#15 lore raw
In reply to KOSAKI Motohiro
Quoted 9 lines · KOSAKI Motohiro
Quoted 9 lines
Quoted 3 lines

Yeah, I don't want ignore .33-stable too. if I can't find the root cause in 2-3 days, I'll revert guilty patch anyway.

It's a good idea to avoid fixing a bug one-way-in-stable, other-way-in-mainline. Because then we have new code in both trees which is different. And the -stable guys sensibly like to see code get a bit of a shakedown in mainline before backporting it.

Quoted 6 lines
Quoted 3 lines

So it would be better to merge the "simple" patch into mainline, tagged for -stable backporting. Then we can later implement the larger fix in mainline, perhaps starting by reverting the "simple" fix.

.....ok. I don't have to prevent your code maintainship. although I still think we need to fix the issue completely.

Agreed on the revert.

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

#28 lore raw
In reply to Wu Fengguang
Quoted 5 lines · Wu Fengguang
Quoted 2 lines · KOSAKI Motohiro

Again, I didn't said his patch is no worth. I only said we don't have to ignore the downside.

Right, we should document both the upside and downside.

The downside is obvious: streaming IO (used once data that does not fit in the cache) can push out data that is used more often - requiring that it be swapped in at a later point in time.

I understand what Shaohua's patch does, but I do not understand the upside. What good does it do to increase the size of the cache for streaming IO data, which is generally touched only once?

What kind of performance benefits can we get by doing that?

Quoted 13 lines

The main difference happens when file:anon scan ratio> 100:1.

For the current percent[] based computing, percent[0]=0 hence nr[0]=0 which disables anon list scan unconditionally, for good or for bad.

For the direct nr[] computing,
- nr[0] will be 0 for typical file servers, because with priority=12 and anon lru size< 1.6GB, nr[0] = (anon_size/4096)/100< 0
- nr[0] will be non-zero when priority=1 and anon_size> 100 pages, this stops OOM for Shaohua's test case, however may not be enough to guarantee safety (your previous reverting patch can provide this guarantee).

Quoted 2 lines

I liked Shaohua's patch a lot -- it adapts well to both the file-server case and the mostly-anon-pages case :)

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

#29 lore raw
Quoted 12 lines · Rik van Riel
Quoted 5 lines · Wu Fengguang
Quoted 2 lines · KOSAKI Motohiro

Again, I didn't said his patch is no worth. I only said we don't have to ignore the downside.

Right, we should document both the upside and downside.

The downside is obvious: streaming IO (used once data that does not fit in the cache) can push out data that is used more often - requiring that it be swapped in at a later point in time.

Quoted 4 lines

I understand what Shaohua's patch does, but I do not understand the upside. What good does it do to increase the size of the cache for streaming IO data, which is generally touched only once?

Not that bad :) With Shaohua's patch the anon list will typically _never_ get scanned, just like before.

If it's mostly use-once IO, file:anon will be 1000 or even 10000, and priority=12. Then only anon lists larger than 16GB or 160GB will get nr[0] >= 1.

Quoted 2 lines

What kind of performance benefits can we get by doing that?

So vmscan behavior and performance remain the same as before.

For really large anon list, such workload is beyond our imagination. So we cannot assert "don't scan anon list" will be a benefit.

On the other hand, in the test case of "do stream IO when most memory occupied by tmpfs pages", it is very bad behavior refuse to scan anon list in normal and suddenly start scanning _the whole_ anon list when priority hits 0. Shaohua's patch helps it by gradually increasing the scan nr of anon list as memory pressure increases.

Thanks,
Fengguang

Quoted 13 lines
Quoted 13 lines

The main difference happens when file:anon scan ratio> 100:1.

For the current percent[] based computing, percent[0]=0 hence nr[0]=0 which disables anon list scan unconditionally, for good or for bad.

For the direct nr[] computing,
- nr[0] will be 0 for typical file servers, because with priority=12 and anon lru size< 1.6GB, nr[0] = (anon_size/4096)/100< 0
- nr[0] will be non-zero when priority=1 and anon_size> 100 pages, this stops OOM for Shaohua's test case, however may not be enough to guarantee safety (your previous reverting patch can provide this guarantee).

Quoted 4 lines
Quoted 2 lines

I liked Shaohua's patch a lot -- it adapts well to both the file-server case and the mostly-anon-pages case :)

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

#33 lore raw
In reply to Shaohua Li

Shaohua,

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1647

Quoted 4 lines
mm/vmscan.c +4 -0
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);

Ah, the (scan * fraction[file]) may overflow in 32bit kernel!

Thanks,
Fengguang

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

author
#30 lore raw
In reply to Wu Fengguang
Quoted 30 lines · Fengguang
Quoted 12 lines · Rik van Riel
Quoted 5 lines · Wu Fengguang
Quoted 2 lines · KOSAKI Motohiro

Again, I didn't said his patch is no worth. I only said we don't have to ignore the downside.

Right, we should document both the upside and downside.

The downside is obvious: streaming IO (used once data that does not fit in the cache) can push out data that is used more often - requiring that it be swapped in at a later point in time.

Quoted 4 lines

I understand what Shaohua's patch does, but I do not understand the upside. What good does it do to increase the size of the cache for streaming IO data, which is generally touched only once?

Not that bad :) With Shaohua's patch the anon list will typically _never_ get scanned, just like before.

If it's mostly use-once IO, file:anon will be 1000 or even 10000, and priority=12. Then only anon lists larger than 16GB or 160GB will get nr[0] >= 1.

Quoted 2 lines

What kind of performance benefits can we get by doing that?

So vmscan behavior and performance remain the same as before.

Quoted 8 lines

For really large anon list, such workload is beyond our imagination. So we cannot assert "don't scan anon list" will be a benefit.

On the other hand, in the test case of "do stream IO when most memory occupied by tmpfs pages", it is very bad behavior refuse to scan anon list in normal and suddenly start scanning _the whole_ anon list when priority hits 0. Shaohua's patch helps it by gradually increasing the scan nr of anon list as memory pressure increases.

Yep, the gradually increasing scan nr is the main advantage in my mind.

Thanks,
Shaohua

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

The main difference happens when file:anon scan ratio> 100:1.

For the current percent[] based computing, percent[0]=0 hence nr[0]=0 which disables anon list scan unconditionally, for good or for bad.

For the direct nr[] computing,
- nr[0] will be 0 for typical file servers, because with priority=12 and anon lru size< 1.6GB, nr[0] = (anon_size/4096)/100< 0
- nr[0] will be non-zero when priority=1 and anon_size> 100 pages, this stops OOM for Shaohua's test case, however may not be enough to guarantee safety (your previous reverting patch can provide this guarantee).

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

I liked Shaohua's patch a lot -- it adapts well to both the file-server case and the mostly-anon-pages case :)

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

author
#34 lore raw
In reply to Wu Fengguang
Quoted 8 lines · Fengguang

Shaohua,

mm/vmscan.c static void get_scan_ratio(struct zone *zone, struct scan_control *sc, · line 1647

Quoted 4 lines
mm/vmscan.c +4 -0
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);

Ah, the (scan * fraction[file]) may overflow in 32bit kernel!

good catch. will change it to u64.

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

author
#35 lore raw
In reply to Wu Fengguang
Quoted 8 lines · Fengguang

Shaohua,

Review

Quoted 4 lines
(quoted diff) +4 -0
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority) {
+			scan >>= priority;
+			scan = (scan * fraction[file] / denominator[file]);

Ah, the (scan * fraction[file]) may overflow in 32bit kernel!

I updated the patch to address previous issues.
is it possible to put this to -mm tree to see if there is anything wield happen?

get_scan_ratio() calculates percentage and if the percentage is < 1%, it will round percentage down to 0% and cause we completely ignore scanning anon/file pages to reclaim memory even the total anon/file pages are very big.

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scanned pages for < 1% percent.

This has some benefits:
1. increase our calculation precision
2. making our scan more smoothly. Without this, if percent[x] is underflow, shrink_zone() doesn't scan any pages and suddenly it scans all pages when priority is zero. With this, even priority isn't zero, shrink_zone() gets chance to scan some pages.

Note, this patch doesn't really change logics, but just increase precision. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will see one anon page swapped. The 16G is calculated as PAGE_SIZE * priority(4096) * (fp/ap). fp/ap is assumed to be 1024 which is common in this workload. So the impact sounds not a big deal.

Cc KOSAKI Motohiro <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Wu Fengguang <[email protected]>
mm/vmscan.c +55 -52
index 3ff3311..1070f83 100644
@@ -1519,21 +1519,52 @@ static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,
 }
 
 /*
+ * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
+ * until we collected @swap_cluster_max pages to scan.
+ */
+static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
+				       unsigned long *nr_saved_scan)
+{
+	unsigned long nr;
+
+	*nr_saved_scan += nr_to_scan;
+	nr = *nr_saved_scan;
+
+	if (nr >= SWAP_CLUSTER_MAX)
+		*nr_saved_scan = 0;
+	else
+		nr = 0;
+
+	return nr;
+}
+
+/*
  * Determine how aggressively the anon and file LRU lists should be
  * scanned.  The relative value of each set of LRU lists is determined
  * by looking at the fraction of the pages scanned we did rotate back
  * onto the active list instead of evict.
  *
- * percent[0] specifies how much pressure to put on ram/swap backed
- * memory, while percent[1] determines pressure on the file LRUs.
+ * nr[0] = anon pages to scan; nr[1] = file pages to scan
  */
-static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
-					unsigned long *percent)
+static void get_scan_count(struct zone *zone, struct scan_control *sc,
+					unsigned long *nr, int priority)
 {
 	unsigned long anon, file, free;
 	unsigned long anon_prio, file_prio;
 	unsigned long ap, fp;
 	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+	u64 fraction[2], denominator;
+	enum lru_list l;
+	int noswap = 0;
+
+	/* If we have no swap space, do not bother scanning anon pages. */
+	if (!sc->may_swap || (nr_swap_pages <= 0)) {
+		noswap = 1;
+		fraction[0] = 0;
+		fraction[1] = 1;
+		denominator = 1;
+		goto out;
+	}
 
 	anon  = zone_nr_lru_pages(zone, sc, LRU_ACTIVE_ANON) +
 		zone_nr_lru_pages(zone, sc, LRU_INACTIVE_ANON);
@@ -1545,9 +1576,10 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 		/* If we have very few page cache pages,
 		   force-scan anon pages. */
 		if (unlikely(file + free <= high_wmark_pages(zone))) {
-			percent[0] = 100;
-			percent[1] = 0;
-			return;
+			fraction[0] = 1;
+			fraction[1] = 0;
+			denominator = 1;
+			goto out;
 		}
 	}
 
@@ -1594,29 +1626,22 @@ static void get_scan_ratio(struct zone *zone, struct scan_control *sc,
 	fp = (file_prio + 1) * (reclaim_stat->recent_scanned[1] + 1);
 	fp /= reclaim_stat->recent_rotated[1] + 1;
 
-	/* Normalize to percentages */
-	percent[0] = 100 * ap / (ap + fp + 1);
-	percent[1] = 100 - percent[0];
-}
-
-/*
- * Smallish @nr_to_scan's are deposited in @nr_saved_scan,
- * until we collected @swap_cluster_max pages to scan.
- */
-static unsigned long nr_scan_try_batch(unsigned long nr_to_scan,
-				       unsigned long *nr_saved_scan)
-{
-	unsigned long nr;
-
-	*nr_saved_scan += nr_to_scan;
-	nr = *nr_saved_scan;
-
-	if (nr >= SWAP_CLUSTER_MAX)
-		*nr_saved_scan = 0;
-	else
-		nr = 0;
+	fraction[0] = ap;
+	fraction[1] = fp;
+	denominator = ap + fp + 1;
+out:
+	for_each_evictable_lru(l) {
+		int file = is_file_lru(l);
+		unsigned long scan;
 
-	return nr;
+		scan = zone_nr_lru_pages(zone, sc, l);
+		if (priority || noswap) {
+			scan >>= priority;
+			scan = div64_u64(scan * fraction[file], denominator);
+		}
+		nr[l] = nr_scan_try_batch(scan,
+					  &reclaim_stat->nr_saved_scan[l]);
+	}
 }
 
 /*
@@ -1627,33 +1652,11 @@ static void shrink_zone(int priority, struct zone *zone,
 {
 	unsigned long nr[NR_LRU_LISTS];
 	unsigned long nr_to_scan;
-	unsigned long percent[2];	/* anon @ 0; file @ 1 */
 	enum lru_list l;
 	unsigned long nr_reclaimed = sc->nr_reclaimed;
 	unsigned long nr_to_reclaim = sc->nr_to_reclaim;
-	struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
-	int noswap = 0;
-
-	/* If we have no swap space, do not bother scanning anon pages. */
-	if (!sc->may_swap || (nr_swap_pages <= 0)) {
-		noswap = 1;
-		percent[0] = 0;
-		percent[1] = 100;
-	} else
-		get_scan_ratio(zone, sc, percent);
 
-	for_each_evictable_lru(l) {
-		int file = is_file_lru(l);
-		unsigned long scan;
-
-		scan = zone_nr_lru_pages(zone, sc, l);
-		if (priority || noswap) {
-			scan >>= priority;
-			scan = (scan * percent[file]) / 100;
-		}
-		nr[l] = nr_scan_try_batch(scan,
-					  &reclaim_stat->nr_saved_scan[l]);
-	}
+	get_scan_count(zone, sc, nr, priority);
 
 	while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
 					nr[LRU_INACTIVE_FILE]) {

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

maintainer
#36 lore raw
Quoted 15 lines · On Fri, 9 Apr 2010 14:51:04 +0800 Shaohua Li <[email protected]> wrote:

get_scan_ratio() calculates percentage and if the percentage is < 1%, it will round percentage down to 0% and cause we completely ignore scanning anon/file pages to reclaim memory even the total anon/file pages are very big.

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scanned pages for < 1% percent.

This has some benefits:
1. increase our calculation precision
2. making our scan more smoothly. Without this, if percent[x] is underflow, shrink_zone() doesn't scan any pages and suddenly it scans all pages when priority is zero. With this, even priority isn't zero, shrink_zone() gets chance to scan some pages.

Quoted 7 lines

Note, this patch doesn't really change logics, but just increase precision. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will see one anon page swapped. The 16G is calculated as PAGE_SIZE * priority(4096) * (fp/ap). fp/ap is assumed to be 1024 which is common in this workload. So the impact sounds not a big deal.

I grabbed this.

Did we decide that this needed to be backported into 2.6.33.x? If so, some words explaining the reasoning would be needed.

Come to that, it's not obvious that we need this in 2.6.34 either. What is the user-visible impact here?

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

Acked-by
#37 lore raw
Quoted 2 lines · Andrew Morton

Come to that, it's not obvious that we need this in 2.6.34 either. What is the user-visible impact here?

I suspect very little impact, especially during workloads where we can just reclaim clean page cache at DEF_PRIORITY. FWIW, the patch looks good to me, so:

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

author
#44 lore raw
In reply to Andrew Morton
Quoted 26 lines · Andrew Morton
Quoted 15 lines · On Fri, 9 Apr 2010 14:51:04 +0800 Shaohua Li <[email protected]> wrote:

get_scan_ratio() calculates percentage and if the percentage is < 1%, it will round percentage down to 0% and cause we completely ignore scanning anon/file pages to reclaim memory even the total anon/file pages are very big.

To avoid underflow, we don't use percentage, instead we directly calculate how many pages should be scaned. In this way, we should get several scanned pages for < 1% percent.

This has some benefits:
1. increase our calculation precision
2. making our scan more smoothly. Without this, if percent[x] is underflow, shrink_zone() doesn't scan any pages and suddenly it scans all pages when priority is zero. With this, even priority isn't zero, shrink_zone() gets chance to scan some pages.

Quoted 7 lines

Note, this patch doesn't really change logics, but just increase precision. For system with a lot of memory, this might slightly changes behavior. For example, in a sequential file read workload, without the patch, we don't swap any anon pages. With it, if anon memory size is bigger than 16G, we will see one anon page swapped. The 16G is calculated as PAGE_SIZE * priority(4096) * (fp/ap). fp/ap is assumed to be 1024 which is common in this workload. So the impact sounds not a big deal.

Quoted 6 lines

I grabbed this.

Did we decide that this needed to be backported into 2.6.33.x? If so, some words explaining the reasoning would be needed.

Come to that, it's not obvious that we need this in 2.6.34 either.

Not needed.

Quoted 1 line

is the user-visible impact here?

Should be very small I think.

Thanks,
Shaohua

#38 lore raw
In reply to Rik van Riel
Quoted 11 lines · Andrew Morton
Quoted 3 lines

Come to that, it's not obvious that we need this in 2.6.34 either. What is the user-visible impact here?

I suspect very little impact, especially during workloads where we can just reclaim clean page cache at DEF_PRIORITY. FWIW, the patch looks good to me, so:

I'm surprised this ack a bit. Rik, do you have any improvement plan about streaming io detection logic?
I think the patch have a slightly marginal benefit, it help to <1% scan ratio case. but it have big regression, it cause streaming io (e.g. backup operation) makes tons swap.

So, I thought we sould do either,
1) drop this one
2) merge to change stream io detection logic improvement at first, and merge this one at second.

Am i missing something?

#39 lore raw
Quoted 9 lines · KOSAKI Motohiro
Quoted 9 lines · Andrew Morton
Quoted 3 lines

Come to that, it's not obvious that we need this in 2.6.34 either. What is the user-visible impact here?

I suspect very little impact, especially during workloads where we can just reclaim clean page cache at DEF_PRIORITY. FWIW, the patch looks good to me, so:

Quoted 8 lines
Quoted 2 lines

I'm surprised this ack a bit. Rik, do you have any improvement plan about streaming io detection logic?
I think the patch have a slightly marginal benefit, it help to<1% scan ratio case. but it have big regression, it cause streaming io (e.g. backup operation) makes tons swap.

How? From the description I believe it took 16GB in a zone before we start scanning anon pages when reclaiming at DEF_PRIORITY?

Would that casue a problem?

Quoted 4 lines

So, I thought we sould do either,
1) drop this one
2) merge to change stream io detection logic improvement at first, and merge this one at second.

We may need better streaming IO detection, anyway.

I have noticed that while heavy sequential reads are fine, the virtual machines on my desktop system do a lot of whole block writes. Presumably, a lot of those writes are to the same blocks, over and over again.

This causes the blocks to be promoted to the active file list, which ends up growing the active file list to the point where things from the working set get evicted.

All for file pages that may only get WRITTEN to by the guests, because the guests cache their own copy whenever they need to read them!

I'll have to check the page cache code to see if it keeps frequently written pages as accessed. We may be better off evicting frequently written pages, and keeping our cache space for data that is read...

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

#40 lore raw
Quoted 19 lines · KOSAKI Motohiro
Quoted 9 lines
Quoted 9 lines · Andrew Morton
Quoted 3 lines

Come to that, it's not obvious that we need this in 2.6.34 either. What is the user-visible impact here?

I suspect very little impact, especially during workloads where we can just reclaim clean page cache at DEF_PRIORITY. FWIW, the patch looks good to me, so:

Quoted 8 lines
Quoted 2 lines

I'm surprised this ack a bit. Rik, do you have any improvement plan about streaming io detection logic?
I think the patch have a slightly marginal benefit, it help to<1% scan ratio case. but it have big regression, it cause streaming io (e.g. backup operation) makes tons swap.

Quoted 5 lines

How? From the description I believe it took 16GB in a zone before we start scanning anon pages when reclaiming at DEF_PRIORITY?

Would that casue a problem?

Please remember, 2.6.27 has following +1 scanning modifier.

  zone->nr_scan_active += (zone_page_state(zone, NR_ACTIVE) >> priority) + 1;
                                                                         ^^^^

and, early (ano not yet merged) SplitLRU VM has similar +1. likes

         scan = zone_nr_lru_pages(zone, sc, l);
         scan >>= priority;
         scan = (scan * percent[file]) / 100 + 1;
                                             ^^^

We didn't think only one page scanning is not big matter. but it was not correct. we got streaming io bug report. the above +1 makes annoying swap io. because some server need big backup operation rather much much than physical memory size.

example, If vm are dropping 1TB use once pages, 0.1% anon scanning makes 1GB scan. and almost server only have some gigabyte swap although it has >1TB memory.

If my memory is not correct, please correct me.

My point is, greater or smaller than 16GB isn't essential. all patches should have big worth than the downside. The description said "the impact sounds not a big deal", nobody disagree it. but it's worth is more little. I don't imagine this patch improve anything.

Quoted 7 lines
Quoted 5 lines

So, I thought we sould do either,
1) drop this one
2) merge to change stream io detection logic improvement at first, and merge this one at second.

We may need better streaming IO detection, anyway.

agreed. that's no doubt.

Quoted 9 lines

I have noticed that while heavy sequential reads are fine, the virtual machines on my desktop system do a lot of whole block writes. Presumably, a lot of those writes are to the same blocks, over and over again.

This causes the blocks to be promoted to the active file list, which ends up growing the active file list to the point where things from the working set get evicted.

Quoted 8 lines

All for file pages that may only get WRITTEN to by the guests, because the guests cache their own copy whenever they need to read them!

I'll have to check the page cache code to see if it keeps frequently written pages as accessed. We may be better off evicting frequently written pages, and keeping our cache space for data that is read...

One question, In such case your guest don't use DirectIO? Or do you talk about guest VM behabior?

I guess inactive_file_is_low_global() can be improvement a lot. but I'm not sure.

#41 lore raw
Quoted 33 lines
Quoted 11 lines
Quoted 5 lines

I'm surprised this ack a bit. Rik, do you have any improvement plan about streaming io detection logic?
I think the patch have a slightly marginal benefit, it help to<1% scan ratio case. but it have big regression, it cause streaming io (e.g. backup operation) makes tons swap.

How? From the description I believe it took 16GB in a zone before we start scanning anon pages when reclaiming at DEF_PRIORITY?

Would that casue a problem?

Please remember, 2.6.27 has following +1 scanning modifier.

  zone->nr_scan_active += (zone_page_state(zone, NR_ACTIVE) >> priority) + 1;
                                                                         ^^^^

and, early (ano not yet merged) SplitLRU VM has similar +1. likes

         scan = zone_nr_lru_pages(zone, sc, l);
         scan >>= priority;
         scan = (scan * percent[file]) / 100 + 1;
                                             ^^^

We didn't think only one page scanning is not big matter. but it was not correct. we got streaming io bug report. the above +1 makes annoying swap io. because some server need big backup operation rather much much than physical memory size.

example, If vm are dropping 1TB use once pages, 0.1% anon scanning makes 1GB scan. and almost server only have some gigabyte swap although it has >1TB memory.

Quoted 6 lines

If my memory is not correct, please correct me.

My point is, greater or smaller than 16GB isn't essential. all patches should have big worth than the downside. The description said "the impact sounds not a big deal", nobody disagree it. but it's worth is more little. I don't imagine this patch improve anything.

And now I've merged this patch into my local vmscan patch queue. After solving streaming io issue, I'll put it to mainline.

Thanks.

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

author
#42 lore raw
Quoted 35 lines · KOSAKI Motohiro
Quoted 35 lines
Quoted 11 lines
Quoted 5 lines

I'm surprised this ack a bit. Rik, do you have any improvement plan about streaming io detection logic?
I think the patch have a slightly marginal benefit, it help to<1% scan ratio case. but it have big regression, it cause streaming io (e.g. backup operation) makes tons swap.

How? From the description I believe it took 16GB in a zone before we start scanning anon pages when reclaiming at DEF_PRIORITY?

Would that casue a problem?

Please remember, 2.6.27 has following +1 scanning modifier.

  zone->nr_scan_active += (zone_page_state(zone, NR_ACTIVE) >> priority) + 1;
                                                                         ^^^^

and, early (ano not yet merged) SplitLRU VM has similar +1. likes

         scan = zone_nr_lru_pages(zone, sc, l);
         scan >>= priority;
         scan = (scan * percent[file]) / 100 + 1;
                                             ^^^

We didn't think only one page scanning is not big matter. but it was not correct. we got streaming io bug report. the above +1 makes annoying swap io. because some server need big backup operation rather much much than physical memory size.

example, If vm are dropping 1TB use once pages, 0.1% anon scanning makes 1GB scan. and almost server only have some gigabyte swap although it has >1TB memory.

If my memory is not correct, please correct me.

Quoted 7 lines
Quoted 4 lines

My point is, greater or smaller than 16GB isn't essential. all patches should have big worth than the downside. The description said "the impact sounds not a big deal", nobody disagree it. but it's worth is more little. I don't imagine this patch improve anything.

And now I've merged this patch into my local vmscan patch queue. After solving streaming io issue, I'll put it to mainline.

if the streaming io issue is popular, how about below patch against my last one? we take priority == DEF_PRIORITY an exception.

mm/vmscan.c +16 -0
Index: linux/mm/vmscan.c
===================================================================
@@ -1629,6 +1629,22 @@ static void get_scan_count(struct zone *
 	fraction[0] = ap;
 	fraction[1] = fp;
 	denominator = ap + fp + 1;
+
+	/*
+	 * memory pressure isn't high, we allow percentage underflow. This
+	 * avoids swap in stream io case.
+	 */
+	if (priority == DEF_PRIORITY) {
+		if (fraction[0] * 99 < fraction[1]) {
+			fraction[0] = 0;
+			fraction[1] = 1;
+			denominator = 1;
+		} else if (fraction[1] * 99 < fraction[0]) {
+			fraction[0] = 1;
+			fraction[1] = 0;
+			denominator = 1;
+		}
+	}
 out:
 	for_each_evictable_lru(l) {
 		int file = is_file_lru(l);

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

#43 lore raw

Hi

sorry for the delay.

Quoted 3 lines
Quoted 1 line

After solving streaming io issue, I'll put it to mainline.

if the streaming io issue is popular, how about below patch against my last one? we take priority == DEF_PRIORITY an exception.

Your patch seems works. but it is obviously ugly and bandaid patch. So, I like single your previous patch rather than combinate this one. Even though both dropping makes sense rather than both merge.

Please consider attack root cause.

Quoted 29 lines

Index: linux/mm/vmscan.c
===================================================================

mm/vmscan.c +16 -1
@@ -1629,6 +1629,22 @@ static void get_scan_count(struct zone *
 	fraction[0] = ap;
 	fraction[1] = fp;
 	denominator = ap + fp + 1;
+
+	/*
+	 * memory pressure isn't high, we allow percentage underflow. This
+	 * avoids swap in stream io case.
+	 */
+	if (priority == DEF_PRIORITY) {
+		if (fraction[0] * 99 < fraction[1]) {
+			fraction[0] = 0;
+			fraction[1] = 1;
+			denominator = 1;
+		} else if (fraction[1] * 99 < fraction[0]) {
+			fraction[0] = 1;
+			fraction[1] = 0;
+			denominator = 1;
+		}
+	}
 out:
 	for_each_evictable_lru(l) {
 		int file = is_file_lru(l);
 
--
Quoted 4 lines

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

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