Skip to contentSkip to conversation

vmscan: make kswapd use a correct order

PATCH In review Shaohua Li 6 participants 30 messages Dec 1, 2010 – Dec 14, 2010

Subsystems (3)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 vmscan: make kswapd use a correct order

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +1 -1
index d31d7ce..15cd0d2 100644
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);
 

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Shaohua Li

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

But you need the description more easily.

I try it.

T0 : Task 1 wakes up kswapd with order-3
T1 : So, kswapd starts to reclaim pages using balance_pgdat
T2:  Task 2 wakes up kswapd with order-2 because pages reclaimed by T1

are consumed quickly.
T3: kswapd exits balance_pgdat and will recheck remained work T4-1 : In beginning of kswapd's loop, pgdat->kswapd_max_order will be reset with zero.
T4-2: If previous balance_pgdat can't meet requirement of order-3 free pages by high watermark, it can start reclaiming again. T4-3 :Unfortunately, balance_pgdat's argument _order_ is pgdat->kswapd_max_order which was zero. It should have been 2.

Regardless of my suggestion, I will add my Reviewed-by.

Quoted 23 lines
mm/vmscan.c +1 -2
index d31d7ce..15cd0d2 100644
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                                }
                        }
 
-                       order = pgdat->kswapd_max_order;
+                       order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
                }
                finish_wait(&pgdat->kswapd_wait, &wait);
 
 
 
--

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author Reviewed-by Minchan Kim
#2 lore raw
Quoted 11 lines · Minchan Kim
Quoted 10 lines · Shaohua Li

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

Quoted 6 lines
Quoted 1 line

But you need the description more easily.

I try it.

Thanks, changed the description.

T0: Task 1 wakes up kswapd with order-3
T1: So, kswapd starts to reclaim pages using balance_pgdat
T2: Task 2 wakes up kswapd with order-2 because pages reclaimed by T1 are consumed quickly.
T3: kswapd exits balance_pgdat and will do following:
T4-1: In beginning of kswapd's loop, pgdat->kswapd_max_order will be reset with zero.
T4-2: order will be set to pgdat->kswapd_max_order(0), since it enters the false branch of 'if (order (3) < new_order (2))'
T4-3: If previous balance_pgdat can't meet requirement of order-2 free pages by high watermark, it will start reclaiming again. So balance_pgdat will use order-0 to do reclaim, while at this time it really should use order-2

This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +2 -1
index d31d7ce..c630349 100644
@@ -2450,7 +2450,8 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order,
+				pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);
 

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
In reply to Shaohua Li
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

new patch is here.

From 8f436224219a1da01985fd9644e1307e7c4cb8c3 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Sun, 26 Dec 2010 21:10:55 +0900
Subject: [PATCH] vmscan: make kswapd use a correct order

If sleeping_prematurely() return false, It's a sign of retrying reclaim. So, we don't have to drop old order value.

---
 mm/vmscan.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
