All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cleanup kswapd()
@ 2010-11-14  9:05 ` KOSAKI Motohiro
  0 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-14  9:05 UTC (permalink / raw)
  To: Mel Gorman, LKML, linux-mm, Andrew Morton; +Cc: kosaki.motohiro


Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8cc90d5..82ffe5f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,42 @@ out:
 	return sc.nr_reclaimed;
 }
 
+void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a
+	 * premature sleep. If not, then go fully
+	 * to sleep until explicitly woken up
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2418,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2450,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,39 +2459,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2




^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH] cleanup kswapd()
@ 2010-11-14  9:05 ` KOSAKI Motohiro
  0 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-14  9:05 UTC (permalink / raw)
  To: Mel Gorman, LKML, linux-mm, Andrew Morton; +Cc: kosaki.motohiro


Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8cc90d5..82ffe5f 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,42 @@ out:
 	return sc.nr_reclaimed;
 }
 
+void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a
+	 * premature sleep. If not, then go fully
+	 * to sleep until explicitly woken up
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2418,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2450,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,39 +2459,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2



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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
  2010-11-14  9:05 ` KOSAKI Motohiro
@ 2010-11-14 11:03   ` Jesper Juhl
  -1 siblings, 0 replies; 14+ messages in thread
From: Jesper Juhl @ 2010-11-14 11:03 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: Mel Gorman, LKML, linux-mm, Andrew Morton

On Sun, 14 Nov 2010, KOSAKI Motohiro wrote:

> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 8cc90d5..82ffe5f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2364,6 +2364,42 @@ out:
>  	return sc.nr_reclaimed;
>  }
>  
> +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)

Shouldn't this be

  static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)

??


-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
@ 2010-11-14 11:03   ` Jesper Juhl
  0 siblings, 0 replies; 14+ messages in thread
From: Jesper Juhl @ 2010-11-14 11:03 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: Mel Gorman, LKML, linux-mm, Andrew Morton

On Sun, 14 Nov 2010, KOSAKI Motohiro wrote:

> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 8cc90d5..82ffe5f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2364,6 +2364,42 @@ out:
>  	return sc.nr_reclaimed;
>  }
>  
> +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)

Shouldn't this be

  static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)

??


-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
  2010-11-14 11:03   ` Jesper Juhl
@ 2010-11-15  0:27     ` KOSAKI Motohiro
  -1 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-15  0:27 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: kosaki.motohiro, Mel Gorman, LKML, linux-mm, Andrew Morton

> On Sun, 14 Nov 2010, KOSAKI Motohiro wrote:
> 
> > 
> > Currently, kswapd() function has deeper nest and it slightly harder to
> > read. cleanup it.
> > 
> > Cc: Mel Gorman <mel@csn.ul.ie>
> > Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > ---
> >  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
> >  1 files changed, 38 insertions(+), 33 deletions(-)
> > 
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 8cc90d5..82ffe5f 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -2364,6 +2364,42 @@ out:
> >  	return sc.nr_reclaimed;
> >  }
> >  
> > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> 
> Shouldn't this be
> 
>   static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> 
> ??

Right. thank you.
I'll respin.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
@ 2010-11-15  0:27     ` KOSAKI Motohiro
  0 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-15  0:27 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: kosaki.motohiro, Mel Gorman, LKML, linux-mm, Andrew Morton

> On Sun, 14 Nov 2010, KOSAKI Motohiro wrote:
> 
> > 
> > Currently, kswapd() function has deeper nest and it slightly harder to
> > read. cleanup it.
> > 
> > Cc: Mel Gorman <mel@csn.ul.ie>
> > Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> > ---
> >  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
> >  1 files changed, 38 insertions(+), 33 deletions(-)
> > 
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 8cc90d5..82ffe5f 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -2364,6 +2364,42 @@ out:
> >  	return sc.nr_reclaimed;
> >  }
> >  
> > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> 
> Shouldn't this be
> 
>   static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> 
> ??