mm/vmscan.c +7 -4
index 1fcadaf..f052a1a 100644
@@ -2364,13 +2364,13 @@ out:
 	return sc.nr_reclaimed;
 }
 
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+static int kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return 0;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2399,13 +2399,17 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		order = pgdat->kswapd_max_order;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
 		else
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+		order = max(order, pgdat->kswapd_max_order);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return order;
 }
 
 /*
@@ -2467,8 +2471,7 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			order = kswapd_try_to_sleep(pgdat, order);
 		}
 
 		ret = try_to_freeze();
Signature · 10 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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by
#4 lore raw
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.
In addtion, new order is always less than old order in that context.
so big order page reclaim makes much safe for low order pages.

Quoted 5 lines

new patch is here.

Quoted 7 lines

From 8f436224219a1da01985fd9644e1307e7c4cb8c3 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Sun, 26 Dec 2010 21:10:55 +0900
Subject: [PATCH] vmscan: make kswapd use a correct order

If sleeping_prematurely() return false, It's a sign of retrying reclaim. So, we don't have to drop old order value.

I think this description isn't enough.

Quoted 5 lines

But could you see my below suggestion?

Quoted 56 lines
---
 mm/vmscan.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
mm/vmscan.c +7 -4
index 1fcadaf..f052a1a 100644
@@ -2364,13 +2364,13 @@ out:
 	return sc.nr_reclaimed;
 }
 
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+static int kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return 0;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2399,13 +2399,17 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		order = pgdat->kswapd_max_order;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
 		else
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+		order = max(order, pgdat->kswapd_max_order);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return order;
 }
 
 /*
@@ -2467,8 +2471,7 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			order = kswapd_try_to_sleep(pgdat, order);
 		}
 
 		ret = try_to_freeze();
Signature · 1 line
1.6.5.2

It might work well. but I don't like such a coding that kswapd_try_to_sleep's eturn value is order. It doesn't look good to me and even no comment. Hmm..

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

---
 mm/vmscan.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
mm/vmscan.c +17 -4
index 42a4859..e48a612 100644
@@ -2447,13 +2447,18 @@ out:
 	return sc.nr_reclaimed;
 }
 
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+/*
+ * Return true if we sleep enough. Othrewise, return false
+ */
+static bool kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
+	bool sleep = 0;
+
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return sleep;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2482,6 +2487,7 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		sleep = 1;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
@@ -2489,6 +2495,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return sleep;
 }
 
 /*
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;
 		}
 
 		ret = try_to_freeze();
Signature · 12 lines
1.7.0.4

-- 
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by
#5 lore raw
Quoted 9 lines

It might work well. but I don't like such a coding that kswapd_try_to_sleep's eturn value is order. It doesn't look good to me and even no comment. Hmm..

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

I'm ok this.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 8 lines
Quoted 8 lines

It might work well. but I don't like such a coding that kswapd_try_to_sleep's eturn value is order. It doesn't look good to me and even no comment. Hmm..

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

Quoted 9 lines
Quoted 1 line

I'm ok this.

Thanks.

Please consider rensend a patch with full patch description. Of cource, you need to rebase this on top Mel's patch.

Plus, please don't remove Shaohua's reported-by tag. It's important line than my code. Please respect good bug finder.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 15 lines · KOSAKI Motohiro
Quoted 15 lines
Quoted 9 lines

It might work well. but I don't like such a coding that kswapd_try_to_sleep's eturn value is order. It doesn't look good to me and even no comment. Hmm..

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

I'm ok this.

Quoted 8 lines
Quoted 2 lines

Thanks.

Please consider rensend a patch with full patch description. Of cource, you need to rebase this on top Mel's patch.

Plus, please don't remove Shaohua's reported-by tag. It's important line than my code. Please respect good bug finder.

I don't have a thought to intercept Shaohua and Your's credit. Just a review so I hoped you send the patch with adding my signed-off or reviewed-by.

Okay. I will resend it with full-description and you guys's signed-off. But before that, We have to discuss Shaohua's argue about _safety_.

Quoted 5 lines

Thanks.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#8 lore raw
In reply to Minchan Kim

Paging Mel Gorman. This fix looks pretty thoroughly related to your "[RFC PATCH 0/3] Prevent kswapd dumping excessive amounts of memory in response to high-order allocations"?

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw
Quoted 5 lines · Andrew Morton

Paging Mel Gorman. This fix looks pretty thoroughly related to your "[RFC PATCH 0/3] Prevent kswapd dumping excessive amounts of memory in response to high-order allocations"?

It affects the same area and I'll need to rebase this patch on top of my series for testing by Simon and his "aggressive kswapd" problem. I haven't finished reviewing the thread yet but my initial impressions are that it won't fix Simon's problem but that it's a real issue.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#10 lore raw
In reply to Minchan Kim
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
Quoted 44 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                           }
                   }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
           }
           finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

Quoted 7 lines

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages. Then, your patch makes continue to reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck. It's kind of live lock(But it's just unlikely theory). But KOSAKI's approach can make sure reclaim order-3 pages so it can meet requirement about both order-2,3. In this context, I said _safety_.

Of course, it could discard useful pages if Task1 get a pages. I think it's a trade-off.
We should determine the policy.
I biased safety of GFP_ATOMIC.

Quoted 4 lines

Thanks,
Shaohua

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#12 lore raw
Quoted 48 lines · Minchan Kim
Quoted 47 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                          }
                  }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
          }
          finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages.

but even you reclaim order-3, you can't guarantee task1 can get the pages too. order-3 page can be steal by order-2 allocation

Quoted 3 lines

Then, your patch makes continue to
reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck.

Task1 will wakeup kswapd again for order-3, so kswapd will reclaim order-3 very soon after the order-2 reclaim.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
Quoted 38 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 36 lines · Shaohua Li
Quoted 35 lines · Minchan Kim
Quoted 34 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                           }
                   }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
           }
           finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false

#14 lore raw

Where is my mail?
I will resend lost content.

Quoted 87 lines · Minchan Kim
Quoted 51 lines · Shaohua Li
Quoted 50 lines · Minchan Kim
Quoted 49 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                           }
                   }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
           }
           finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages.

but even you reclaim order-3, you can't guarantee task1 can get the pages too. order-3 page can be steal by order-2 allocation

But at least, it has a high possibility to allocate order-3 page than reclaim order-2 pages.

Quoted 6 lines
Quoted 4 lines

Then, your patch makes continue to
reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck.

Task1 will wakeup kswapd again for order-3, so kswapd will reclaim order-3 very soon after the order-2 reclaim.

GFP_ATOMIC case doesn't wakeup kswapd.
When kswapd wakeup by order-3 depends on caller's retry. And this situation can be repeated in next turn.

We can't guarantee 100% Task-1's order-3 pages so I hope we should go way to reduce the problem as possible as we can.

Quoted 2 lines

--
Kind regards,
Minchan Kim

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#15 lore raw
Quoted 79 lines · Minchan Kim

Where is my mail?
I will resend lost content.

Quoted 75 lines · Minchan Kim
Quoted 51 lines · Shaohua Li
Quoted 50 lines · Minchan Kim
Quoted 49 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                          }
                  }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
          }
          finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages.

but even you reclaim order-3, you can't guarantee task1 can get the pages too. order-3 page can be steal by order-2 allocation

But at least, it has a high possibility to allocate order-3 page than reclaim order-2 pages.

Quoted 6 lines
Quoted 4 lines

Then, your patch makes continue to
reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck.

Task1 will wakeup kswapd again for order-3, so kswapd will reclaim order-3 very soon after the order-2 reclaim.

GFP_ATOMIC case doesn't wakeup kswapd.
When kswapd wakeup by order-3 depends on caller's retry. And this situation can be repeated in next turn.

GFP_ATOMIC does wakeup kswapd. It just doesn't wait on kswapd to do anything.

Quoted 26 lines
Quoted 12 lines

We can't guarantee 100% Task-1's order-3 pages so I hope we should go way to reduce the problem as possible as we can.

Quoted 2 lines

--
Kind regards,
Minchan Kim

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw
Quoted 76 lines · Mel Gorman
Quoted 75 lines · Minchan Kim

Where is my mail?
I will resend lost content.

Quoted 71 lines · Minchan Kim
Quoted 51 lines · Shaohua Li
Quoted 50 lines · Minchan Kim
Quoted 49 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 ? ? ? ? ? ? ? ? ? ? ? ? ? }
 ? ? ? ? ? ? ? ? ? }
 
- ? ? ? ? ? ? ? ? order = pgdat->kswapd_max_order;
+ ? ? ? ? ? ? ? ? order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 ? ? ? ? ? }
 ? ? ? ? ? finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't ? ?use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean
? ?zone_watermark_ok_safe(zone, order, high_wmark) return false. ? ?therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages.

but even you reclaim order-3, you can't guarantee task1 can get the pages too. order-3 page can be steal by order-2 allocation

But at least, it has a high possibility to allocate order-3 page than reclaim order-2 pages.

Quoted 6 lines
Quoted 4 lines

Then, your patch makes continue to
reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck.

Task1 will wakeup kswapd again for order-3, so kswapd will reclaim order-3 very soon after the order-2 reclaim.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

GFP_ATOMIC case doesn't wakeup kswapd.
When kswapd wakeup by order-3 depends on caller's retry. And this situation can be repeated in next turn.

GFP_ATOMIC does wakeup kswapd. It just doesn't wait on kswapd to do anything.

I mean GFP_ATOMIC doesn't do restart for waking up kswapd again in __alloc_pages_slowpath.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author Reviewed-by
#17 lore raw
In reply to Minchan Kim
Quoted 71 lines · Minchan Kim
Quoted 51 lines · Shaohua Li
Quoted 50 lines · Minchan Kim
Quoted 49 lines · Shaohua Li
Quoted 37 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
                          }
                  }
 
-                 order = pgdat->kswapd_max_order;
+                 order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
          }
          finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Quoted 6 lines

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.

why? it's just a possibility. Task1 might get its pages too. If Task1 doesn't get its pages, it will wakeup kswapd too with its order.

Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

For example, It assume tat Task1 continues to fail get the order-3 page of GFP_ATOMIC since other tasks continues to allocate order-2 pages so that they steal pages.

but even you reclaim order-3, you can't guarantee task1 can get the pages too. order-3 page can be steal by order-2 allocation

But at least, it has a high possibility to allocate order-3 page than reclaim order-2 pages.

Quoted 6 lines
Quoted 4 lines

Then, your patch makes continue to
reclaim order-2 page in this scenario. Task1 never get the order-3 pages if it doesn't have a merge luck.

Task1 will wakeup kswapd again for order-3, so kswapd will reclaim order-3 very soon after the order-2 reclaim.

Quoted 6 lines

GFP_ATOMIC case doesn't wakeup kswapd.
When kswapd wakeup by order-3 depends on caller's retry. And this situation can be repeated in next turn.

We can't guarantee 100% Task-1's order-3 pages so I hope we should go way to reduce the problem as possible as we can.

ok, I have no objection now.

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw
In reply to Shaohua Li
Quoted 4 lines
Quoted 2 lines

In addtion, new order is always less than old order in that context. so big order page reclaim makes much safe for low order pages.

big order page reclaim makes we have more chances to reclaim useful pages by lumpy, why it's safe?

Because some crappy driver try high order GFP_ATOMIC allocation and they often don't have enough failure handling.

Even though they have good allocation failure handling, network packet loss (wireless drivers are one of most big high order GFP_ATOMIC user) is usually big impact than page cache drop/re-readings.

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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw
In reply to Minchan Kim
Quoted 145 lines · Minchan Kim
Quoted 27 lines · KOSAKI Motohiro
Quoted 17 lines

T0: Task1 wakeup_kswapd(order=3)
T1: kswapd enters balance_pgdat
T2: Task2 wakeup_kswapd(order=2), because pages reclaimed by kswapd are used quickly
T3: kswapd exits balance_pgdat. kswapd will do check. Now new order=2, pgdat->kswapd_max_order will become 0, but order=3, if sleeping_prematurely, then order will become pgdat->kswapd_max_order(0), while at this time the order should 2
This isn't a big deal, but we do have a small window the order is wrong.

mm/vmscan.c +0 -0
index d31d7ce..15cd0d2 100644

mm/vmscan.c static int kswapd(void *p) · line 2455

Quoted 7 lines
mm/vmscan.c +1 -1
@@ -2450,7 +2450,7 @@ static int kswapd(void *p)
 				}
 			}
 
-			order = pgdat->kswapd_max_order;
+			order = max_t(unsigned long, new_order, pgdat->kswapd_max_order);
 		}
 		finish_wait(&pgdat->kswapd_wait, &wait);

Good catch!

Quoted 8 lines

But unfortunatelly, the code is not correct. At least, don't fit corrent design.

1) if "order < new_order" condition is false, we already decided to don't use new_order. So, we shouldn't use new_order after kswapd_try_to_sleep()
2) if sleeping_prematurely() return false, it probably mean zone_watermark_ok_safe(zone, order, high_wmark) return false. therefore, we have to retry reclaim by using old 'order' parameter.

Good catch, too.

In Shaohua's scenario, if Task1 gets the order-3 page after kswapd's reclaiming, it's no problem.
But if Task1 doesn't get the order-3 page and others used the order-3 page for Task1, Kswapd have to reclaim order-3 for Task1, again.
In addtion, new order is always less than old order in that context.
so big order page reclaim makes much safe for low order pages.

Quoted 5 lines

new patch is here.

Quoted 7 lines

From 8f436224219a1da01985fd9644e1307e7c4cb8c3 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Sun, 26 Dec 2010 21:10:55 +0900
Subject: [PATCH] vmscan: make kswapd use a correct order

If sleeping_prematurely() return false, It's a sign of retrying reclaim. So, we don't have to drop old order value.

I think this description isn't enough.

Quoted 5 lines

But could you see my below suggestion?

Quoted 56 lines
---
 mm/vmscan.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
mm/vmscan.c +7 -4
index 1fcadaf..f052a1a 100644
@@ -2364,13 +2364,13 @@ out:
 	return sc.nr_reclaimed;
 }
 
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+static int kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return 0;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2399,13 +2399,17 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		order = pgdat->kswapd_max_order;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
 		else
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+		order = max(order, pgdat->kswapd_max_order);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return order;
 }
 
 /*
@@ -2467,8 +2471,7 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			order = kswapd_try_to_sleep(pgdat, order);
 		}
 
 		ret = try_to_freeze();
Signature · 1 line
1.6.5.2

It might work well. but I don't like such a coding that kswapd_try_to_sleep's eturn value is order. It doesn't look good to me and even no comment. Hmm..

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

---
 mm/vmscan.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
mm/vmscan.c +0 -0
index 42a4859..e48a612 100644

mm/vmscan.c out: · line 2452

Quoted 7 lines
mm/vmscan.c +3 -1
@@ -2447,13 +2447,18 @@ out:
 	return sc.nr_reclaimed;
 }
 
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+/*
+ * Return true if we sleep enough. Othrewise, return false
+ */

s/Othrewise/Otherwise/

Maybe

mm/vmscan.c out: · line 2457

Quoted 5 lines
mm/vmscan.c +3 -0
+static bool kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
+	bool sleep = 0;
+

sleep is a boolean, it's true or false, not 0 or !0

The term "sleep" implies present or future tense - i.e. I am going to sleep or will go to sleep in the future. The event this variable cares about in the past so "slept" or finished_sleeping might be a more appropriate term. Sorry to be picky about the English but there is an important distinction here.

Quoted 28 lines
mm/vmscan.c +4 -1
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return sleep;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2482,6 +2487,7 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		sleep = 1;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
@@ -2489,6 +2495,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return sleep;
 }
 
 /*
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;

mm/vmscan.c static int kswapd(void *p) · line 2567

Quoted 10 lines
mm/vmscan.c +7 -2
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;

Ok, we lose the old order if we slept enough. That is fine because if we slept enough it implies that reclaiming at that order was no longer necessary.

This needs a repost with a full changelog explaining why order has to be preserved if kswapd fails to go to sleep. There will be merge difficulties with the series aimed at fixing Simon's problem but it's unavoidable. Rebasing on top of my series isn't an option as I'm still patching against mainline until that issue is resolved.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw
Quoted 19 lines · Mel Gorman
Quoted 18 lines · Minchan Kim

How about this?
If you want it, feel free to use it.
If you insist on your coding style, I don't have any objection. Then add My Reviewed-by.

---
 mm/vmscan.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
mm/vmscan.c +0 -0
index 42a4859..e48a612 100644
@@ -2447,13 +2447,18 @@ out:
 	return sc.nr_reclaimed;
 }
 
Quoted 8 lines

mm/vmscan.c out: · line 2452

Quoted 4 lines
mm/vmscan.c +3 -1
-static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+/*
+ * Return true if we sleep enough. Othrewise, return false
+ */

s/Othrewise/Otherwise/

Maybe

Will fix.

Quoted 8 lines

mm/vmscan.c out: · line 2457