Right. thank you.
I'll respin.




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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
  2010-11-15  0:27     ` KOSAKI Motohiro
@ 2010-11-15  1:37       ` KOSAKI Motohiro
  -1 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-15  1:37 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: kosaki.motohiro, Jesper Juhl, Mel Gorman, LKML, linux-mm, Andrew Morton

> Right. thank you.
> I'll respin.

Done.



>From a29f0f5b780170fc26eb9210df03ed974aad8362 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Date: Fri, 3 Dec 2010 10:48:41 +0900
Subject: [PATCH] factor out kswapd sleeping logic from kswapd()

Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8cc90d5..3ee33a8 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,42 @@ out:
 	return sc.nr_reclaimed;
 }
 
+static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a
+	 * premature sleep. If not, then go fully
+	 * to sleep until explicitly woken up
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2418,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2450,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,39 +2459,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2






^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
@ 2010-11-15  1:37       ` KOSAKI Motohiro
  0 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-15  1:37 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: Jesper Juhl, Mel Gorman, LKML, linux-mm, Andrew Morton

> Right. thank you.
> I'll respin.

Done.



From a29f0f5b780170fc26eb9210df03ed974aad8362 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Date: Fri, 3 Dec 2010 10:48:41 +0900
Subject: [PATCH] factor out kswapd sleeping logic from kswapd()

Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8cc90d5..3ee33a8 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,42 @@ out:
 	return sc.nr_reclaimed;
 }
 
+static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a
+	 * premature sleep. If not, then go fully
+	 * to sleep until explicitly woken up
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2418,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2450,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,39 +2459,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2





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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
  2010-11-14  9:05 ` KOSAKI Motohiro
@ 2010-11-15  9:42   ` Mel Gorman
  -1 siblings, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2010-11-15  9:42 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: LKML, linux-mm, Andrew Morton

On Sun, Nov 14, 2010 at 06:05:26PM +0900, KOSAKI Motohiro wrote:
> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 8cc90d5..82ffe5f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2364,6 +2364,42 @@ out:
>  	return sc.nr_reclaimed;
>  }
>  
> +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> +{

As pointed out elsewhere, this should be static.

> +	long remaining = 0;
> +	DEFINE_WAIT(wait);
> +
> +	if (freezing(current) || kthread_should_stop())
> +		return;
> +
> +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> +
> +	/* Try to sleep for a short interval */
> +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> +		remaining = schedule_timeout(HZ/10);
> +		finish_wait(&pgdat->kswapd_wait, &wait);
> +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> +	}
> +
> +	/*
> +	 * After a short sleep, check if it was a
> +	 * premature sleep. If not, then go fully
> +	 * to sleep until explicitly woken up
> +	 */

Very minor but that comment should now fit on fewer lines.

> +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> +		schedule();
> +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);

I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
called. I do not believe it has been picked up by Andrew but it if is,
the patches will conflict. The resolution will be obvious but you may
need to respin this patch if the comment patch gets picked up in mmotm.

Otherwise, I see no problems.

> +	} else {
> +		if (remaining)
> +			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
> +		else
> +			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
> +	}
> +	finish_wait(&pgdat->kswapd_wait, &wait);
> +}
> +
>  /*
>   * The background pageout daemon, started as a kernel thread
>   * from the init process.
> @@ -2382,7 +2418,7 @@ static int kswapd(void *p)
>  	unsigned long order;
>  	pg_data_t *pgdat = (pg_data_t*)p;
>  	struct task_struct *tsk = current;
> -	DEFINE_WAIT(wait);
> +
>  	struct reclaim_state reclaim_state = {
>  		.reclaimed_slab = 0,
>  	};
> @@ -2414,7 +2450,6 @@ static int kswapd(void *p)
>  		unsigned long new_order;
>  		int ret;
>  
> -		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
>  		new_order = pgdat->kswapd_max_order;
>  		pgdat->kswapd_max_order = 0;
>  		if (order < new_order) {
> @@ -2424,39 +2459,9 @@ static int kswapd(void *p)
>  			 */
>  			order = new_order;
>  		} else {
> -			if (!freezing(current) && !kthread_should_stop()) {
> -				long remaining = 0;
> -
> -				/* Try to sleep for a short interval */
> -				if (!sleeping_prematurely(pgdat, order, remaining)) {
> -					remaining = schedule_timeout(HZ/10);
> -					finish_wait(&pgdat->kswapd_wait, &wait);
> -					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> -				}
> -
> -				/*
> -				 * After a short sleep, check if it was a
> -				 * premature sleep. If not, then go fully
> -				 * to sleep until explicitly woken up
> -				 */
> -				if (!sleeping_prematurely(pgdat, order, remaining)) {
> -					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> -					set_pgdat_percpu_threshold(pgdat,
> -						calculate_normal_threshold);
> -					schedule();
> -					set_pgdat_percpu_threshold(pgdat,
> -						calculate_pressure_threshold);
> -				} else {
> -					if (remaining)
> -						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
> -					else
> -						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
> -				}
> -			}
> -
> +			kswapd_try_to_sleep(pgdat, order);
>  			order = pgdat->kswapd_max_order;
>  		}
> -		finish_wait(&pgdat->kswapd_wait, &wait);
>  
>  		ret = try_to_freeze();
>  		if (kthread_should_stop())
> -- 
> 1.6.5.2
> 
> 
> 

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] cleanup kswapd()
@ 2010-11-15  9:42   ` Mel Gorman
  0 siblings, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2010-11-15  9:42 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: LKML, linux-mm, Andrew Morton

On Sun, Nov 14, 2010 at 06:05:26PM +0900, KOSAKI Motohiro wrote:
> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> ---
>  mm/vmscan.c |   71 +++++++++++++++++++++++++++++++---------------------------
>  1 files changed, 38 insertions(+), 33 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 8cc90d5..82ffe5f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2364,6 +2364,42 @@ out:
>  	return sc.nr_reclaimed;
>  }
>  
> +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> +{

As pointed out elsewhere, this should be static.

> +	long remaining = 0;
> +	DEFINE_WAIT(wait);
> +
> +	if (freezing(current) || kthread_should_stop())
> +		return;
> +
> +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> +
> +	/* Try to sleep for a short interval */
> +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> +		remaining = schedule_timeout(HZ/10);
> +		finish_wait(&pgdat->kswapd_wait, &wait);
> +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> +	}
> +
> +	/*
> +	 * After a short sleep, check if it was a
> +	 * premature sleep. If not, then go fully
> +	 * to sleep until explicitly woken up
> +	 */

Very minor but that comment should now fit on fewer lines.

> +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> +		schedule();
> +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);

I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
called. I do not believe it has been picked up by Andrew but it if is,
the patches will conflict. The resolution will be obvious but you may
need to respin this patch if the comment patch gets picked up in mmotm.

Otherwise, I see no problems.