Quoted 6 lines
mm/vmscan.c +3 -0
+static bool kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 {
 	long remaining = 0;
+	bool sleep = 0;
+

sleep is a boolean, it's true or false, not 0 or !0

I was out of my mind. :(

Quoted 5 lines

The term "sleep" implies present or future tense - i.e. I am going to sleep or will go to sleep in the future. The event this variable cares about in the past so "slept" or finished_sleeping might be a more appropriate term. Sorry to be picky about the English but there is an important distinction here.

Never mind. You pointed a very important thing.
Non-native speaker like me always suffer from writing some comment or naming variable name so such a point can help very much.

It's a very desirable, I think.

Quoted 44 lines
Quoted 29 lines
mm/vmscan.c +4 -1
 	DEFINE_WAIT(wait);
 
 	if (freezing(current) || kthread_should_stop())
-		return;
+		return sleep;
 
 	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 
@@ -2482,6 +2487,7 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
 		schedule();
 		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+		sleep = 1;
 	} else {
 		if (remaining)
 			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
@@ -2489,6 +2495,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
 			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
 	}
 	finish_wait(&pgdat->kswapd_wait, &wait);
+
+	return sleep;
 }
 
 /*
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;

mm/vmscan.c static int kswapd(void *p) · line 2567

Quoted 10 lines
mm/vmscan.c +7 -2
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;

Ok, we lose the old order if we slept enough. That is fine because if we slept enough it implies that reclaiming at that order was no longer necessary.

Quoted 5 lines

This needs a repost with a full changelog explaining why order has to be preserved if kswapd fails to go to sleep. There will be merge difficulties with the series aimed at fixing Simon's problem but it's unavoidable. Rebasing on top of my series isn't an option as I'm still patching against mainline until that issue is resolved.

So what's your point? Do you want me to send this patch alone regardless of your series for Simon's problem?

Thanks for the review, Mel.

Quoted 5 lines
Signature · 4 lines
-- 
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw
Quoted 18 lines · Minchan Kim
Quoted 18 lines

mm/vmscan.c static int kswapd(void *p) · line 2567

Quoted 13 lines
mm/vmscan.c +7 -2
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;

Ok, we lose the old order if we slept enough. That is fine because if we slept enough it implies that reclaiming at that order was no longer necessary.

Quoted 7 lines
Quoted 5 lines

This needs a repost with a full changelog explaining why order has to be preserved if kswapd fails to go to sleep. There will be merge difficulties with the series aimed at fixing Simon's problem but it's unavoidable. Rebasing on top of my series isn't an option as I'm still patching against mainline until that issue is resolved.

So what's your point?

Only point was to comment "I think this part of the patch is fine".

Quoted 3 lines

Do you want me to send this patch alone
regardless of your series for Simon's problem?

Yes, because I do not believe the problems are directly related. When/if I get something working with Simon, I'll backport your patch on top of it for testing by him just in case but I don't think it'll affect him.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw
Quoted 29 lines · Mel Gorman
Quoted 18 lines · Minchan Kim
Quoted 18 lines

mm/vmscan.c static int kswapd(void *p) · line 2567

Quoted 13 lines
mm/vmscan.c +7 -2
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;

Ok, we lose the old order if we slept enough. That is fine because if we slept enough it implies that reclaiming at that order was no longer necessary.

Quoted 7 lines
Quoted 5 lines

This needs a repost with a full changelog explaining why order has to be preserved if kswapd fails to go to sleep. There will be merge difficulties with the series aimed at fixing Simon's problem but it's unavoidable. Rebasing on top of my series isn't an option as I'm still patching against mainline until that issue is resolved.

So what's your point?

Only point was to comment "I think this part of the patch is fine".

Quoted 7 lines
Quoted 3 lines

Do you want me to send this patch alone
regardless of your series for Simon's problem?

Yes, because I do not believe the problems are directly related. When/if I get something working with Simon, I'll backport your patch on top of it for testing by him just in case but I don't think it'll affect him.

We could test this and your patch together, no? Your patch definitely fixed the case for us where kswapd would just run all day long, throwing out everything while trying to reach the order-3 watermark in zone Normal while order-0 page cache allocations were splitting it back out again.

However, the subject of my original post was to do with too much free memory and swap, which is still occurring:

	http://0x.ca/sim/ref/2.6.36/memory_mel_patch_week.png

But this is still occurring even if I tell slub to use only order-0 and order-1, and disable jumbo frames (which I did on another box, not this one). It may not be quite as bad, but I think the increase in free memory is just based on fragmentation that builds up over time. I don't have any long-running graphs of this yet, but I can see that pretty much all of the free memory always is order-0, and even a "while true; do sleep .01; done" is enough to make it throw out more order-0 while trying to make room for order-1 task_struct allocations.

Maybe some pattern in the way that pages are reclaimed while they are being allocated is resulting in increasing fragmentation? All the boxes I see this on start out fine, but after a day or week they end up in swap and with lots of free memory.

Simon-

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw
Quoted 39 lines · Simon Kirby
Quoted 29 lines · Mel Gorman
Quoted 18 lines · Minchan Kim
Quoted 18 lines

mm/vmscan.c static int kswapd(void *p) · line 2567

Quoted 13 lines
mm/vmscan.c +7 -2
@@ -2550,8 +2558,13 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			kswapd_try_to_sleep(pgdat, order);
-			order = pgdat->kswapd_max_order;
+			/*
+			 * If we wake up after enough sleeping, let's
+			 * start new order. Otherwise, it was a premature
+			 * sleep so we keep going on.
+			 */
+			if (kswapd_try_to_sleep(pgdat, order))
+				order = pgdat->kswapd_max_order;

Ok, we lose the old order if we slept enough. That is fine because if we slept enough it implies that reclaiming at that order was no longer necessary.

Quoted 7 lines
Quoted 5 lines

This needs a repost with a full changelog explaining why order has to be preserved if kswapd fails to go to sleep. There will be merge difficulties with the series aimed at fixing Simon's problem but it's unavoidable. Rebasing on top of my series isn't an option as I'm still patching against mainline until that issue is resolved.

So what's your point?

Only point was to comment "I think this part of the patch is fine".

Quoted 7 lines
Quoted 3 lines

Do you want me to send this patch alone
regardless of your series for Simon's problem?

Yes, because I do not believe the problems are directly related. When/if I get something working with Simon, I'll backport your patch on top of it for testing by him just in case but I don't think it'll affect him.

Quoted 6 lines

We could test this and your patch together, no?
Your patch definitely
fixed the case for us where kswapd would just run all day long, throwing out everything while trying to reach the order-3 watermark in zone Normal while order-0 page cache allocations were splitting it back out again.

Ideally they would ultimately be tested together, but I'd really like to hear if the 5 patch series I posted still prevents kswapd going crazy and if the "too much free memory" problem is affected. Minimally, fixing kswapd being awake is worthwhile.

Quoted 5 lines

However, the subject of my original post was to do with too much free memory and swap, which is still occurring:

	http://0x.ca/sim/ref/2.6.36/memory_mel_patch_week.png

Ok, we had been working on the assumption that kswapd staying awake was responsible for too much memory being free. If after the series is applied and working there is still too much free memory, we know there is an additional part to the problem.

Quoted 4 lines

But this is still occurring even if I tell slub to use only order-0 and order-1, and disable jumbo frames (which I did on another box, not this one). It may not be quite as bad, but I think the increase in free memory is just based on fragmentation that builds up over time.

Before you said SLUB was using only order-0 and order-1, I would have suspected lumpy reclaim. Without high-order allocations, fragmentation is not a problem and shouldn't be triggering a mass freeing of memory. can you confirm with perf that there is no other constant source of high-order allocations?

Quoted 6 lines

I don't
have any long-running graphs of this yet, but I can see that pretty much all of the free memory always is order-0, and even a "while true; do sleep .01; done" is enough to make it throw out more order-0 while trying to make room for order-1 task_struct allocations.

It would be semi-normal to throw out a few pages for order-1 task_struct allocations. Is your server fork-heavy? I would have guessed "no" as you are forcing a large number of forks with the while loop.

Quoted 5 lines

Maybe some pattern in the way that pages are reclaimed while they are being allocated is resulting in increasing fragmentation? All the boxes I see this on start out fine, but after a day or week they end up in swap and with lots of free memory.

Is there something like a big weekly backup task running that would be responsible for pushing a large amount of memory to swap that is never faulted back in again because it's unused?

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#24 lore raw
Quoted 21 lines · Mel Gorman
Quoted 13 lines · Simon Kirby
Quoted 10 lines · Mel Gorman

On Fri, Dec 03, 2010 at 12:35:26AM +0900, Minchan Kim wrote:

Only point was to comment "I think this part of the patch is fine".

Quoted 2 lines

Do you want me to send this patch alone
regardless of your series for Simon's problem?

Yes, because I do not believe the problems are directly related. When/if I get something working with Simon, I'll backport your patch on top of it for testing by him just in case but I don't think it'll affect him.

Quoted 6 lines

We could test this and your patch together, no?
Your patch definitely
fixed the case for us where kswapd would just run all day long, throwing out everything while trying to reach the order-3 watermark in zone Normal while order-0 page cache allocations were splitting it back out again.

Quoted 4 lines

Ideally they would ultimately be tested together, but I'd really like to hear if the 5 patch series I posted still prevents kswapd going crazy and if the "too much free memory" problem is affected. Minimally, fixing kswapd being awake is worthwhile.

Ok, we will try this version of your patches and see if anything changes. The previous version did stop kswapd from running continuously during daytime load, and made our SSD server useful, so I definitely like it. :)

Quoted 9 lines
Quoted 4 lines

However, the subject of my original post was to do with too much free memory and swap, which is still occurring:

	http://0x.ca/sim/ref/2.6.36/memory_mel_patch_week.png

Ok, we had been working on the assumption that kswapd staying awake was responsible for too much memory being free. If after the series is applied and working there is still too much free memory, we know there is an additional part to the problem.

This was part of the problem. kswapd was throwing so much out while trying to meet the watermark in zone Normal that the daemons had to keep being read back in from /dev/sda (non-ssd), and this ended up causing degraded performance.

Quoted 10 lines
Quoted 4 lines

But this is still occurring even if I tell slub to use only order-0 and order-1, and disable jumbo frames (which I did on another box, not this one). It may not be quite as bad, but I think the increase in free memory is just based on fragmentation that builds up over time.

Before you said SLUB was using only order-0 and order-1, I would have suspected lumpy reclaim. Without high-order allocations, fragmentation is not a problem and shouldn't be triggering a mass freeing of memory. can you confirm with perf that there is no other constant source of high-order allocations?

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change, but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

The original server I was posting graphs for has had no other vm tweaks, and so slub is still doing order-3 GFP_ATOMIC allocations from skb allocations.

By the way, I noticed slub seems to choose different maximum orders based on the memory size. You may be able to get your test box to issue the same GFP_ATOMIC order-3 allocations from skb allocations by making your sysfs files match these values:

[/sys/kernel/slab]# grep . kmalloc-??{,?,??}/order kmalloc-16/order:0
kmalloc-32/order:0
kmalloc-64/order:0
kmalloc-96/order:0
kmalloc-128/order:0
kmalloc-192/order:0
kmalloc-256/order:1
kmalloc-512/order:2
kmalloc-1024/order:3
kmalloc-2048/order:3
kmalloc-4096/order:3
kmalloc-8192/order:3

I suspect your kmalloc-1024 and kmalloc-2048 orders are less than 3 now?

Quoted 10 lines
Quoted 6 lines

I don't
have any long-running graphs of this yet, but I can see that pretty much all of the free memory always is order-0, and even a "while true; do sleep .01; done" is enough to make it throw out more order-0 while trying to make room for order-1 task_struct allocations.

It would be semi-normal to throw out a few pages for order-1 task_struct allocations. Is your server fork-heavy? I would have guessed "no" as you are forcing a large number of forks with the while loop.

No, the only things that cause forks on these servers usually are monitoring processes. According to munin, it averages under 3 forks per second.

Quoted 8 lines
Quoted 4 lines

Maybe some pattern in the way that pages are reclaimed while they are being allocated is resulting in increasing fragmentation? All the boxes I see this on start out fine, but after a day or week they end up in swap and with lots of free memory.

Is there something like a big weekly backup task running that would be responsible for pushing a large amount of memory to swap that is never faulted back in again because it's unused?

There are definitely pages that are leaking from dovecot or similar which can be swapped out and not swapped in again (you can see "apps" growing), but there are no tasks I can think of that would ever cause the system to be starved. The calls to pageout() seem to happen if sc.may_writepage is set, which seems to happen when it thinks it has scanned enough without making enough progress. Could this happen just from too much fragmentation?

The swapping seems to be at a slow but constant rate, so maybe it's happening just due to the way the types of allocations are biasing to Normal instead of DMA32, or vice-versa. Check out the latest memory graphs for the server running your original patch:

http://0x.ca/sim/ref/2.6.36/memory_mel_patch_dec4.png
http://0x.ca/sim/ref/2.6.36/zoneinfo_mel_patch_dec4
http://0x.ca/sim/ref/2.6.36/pagetypeinfo_mel_patch_dec4

Hmm, pagetypeinfo shows none or only a few of the pages in Normal are considered reclaimable...

Simon-

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw
Quoted 23 lines · Simon Kirby
Quoted 21 lines · Mel Gorman
Quoted 19 lines · Simon Kirby
Quoted 10 lines · Mel Gorman

On Fri, Dec 03, 2010 at 12:35:26AM +0900, Minchan Kim wrote:

Only point was to comment "I think this part of the patch is fine".

Quoted 2 lines

Do you want me to send this patch alone
regardless of your series for Simon's problem?

Yes, because I do not believe the problems are directly related. When/if I get something working with Simon, I'll backport your patch on top of it for testing by him just in case but I don't think it'll affect him.

We could test this and your patch together, no?
Your patch definitely
fixed the case for us where kswapd would just run all day long, throwing out everything while trying to reach the order-3 watermark in zone Normal while order-0 page cache allocations were splitting it back out again.

Quoted 9 lines
Quoted 4 lines

Ideally they would ultimately be tested together, but I'd really like to hear if the 5 patch series I posted still prevents kswapd going crazy and if the "too much free memory" problem is affected. Minimally, fixing kswapd being awake is worthwhile.

Ok, we will try this version of your patches and see if anything changes. The previous version did stop kswapd from running continuously during daytime load, and made our SSD server useful, so I definitely like it. :)

Good.

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

However, the subject of my original post was to do with too much free memory and swap, which is still occurring:

	http://0x.ca/sim/ref/2.6.36/memory_mel_patch_week.png

Ok, we had been working on the assumption that kswapd staying awake was responsible for too much memory being free. If after the series is applied and working there is still too much free memory, we know there is an additional part to the problem.