> +	} else {
> +		if (remaining)
> +			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
> +		else
> +			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
> +	}
> +	finish_wait(&pgdat->kswapd_wait, &wait);
> +}
> +
>  /*
>   * The background pageout daemon, started as a kernel thread
>   * from the init process.
> @@ -2382,7 +2418,7 @@ static int kswapd(void *p)
>  	unsigned long order;
>  	pg_data_t *pgdat = (pg_data_t*)p;
>  	struct task_struct *tsk = current;
> -	DEFINE_WAIT(wait);
> +
>  	struct reclaim_state reclaim_state = {
>  		.reclaimed_slab = 0,
>  	};
> @@ -2414,7 +2450,6 @@ static int kswapd(void *p)
>  		unsigned long new_order;
>  		int ret;
>  
> -		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
>  		new_order = pgdat->kswapd_max_order;
>  		pgdat->kswapd_max_order = 0;
>  		if (order < new_order) {
> @@ -2424,39 +2459,9 @@ static int kswapd(void *p)
>  			 */
>  			order = new_order;
>  		} else {
> -			if (!freezing(current) && !kthread_should_stop()) {
> -				long remaining = 0;
> -
> -				/* Try to sleep for a short interval */
> -				if (!sleeping_prematurely(pgdat, order, remaining)) {
> -					remaining = schedule_timeout(HZ/10);
> -					finish_wait(&pgdat->kswapd_wait, &wait);
> -					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> -				}
> -
> -				/*
> -				 * After a short sleep, check if it was a
> -				 * premature sleep. If not, then go fully
> -				 * to sleep until explicitly woken up
> -				 */
> -				if (!sleeping_prematurely(pgdat, order, remaining)) {
> -					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> -					set_pgdat_percpu_threshold(pgdat,
> -						calculate_normal_threshold);
> -					schedule();
> -					set_pgdat_percpu_threshold(pgdat,
> -						calculate_pressure_threshold);
> -				} else {
> -					if (remaining)
> -						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
> -					else
> -						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
> -				}
> -			}
> -
> +			kswapd_try_to_sleep(pgdat, order);
>  			order = pgdat->kswapd_max_order;
>  		}
> -		finish_wait(&pgdat->kswapd_wait, &wait);
>  
>  		ret = try_to_freeze();
>  		if (kthread_should_stop())
> -- 
> 1.6.5.2
> 
> 
> 

-- 
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 majordomo@kvack.org.  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:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] factor out kswapd sleeping logic from kswapd()
  2010-11-15  9:42   ` Mel Gorman
@ 2010-11-16  6:07     ` KOSAKI Motohiro
  -1 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-16  6:07 UTC (permalink / raw)
  To: Mel Gorman; +Cc: kosaki.motohiro, LKML, linux-mm, Andrew Morton

> > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> > +{
> 
> As pointed out elsewhere, this should be static.

Fixed.


> > +	long remaining = 0;
> > +	DEFINE_WAIT(wait);
> > +
> > +	if (freezing(current) || kthread_should_stop())
> > +		return;
> > +
> > +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > +
> > +	/* Try to sleep for a short interval */
> > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > +		remaining = schedule_timeout(HZ/10);
> > +		finish_wait(&pgdat->kswapd_wait, &wait);
> > +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > +	}
> > +
> > +	/*
> > +	 * After a short sleep, check if it was a
> > +	 * premature sleep. If not, then go fully
> > +	 * to sleep until explicitly woken up
> > +	 */
> 
> Very minor but that comment should now fit on fewer lines.

Thanks, fixed.


> > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> > +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> > +		schedule();
> > +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
> 
> I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
> called. I do not believe it has been picked up by Andrew but it if is,
> the patches will conflict. The resolution will be obvious but you may
> need to respin this patch if the comment patch gets picked up in mmotm.
> 
> Otherwise, I see no problems.

OK, I've rebased the patch on top your comment patch. 



>From 1bd232713d55f033676f80cc7451ff83d4483884 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Date: Mon, 6 Dec 2010 20:44:27 +0900
Subject: [PATCH] factor out kswapd sleeping logic from kswapd()

Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   92 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 33994b7..cd07b97 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,50 @@ out:
 	return sc.nr_reclaimed;
 }
 