Quoted 5 lines

This was part of the problem. kswapd was throwing so much out while trying to meet the watermark in zone Normal that the daemons had to keep being read back in from /dev/sda (non-ssd), and this ended up causing degraded performance.

But there is still potentially two problems here. The first was kswapd throwing out everything in zone normal. Even when fixed, there is potentially still too many pages being thrown out. The situation might be improved but not repaired.

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines

But this is still occurring even if I tell slub to use only order-0 and order-1, and disable jumbo frames (which I did on another box, not this one). It may not be quite as bad, but I think the increase in free memory is just based on fragmentation that builds up over time.

Before you said SLUB was using only order-0 and order-1, I would have suspected lumpy reclaim. Without high-order allocations, fragmentation is not a problem and shouldn't be triggering a mass freeing of memory. can you confirm with perf that there is no other constant source of high-order allocations?

Quoted 13 lines

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change, but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

Ok, but it's still evidence that lumpy reclaim is still the problem here. This should be "fixed" by reclaim/compaction which has less impact and frees fewer pages than lumpy reclaim. If necessary, I can backport this to 2.6.36 for you to verify. There is little chance the series would be accepted into -stable but you'd at least know that 2.6.37 or 2.6.38 would behave as expected.

Quoted 23 lines

The original server I was posting graphs for has had no other vm tweaks, and so slub is still doing order-3 GFP_ATOMIC allocations from skb allocations.

By the way, I noticed slub seems to choose different maximum orders based on the memory size. You may be able to get your test box to issue the same GFP_ATOMIC order-3 allocations from skb allocations by making your sysfs files match these values:

[/sys/kernel/slab]# grep . kmalloc-??{,?,??}/order kmalloc-16/order:0
kmalloc-32/order:0
kmalloc-64/order:0
kmalloc-96/order:0
kmalloc-128/order:0
kmalloc-192/order:0
kmalloc-256/order:1
kmalloc-512/order:2
kmalloc-1024/order:3
kmalloc-2048/order:3
kmalloc-4096/order:3
kmalloc-8192/order:3

Quoted 2 lines

I suspect your kmalloc-1024 and kmalloc-2048 orders are less than 3 now?

I'm using slub_min_order=3 to force the larger allocations.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

I don't
have any long-running graphs of this yet, but I can see that pretty much all of the free memory always is order-0, and even a "while true; do sleep .01; done" is enough to make it throw out more order-0 while trying to make room for order-1 task_struct allocations.

Quoted 7 lines
Quoted 3 lines

It would be semi-normal to throw out a few pages for order-1 task_struct allocations. Is your server fork-heavy? I would have guessed "no" as you are forcing a large number of forks with the while loop.

No, the only things that cause forks on these servers usually are monitoring processes. According to munin, it averages under 3 forks per second.

Ok.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Maybe some pattern in the way that pages are reclaimed while they are being allocated is resulting in increasing fragmentation? All the boxes I see this on start out fine, but after a day or week they end up in swap and with lots of free memory.

Quoted 8 lines
Quoted 3 lines

Is there something like a big weekly backup task running that would be responsible for pushing a large amount of memory to swap that is never faulted back in again because it's unused?

There are definitely pages that are leaking from dovecot or similar which can be swapped out and not swapped in again (you can see "apps" growing), but there are no tasks I can think of that would ever cause the system to be starved.

So dovecot has a memory leak? As you say, this shouldn't starve the system but it's inevitable that swap usage will grow over time.

Quoted 5 lines

The calls to pageout() seem to happen if sc.may_writepage is set, which seems to happen when it thinks it has scanned enough without making enough progress. Could this happen just from too much fragmentation?

Not on its own but if too many pages have to be scanned due to fragmentation, it can get set.

Quoted 1 line

The swapping seems to be at a slow but constant rate, so maybe it's

I assume you mean swap usage is growing at a slow but constant rate?

Quoted 6 lines

happening just due to the way the types of allocations are biasing to Normal instead of DMA32, or vice-versa.
Check out the latest memory
graphs for the server running your original patch:

http://0x.ca/sim/ref/2.6.36/memory_mel_patch_dec4.png

Do you think the growth in swap usage is due to dovecot leaking?

Quoted 6 lines

http://0x.ca/sim/ref/2.6.36/zoneinfo_mel_patch_dec4
http://0x.ca/sim/ref/2.6.36/pagetypeinfo_mel_patch_dec4

Hmm, pagetypeinfo shows none or only a few of the pages in Normal are considered reclaimable...

Reclaimable in the context of pagetypeinfo means slab-reclaimable. The results imply that very few slab allocations are being satisified from the Normal zone or at least very few have been released recently.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#26 lore raw
Quoted 9 lines · Mel Gorman
Quoted 4 lines

This was part of the problem. kswapd was throwing so much out while trying to meet the watermark in zone Normal that the daemons had to keep being read back in from /dev/sda (non-ssd), and this ended up causing degraded performance.

But there is still potentially two problems here. The first was kswapd throwing out everything in zone normal. Even when fixed, there is potentially still too many pages being thrown out. The situation might be improved but not repaired.

Yes.

Quoted 19 lines
Quoted 6 lines
Quoted 5 lines

Before you said SLUB was using only order-0 and order-1, I would have suspected lumpy reclaim. Without high-order allocations, fragmentation is not a problem and shouldn't be triggering a mass freeing of memory. can you confirm with perf that there is no other constant source of high-order allocations?

Quoted 12 lines

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change, but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

Quoted 5 lines

Ok, but it's still evidence that lumpy reclaim is still the problem here. This should be "fixed" by reclaim/compaction which has less impact and frees fewer pages than lumpy reclaim. If necessary, I can backport this to 2.6.36 for you to verify. There is little chance the series would be accepted into -stable but you'd at least know that 2.6.37 or 2.6.38 would behave as expected.

Isn't lumpy reclaim supposed to _improve_ this situation by trying to free contiguous stuff rather than shooting aimlessly until contiguous pages appear? Or is there some other point to it? If this is the case, maybe the issue is that lumpy reclaim isn't happening soon enough, so it shoots around too much before it tries to look for lumpy stuff. In 2.6.3[67], set_lumpy_reclaim_mode() only sets lumpy mode if sc->order > PAGE_ALLOC_COSTLY_ORDER (>= 4), or if priority < DEF_PRIORITY - 2.

Also, try_to_compact_pages() bails without doing anything when order <= PAGE_ALLOC_COSTLY_ORDER, which is the order I'm seeing problems at. So, without further chanegs, I don't see how CONFIG_COMPACTION or 2.6.37 will make any difference, unless I'm missing some related 2.6.37 changes.

Quoted 7 lines
Quoted 4 lines

There are definitely pages that are leaking from dovecot or similar which can be swapped out and not swapped in again (you can see "apps" growing), but there are no tasks I can think of that would ever cause the system to be starved.

So dovecot has a memory leak? As you say, this shouldn't starve the system but it's inevitable that swap usage will grow over time.

Yeah, we just squashed what seemed to be the biggest leak in dovecot, so this should stop happening once we rebuild and restart everything.