+static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a premature sleep. If not, then
+	 * go fully to sleep until explicitly woken up.
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+
+		/*
+		 * vmstat counters are not perfectly accurate and the estimated
+		 * value for counters such as NR_FREE_PAGES can deviate from the
+		 * true value by nr_online_cpus * threshold. To avoid the zone
+		 * watermarks being breached while under pressure, we reduce the
+		 * per-cpu vmstat threshold while kswapd is awake and restore
+		 * them before going back to sleep.
+		 */
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2426,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2458,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,52 +2467,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-
-					/*
-					 * vmstat counters are not perfectly
-					 * accurate and the estimated value
-					 * for counters such as NR_FREE_PAGES
-					 * can deviate from the true value by
-					 * nr_online_cpus * threshold. To
-					 * avoid the zone watermarks being
-					 * breached while under pressure, we
-					 * reduce the per-cpu vmstat threshold
-					 * while kswapd is awake and restore
-					 * them before going back to sleep.
-					 */
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2




^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3] factor out kswapd sleeping logic from kswapd()
@ 2010-11-16  6:07     ` KOSAKI Motohiro
  0 siblings, 0 replies; 14+ messages in thread
From: KOSAKI Motohiro @ 2010-11-16  6:07 UTC (permalink / raw)
  To: Mel Gorman; +Cc: kosaki.motohiro, LKML, linux-mm, Andrew Morton

> > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> > +{
> 
> As pointed out elsewhere, this should be static.

Fixed.


> > +	long remaining = 0;
> > +	DEFINE_WAIT(wait);
> > +
> > +	if (freezing(current) || kthread_should_stop())
> > +		return;
> > +
> > +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > +
> > +	/* Try to sleep for a short interval */
> > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > +		remaining = schedule_timeout(HZ/10);
> > +		finish_wait(&pgdat->kswapd_wait, &wait);
> > +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > +	}
> > +
> > +	/*
> > +	 * After a short sleep, check if it was a
> > +	 * premature sleep. If not, then go fully
> > +	 * to sleep until explicitly woken up
> > +	 */
> 
> Very minor but that comment should now fit on fewer lines.

Thanks, fixed.


> > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> > +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> > +		schedule();
> > +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
> 
> I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
> called. I do not believe it has been picked up by Andrew but it if is,
> the patches will conflict. The resolution will be obvious but you may
> need to respin this patch if the comment patch gets picked up in mmotm.
> 
> Otherwise, I see no problems.

OK, I've rebased the patch on top your comment patch. 



From 1bd232713d55f033676f80cc7451ff83d4483884 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Date: Mon, 6 Dec 2010 20:44:27 +0900
Subject: [PATCH] factor out kswapd sleeping logic from kswapd()

Currently, kswapd() function has deeper nest and it slightly harder to
read. cleanup it.

Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
---
 mm/vmscan.c |   92 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 33994b7..cd07b97 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2364,6 +2364,50 @@ out:
 	return sc.nr_reclaimed;
 }
 
+static void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
+{
+	long remaining = 0;
+	DEFINE_WAIT(wait);
+
+	if (freezing(current) || kthread_should_stop())
+		return;
+
+	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+
+	/* Try to sleep for a short interval */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		remaining = schedule_timeout(HZ/10);
+		finish_wait(&pgdat->kswapd_wait, &wait);
+		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
+	}
+
+	/*
+	 * After a short sleep, check if it was a premature sleep. If not, then
+	 * go fully to sleep until explicitly woken up.
+	 */
+	if (!sleeping_prematurely(pgdat, order, remaining)) {
+		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
+
+		/*
+		 * vmstat counters are not perfectly accurate and the estimated
+		 * value for counters such as NR_FREE_PAGES can deviate from the
+		 * true value by nr_online_cpus * threshold. To avoid the zone
+		 * watermarks being breached while under pressure, we reduce the
+		 * per-cpu vmstat threshold while kswapd is awake and restore
+		 * them before going back to sleep.
+		 */
+		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
+		schedule();
+		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
+	} else {
+		if (remaining)
+			count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
+		else
+			count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
+	}
+	finish_wait(&pgdat->kswapd_wait, &wait);
+}
+
 /*
  * The background pageout daemon, started as a kernel thread
  * from the init process.
@@ -2382,7 +2426,7 @@ static int kswapd(void *p)
 	unsigned long order;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
-	DEFINE_WAIT(wait);
+
 	struct reclaim_state reclaim_state = {
 		.reclaimed_slab = 0,
 	};
@@ -2414,7 +2458,6 @@ static int kswapd(void *p)
 		unsigned long new_order;
 		int ret;
 
-		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
 		new_order = pgdat->kswapd_max_order;
 		pgdat->kswapd_max_order = 0;
 		if (order < new_order) {
@@ -2424,52 +2467,9 @@ static int kswapd(void *p)
 			 */
 			order = new_order;
 		} else {
-			if (!freezing(current) && !kthread_should_stop()) {
-				long remaining = 0;
-
-				/* Try to sleep for a short interval */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					remaining = schedule_timeout(HZ/10);
-					finish_wait(&pgdat->kswapd_wait, &wait);
-					prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
-				}
-
-				/*
-				 * After a short sleep, check if it was a
-				 * premature sleep. If not, then go fully
-				 * to sleep until explicitly woken up
-				 */
-				if (!sleeping_prematurely(pgdat, order, remaining)) {
-					trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
-
-					/*
-					 * vmstat counters are not perfectly
-					 * accurate and the estimated value
-					 * for counters such as NR_FREE_PAGES
-					 * can deviate from the true value by
-					 * nr_online_cpus * threshold. To
-					 * avoid the zone watermarks being
-					 * breached while under pressure, we
-					 * reduce the per-cpu vmstat threshold
-					 * while kswapd is awake and restore
-					 * them before going back to sleep.
-					 */
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_normal_threshold);
-					schedule();
-					set_pgdat_percpu_threshold(pgdat,
-						calculate_pressure_threshold);
-				} else {
-					if (remaining)
-						count_vm_event(KSWAPD_LOW_WMARK_HIT_QUICKLY);
-					else
-						count_vm_event(KSWAPD_HIGH_WMARK_HIT_QUICKLY);
-				}
-			}
-
+			kswapd_try_to_sleep(pgdat, order);
 			order = pgdat->kswapd_max_order;
 		}
-		finish_wait(&pgdat->kswapd_wait, &wait);
 
 		ret = try_to_freeze();
 		if (kthread_should_stop())
-- 
1.6.5.2



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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] factor out kswapd sleeping logic from kswapd()
  2010-11-16  6:07     ` KOSAKI Motohiro