Quoted 6 lines
Quoted 5 lines

The calls to pageout() seem to happen if sc.may_writepage is set, which seems to happen when it thinks it has scanned enough without making enough progress. Could this happen just from too much fragmentation?

Quoted 6 lines

Not on its own but if too many pages have to be scanned due to fragmentation, it can get set.

Quoted 1 line

The swapping seems to be at a slow but constant rate, so maybe it's

I assume you mean swap usage is growing at a slow but constant rate?

Yes.

Quoted 8 lines
Quoted 6 lines

happening just due to the way the types of allocations are biasing to Normal instead of DMA32, or vice-versa.
Check out the latest memory
graphs for the server running your original patch:

http://0x.ca/sim/ref/2.6.36/memory_mel_patch_dec4.png

Do you think the growth in swap usage is due to dovecot leaking?

I guess we'll find out shortly, with dovecot being fixed. :)

Quoted 10 lines
Quoted 6 lines

http://0x.ca/sim/ref/2.6.36/zoneinfo_mel_patch_dec4
http://0x.ca/sim/ref/2.6.36/pagetypeinfo_mel_patch_dec4

Hmm, pagetypeinfo shows none or only a few of the pages in Normal are considered reclaimable...

Reclaimable in the context of pagetypeinfo means slab-reclaimable. The results imply that very few slab allocations are being satisified from the Normal zone or at least very few have been released recently.

Hmm, ok.

Simon-

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw
Quoted 39 lines · Simon Kirby
Quoted 9 lines · Mel Gorman
Quoted 4 lines

This was part of the problem. kswapd was throwing so much out while trying to meet the watermark in zone Normal that the daemons had to keep being read back in from /dev/sda (non-ssd), and this ended up causing degraded performance.

But there is still potentially two problems here. The first was kswapd throwing out everything in zone normal. Even when fixed, there is potentially still too many pages being thrown out. The situation might be improved but not repaired.

Yes.

Quoted 19 lines
Quoted 6 lines
Quoted 5 lines

Before you said SLUB was using only order-0 and order-1, I would have suspected lumpy reclaim. Without high-order allocations, fragmentation is not a problem and shouldn't be triggering a mass freeing of memory. can you confirm with perf that there is no other constant source of high-order allocations?

Quoted 12 lines

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change, but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

Quoted 5 lines

Ok, but it's still evidence that lumpy reclaim is still the problem here. This should be "fixed" by reclaim/compaction which has less impact and frees fewer pages than lumpy reclaim. If necessary, I can backport this to 2.6.36 for you to verify. There is little chance the series would be accepted into -stable but you'd at least know that 2.6.37 or 2.6.38 would behave as expected.

Quoted 3 lines

Isn't lumpy reclaim supposed to _improve_ this situation by trying to free contiguous stuff rather than shooting aimlessly until contiguous pages appear?

For lower orders like order-1 and order-2, it reclaims randomly before using lumpy reclaim as the assumption is that these lower pages free naturally.

Quoted 3 lines

Or is there some other point to it? If this is the case, maybe the issue is that lumpy reclaim isn't happening soon enough, so it shoots around too much before it tries to look for lumpy stuff.

It used to happen sooner but it ran into latency problems.

Quoted 9 lines

In
2.6.3[67], set_lumpy_reclaim_mode() only sets lumpy mode if sc->order > PAGE_ALLOC_COSTLY_ORDER (>= 4), or if priority < DEF_PRIORITY - 2.

Also, try_to_compact_pages() bails without doing anything when order <= PAGE_ALLOC_COSTLY_ORDER, which is the order I'm seeing problems at. So, without further chanegs, I don't see how CONFIG_COMPACTION or 2.6.37 will make any difference, unless I'm missing some related 2.6.37 changes.

There is increasing pressure to use compaction for the lower orders as well. This problem is going to be added to the list of justifications :/

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

There are definitely pages that are leaking from dovecot or similar which can be swapped out and not swapped in again (you can see "apps" growing), but there are no tasks I can think of that would ever cause the system to be starved.

So dovecot has a memory leak? As you say, this shouldn't starve the system but it's inevitable that swap usage will grow over time.

Yeah, we just squashed what seemed to be the biggest leak in dovecot, so this should stop happening once we rebuild and restart everything.

Ok.

Quoted 20 lines
Quoted 6 lines
Quoted 5 lines

The calls to pageout() seem to happen if sc.may_writepage is set, which seems to happen when it thinks it has scanned enough without making enough progress. Could this happen just from too much fragmentation?

Quoted 6 lines

Not on its own but if too many pages have to be scanned due to fragmentation, it can get set.

Quoted 1 line

The swapping seems to be at a slow but constant rate, so maybe it's

I assume you mean swap usage is growing at a slow but constant rate?

Yes.

Quoted 5 lines
Quoted 5 lines

happening just due to the way the types of allocations are biasing to Normal instead of DMA32, or vice-versa.
Check out the latest memory
graphs for the server running your original patch:

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

http://0x.ca/sim/ref/2.6.36/memory_mel_patch_dec4.png

Do you think the growth in swap usage is due to dovecot leaking?

I guess we'll find out shortly, with dovecot being fixed. :)

Great.

Quoted 15 lines
Quoted 10 lines
Quoted 6 lines

http://0x.ca/sim/ref/2.6.36/zoneinfo_mel_patch_dec4
http://0x.ca/sim/ref/2.6.36/pagetypeinfo_mel_patch_dec4

Hmm, pagetypeinfo shows none or only a few of the pages in Normal are considered reclaimable...

Reclaimable in the context of pagetypeinfo means slab-reclaimable. The results imply that very few slab allocations are being satisified from the Normal zone or at least very few have been released recently.

Hmm, ok.

Simon-

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw
Quoted 29 lines · Mel Gorman
Quoted 28 lines · Simon Kirby
Quoted 4 lines · Mel Gorman

But there is still potentially two problems here. The first was kswapd throwing out everything in zone normal. Even when fixed, there is potentially still too many pages being thrown out. The situation might be improved but not repaired.

Yes.

Quoted 18 lines
Quoted 4 lines

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change,

Quoted 8 lines

but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

Ok, but it's still evidence that lumpy reclaim is still the problem here. This should be "fixed" by reclaim/compaction which has less impact and frees fewer pages than lumpy reclaim. If necessary, I can backport this to 2.6.36 for you to verify. There is little chance the series would be accepted into -stable but you'd at least know that 2.6.37 or 2.6.38 would behave as expected.

Quoted 7 lines
Quoted 3 lines

Isn't lumpy reclaim supposed to _improve_ this situation by trying to free contiguous stuff rather than shooting aimlessly until contiguous pages appear?

For lower orders like order-1 and order-2, it reclaims randomly before using lumpy reclaim as the assumption is that these lower pages free naturally.

Hmm.. We were looking were looking at some other servers' munin graphs, and I seem to notice a correlation between high allocation rates (eg, heavily loaded servers) and more memory being free. I am wondering if the problem isn't the choice of how to reclaim, but more an issue from concurrent allocation calls. Because (direct) reclaim isn't protected from other allocations, it can fight with allocations that split back up the orders, which might be increasing fragmentation.