@ 2010-11-18 17:27       ` Mel Gorman
  -1 siblings, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2010-11-18 17:27 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: LKML, linux-mm, Andrew Morton

On Tue, Nov 16, 2010 at 03:07:22PM +0900, KOSAKI Motohiro wrote:
> > > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> > > +{
> > 
> > As pointed out elsewhere, this should be static.
> 
> Fixed.
> 
> 
> > > +	long remaining = 0;
> > > +	DEFINE_WAIT(wait);
> > > +
> > > +	if (freezing(current) || kthread_should_stop())
> > > +		return;
> > > +
> > > +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > > +
> > > +	/* Try to sleep for a short interval */
> > > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > > +		remaining = schedule_timeout(HZ/10);
> > > +		finish_wait(&pgdat->kswapd_wait, &wait);
> > > +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > > +	}
> > > +
> > > +	/*
> > > +	 * After a short sleep, check if it was a
> > > +	 * premature sleep. If not, then go fully
> > > +	 * to sleep until explicitly woken up
> > > +	 */
> > 
> > Very minor but that comment should now fit on fewer lines.
> 
> Thanks, fixed.
> 
> 
> > > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > > +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> > > +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> > > +		schedule();
> > > +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
> > 
> > I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
> > called. I do not believe it has been picked up by Andrew but it if is,
> > the patches will conflict. The resolution will be obvious but you may
> > need to respin this patch if the comment patch gets picked up in mmotm.
> > 
> > Otherwise, I see no problems.
> 
> OK, I've rebased the patch on top your comment patch. 
> 
> 
> 
> From 1bd232713d55f033676f80cc7451ff83d4483884 Mon Sep 17 00:00:00 2001
> From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Date: Mon, 6 Dec 2010 20:44:27 +0900
> Subject: [PATCH] factor out kswapd sleeping logic from kswapd()
> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

Acked-by: Mel Gorman <mel@csn.ul.ie>

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] factor out kswapd sleeping logic from kswapd()
@ 2010-11-18 17:27       ` Mel Gorman
  0 siblings, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2010-11-18 17:27 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: LKML, linux-mm, Andrew Morton