The fragmentation and reaching watermarks does seem to be what is causing a larger amount to stay free, once it _gets_ fragmented...

I was thinking of ways that it could hold pages while reclaiming, and then free them all and allocate the request under a lock to avoid colliding with other allocations. I see shrink_active_list() almost seems to have something like this with l_hold, but nothing cares about watermarks down at that level. The inactive list goes through a separate routine, and only inactive uses lumpy reclaim.

Quoted 5 lines
Quoted 3 lines

Or is there some other point to it? If this is the case, maybe the issue is that lumpy reclaim isn't happening soon enough, so it shoots around too much before it tries to look for lumpy stuff.

It used to happen sooner but it ran into latency problems.

Latency from writeback or something? I wonder if it would be worth trying a cheap patch to try lumpy mode immediately, just to see how things change.

Quoted 11 lines
Quoted 8 lines

In
2.6.3[67], set_lumpy_reclaim_mode() only sets lumpy mode if sc->order > PAGE_ALLOC_COSTLY_ORDER (>= 4), or if priority < DEF_PRIORITY - 2.

Also, try_to_compact_pages() bails without doing anything when order <= PAGE_ALLOC_COSTLY_ORDER, which is the order I'm seeing problems at. So, without further chanegs, I don't see how CONFIG_COMPACTION or 2.6.37 will make any difference, unless I'm missing some related 2.6.37 changes.

There is increasing pressure to use compaction for the lower orders as well. This problem is going to be added to the list of justifications :/

I figured perhaps this was skipped due to being expensive, or else why wouldn't it just always happen for non-zero orders. I do see a lot of servers with 200,000 free order-0 pages and almost no order-1 or anything bigger, so maybe this could help. I could try to modify the test in try_to_compact_pages() to if (!order || !may_enter_fs || !may_perform_io).

Simon-

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#29 lore raw
Quoted 39 lines · Simon Kirby
Quoted 29 lines · Mel Gorman
Quoted 28 lines · Simon Kirby
Quoted 4 lines · Mel Gorman

But there is still potentially two problems here. The first was kswapd throwing out everything in zone normal. Even when fixed, there is potentially still too many pages being thrown out. The situation might be improved but not repaired.

Yes.

Quoted 18 lines
Quoted 4 lines

Let me clarify: On _another_ box, with 2.6.36 but without your patches and without as much load or SSD devices, I forced slub to use order-0 except where order-1 was absolutely necessary (objects > 4096 bytes), just to see what impact this had on free memory. There was a change,

Quoted 8 lines

but still lots of memory left free. I was trying to avoid confusion by posting graphs from different machines, but here is that one just as a
reference: http://0x.ca/sim/ref/2.6.36/memory_stor25r_week.png
(I made the slub order adjustment on Tuesday, November 30th.) The spikes are actually from mail nightly expunge/purge runs. It seems that minimizing the slub orders did remove the large free spike that was happening during mailbox compaction runs (nightly), and overall there was a bit more memory used on average, but it definitely didn't "fix" it.

Ok, but it's still evidence that lumpy reclaim is still the problem here. This should be "fixed" by reclaim/compaction which has less impact and frees fewer pages than lumpy reclaim. If necessary, I can backport this to 2.6.36 for you to verify. There is little chance the series would be accepted into -stable but you'd at least know that 2.6.37 or 2.6.38 would behave as expected.

Quoted 7 lines
Quoted 3 lines

Isn't lumpy reclaim supposed to _improve_ this situation by trying to free contiguous stuff rather than shooting aimlessly until contiguous pages appear?

For lower orders like order-1 and order-2, it reclaims randomly before using lumpy reclaim as the assumption is that these lower pages free naturally.

Quoted 5 lines

Hmm.. We were looking were looking at some other servers' munin graphs, and I seem to notice a correlation between high allocation rates (eg, heavily loaded servers) and more memory being free. I am wondering if the problem isn't the choice of how to reclaim, but more an issue from concurrent allocation calls.

It could be both. With many parallel allocators reclaiming order-0 pages, significantly more memory would be freed than necessary.

Quoted 4 lines

Because (direct) reclaim isn't protected
from other allocations, it can fight with allocations that split back up the orders, which might be increasing fragmentation.

It might but the dominant problem is likely to be a larger number of order-0 pages being reclaimed rather than this known-to-exist race occuring.

Quoted 6 lines

The fragmentation and reaching watermarks does seem to be what is causing a larger amount to stay free, once it _gets_ fragmented...

I was thinking of ways that it could hold pages while reclaiming, and then free them all and allocate the request under a lock to avoid colliding with other allocations.

This has been tried a few times in different implementations but it almost always ended up increasing the number of pages reclaimed (because more pages get isolated) and increased allocation ltency. It could be tried again of course.

Quoted 5 lines

I see shrink_active_list() almost
seems to have something like this with l_hold, but nothing cares about watermarks down at that level. The inactive list goes through a separate routine, and only inactive uses lumpy reclaim.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Or is there some other point to it? If this is the case, maybe the issue is that lumpy reclaim isn't happening soon enough, so it shoots around too much before it tries to look for lumpy stuff.

It used to happen sooner but it ran into latency problems.

Latency from writeback or something?

Writeback and deactivating active pages.

Quoted 4 lines

I wonder if it would be worth
trying a cheap patch to try lumpy mode immediately, just to see how things change.

If the problem persists, it can be considered but lumpy mode is delayed on purpose. Maybe that decision was wrong.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

In
2.6.3[67], set_lumpy_reclaim_mode() only sets lumpy mode if sc->order > PAGE_ALLOC_COSTLY_ORDER (>= 4), or if priority < DEF_PRIORITY - 2.

Also, try_to_compact_pages() bails without doing anything when order <= PAGE_ALLOC_COSTLY_ORDER, which is the order I'm seeing problems at. So, without further chanegs, I don't see how CONFIG_COMPACTION or 2.6.37 will make any difference, unless I'm missing some related 2.6.37 changes.

Quoted 5 lines
Quoted 2 lines

There is increasing pressure to use compaction for the lower orders as well. This problem is going to be added to the list of justifications :/

I figured perhaps this was skipped due to being expensive, or else why wouldn't it just always happen for non-zero orders.

No, it was skipped because it was a lot of new code and a number of bugs in page migration had to be ironed out. If it was only going to be activated for huge page allocation to start with, people were reasonably happy. It is a bit expensive as well as the scanning rates for it are astonishinly high but it should still be cheaper than reclaiming and paging back in.

Quoted 5 lines

I do see a lot of
servers with 200,000 free order-0 pages and almost no order-1 or anything bigger, so maybe this could help. I could try to modify the test in try_to_compact_pages() to if (!order || !may_enter_fs || !may_perform_io).

You could but I reckon the reclaim/compaction patches that are currently in mmotm in combination with allowing compaction for lower orders will be what happens longer term.

Signature · 10 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>