On Tue, Nov 16, 2010 at 03:07:22PM +0900, KOSAKI Motohiro wrote:
> > > +void kswapd_try_to_sleep(pg_data_t *pgdat, int order)
> > > +{
> > 
> > As pointed out elsewhere, this should be static.
> 
> Fixed.
> 
> 
> > > +	long remaining = 0;
> > > +	DEFINE_WAIT(wait);
> > > +
> > > +	if (freezing(current) || kthread_should_stop())
> > > +		return;
> > > +
> > > +	prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > > +
> > > +	/* Try to sleep for a short interval */
> > > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > > +		remaining = schedule_timeout(HZ/10);
> > > +		finish_wait(&pgdat->kswapd_wait, &wait);
> > > +		prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
> > > +	}
> > > +
> > > +	/*
> > > +	 * After a short sleep, check if it was a
> > > +	 * premature sleep. If not, then go fully
> > > +	 * to sleep until explicitly woken up
> > > +	 */
> > 
> > Very minor but that comment should now fit on fewer lines.
> 
> Thanks, fixed.
> 
> 
> > > +	if (!sleeping_prematurely(pgdat, order, remaining)) {
> > > +		trace_mm_vmscan_kswapd_sleep(pgdat->node_id);
> > > +		set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
> > > +		schedule();
> > > +		set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
> > 
> > I posted a patch adding a comment on why set_pgdat_percpu_threshold() is
> > called. I do not believe it has been picked up by Andrew but it if is,
> > the patches will conflict. The resolution will be obvious but you may
> > need to respin this patch if the comment patch gets picked up in mmotm.
> > 
> > Otherwise, I see no problems.
> 
> OK, I've rebased the patch on top your comment patch. 
> 
> 
> 
> From 1bd232713d55f033676f80cc7451ff83d4483884 Mon Sep 17 00:00:00 2001
> From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Date: Mon, 6 Dec 2010 20:44:27 +0900
> Subject: [PATCH] factor out kswapd sleeping logic from kswapd()
> 
> Currently, kswapd() function has deeper nest and it slightly harder to
> read. cleanup it.
> 
> Cc: Mel Gorman <mel@csn.ul.ie>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

Acked-by: Mel Gorman <mel@csn.ul.ie>

-- 
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 majordomo@kvack.org.  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:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-11-18 17:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-14  9:05 [PATCH] cleanup kswapd() KOSAKI Motohiro
2010-11-14  9:05 ` KOSAKI Motohiro
2010-11-14 11:03 ` Jesper Juhl
2010-11-14 11:03   ` Jesper Juhl
2010-11-15  0:27   ` KOSAKI Motohiro
2010-11-15  0:27     ` KOSAKI Motohiro
2010-11-15  1:37     ` KOSAKI Motohiro
2010-11-15  1:37       ` KOSAKI Motohiro
2010-11-15  9:42 ` Mel Gorman
2010-11-15  9:42   ` Mel Gorman
2010-11-16  6:07   ` [PATCH v3] factor out kswapd sleeping logic from kswapd() KOSAKI Motohiro
2010-11-16  6:07     ` KOSAKI Motohiro
2010-11-18 17:27     ` Mel Gorman
2010-11-18 17:27       ` Mel Gorman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.