All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 11:17 ` Konstantin Khlebnikov
  0 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-22 11:17 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel

Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.

Also make total_scan signed, otherwise check (total_scan < 0) below never works.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
 mm/vmscan.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 29b3612..f174561 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -248,14 +248,18 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 
 	list_for_each_entry(shrinker, &shrinker_list, list) {
 		unsigned long long delta;
-		unsigned long total_scan;
-		unsigned long max_pass;
+		long total_scan;
+		long max_pass;
 		int shrink_ret = 0;
 		long nr;
 		long new_nr;
 		long batch_size = shrinker->batch ? shrinker->batch
 						  : SHRINK_BATCH;
 
+		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
+		if (max_pass <= 0)
+			continue;
+
 		/*
 		 * copy the current shrinker scan count into a local variable
 		 * and zero it so that other concurrent shrinker invocations
@@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
 
 		total_scan = nr;
-		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
 		delta = (4 * nr_pages_scanned) / shrinker->seeks;
 		delta *= max_pass;
 		do_div(delta, lru_pages + 1);


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

* [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 11:17 ` Konstantin Khlebnikov
  0 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-22 11:17 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel

Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.

Also make total_scan signed, otherwise check (total_scan < 0) below never works.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
 mm/vmscan.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 29b3612..f174561 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -248,14 +248,18 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 
 	list_for_each_entry(shrinker, &shrinker_list, list) {
 		unsigned long long delta;
-		unsigned long total_scan;
-		unsigned long max_pass;
+		long total_scan;
+		long max_pass;
 		int shrink_ret = 0;
 		long nr;
 		long new_nr;
 		long batch_size = shrinker->batch ? shrinker->batch
 						  : SHRINK_BATCH;
 
+		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
+		if (max_pass <= 0)
+			continue;
+
 		/*
 		 * copy the current shrinker scan count into a local variable
 		 * and zero it so that other concurrent shrinker invocations
@@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
 
 		total_scan = nr;
-		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
 		delta = (4 * nr_pages_scanned) / shrinker->seeks;
 		delta *= max_pass;
 		do_div(delta, lru_pages + 1);

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* [PATCH 2/2] vmscan: use atomic-long for shrinker batching
  2011-08-22 11:17 ` Konstantin Khlebnikov
@ 2011-08-22 11:17   ` Konstantin Khlebnikov
  -1 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-22 11:17 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel

Use atomic-long operations instead of looping around cmpxchg().

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
 include/linux/shrinker.h |    2 +-
 mm/vmscan.c              |   17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
index 790651b..ac6b8ee 100644
--- a/include/linux/shrinker.h
+++ b/include/linux/shrinker.h
@@ -34,7 +34,7 @@ struct shrinker {
 
 	/* These are for internal use */
 	struct list_head list;
-	long nr;	/* objs pending delete */
+	atomic_long_t nr_in_batch; /* objs pending delete */
 };
 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
 extern void register_shrinker(struct shrinker *);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f174561..e31c3e2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -184,7 +184,7 @@ static unsigned long zone_nr_lru_pages(struct zone *zone,
  */
 void register_shrinker(struct shrinker *shrinker)
 {
-	shrinker->nr = 0;
+	atomic_long_set(&shrinker->nr_in_batch, 0);
 	down_write(&shrinker_rwsem);
 	list_add_tail(&shrinker->list, &shrinker_list);
 	up_write(&shrinker_rwsem);
@@ -265,9 +265,7 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		 * and zero it so that other concurrent shrinker invocations
 		 * don't also do this scanning work.
 		 */
-		do {
-			nr = shrinker->nr;
-		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
+		nr = atomic_long_xchg(&shrinker->nr_in_batch, 0);
 
 		total_scan = nr;
 		delta = (4 * nr_pages_scanned) / shrinker->seeks;
@@ -329,12 +327,11 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		 * manner that handles concurrent updates. If we exhausted the
 		 * scan, there is no need to do an update.
 		 */
-		do {
-			nr = shrinker->nr;
-			new_nr = total_scan + nr;
-			if (total_scan <= 0)
-				break;
-		} while (cmpxchg(&shrinker->nr, nr, new_nr) != nr);
+		if (total_scan > 0)
+			new_nr = atomic_long_add_return(total_scan,
+					&shrinker->nr_in_batch);
+		else
+			new_nr = atomic_long_read(&shrinker->nr_in_batch);
 
 		trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);
 	}


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

* [PATCH 2/2] vmscan: use atomic-long for shrinker batching
@ 2011-08-22 11:17   ` Konstantin Khlebnikov
  0 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-22 11:17 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel

Use atomic-long operations instead of looping around cmpxchg().

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
 include/linux/shrinker.h |    2 +-
 mm/vmscan.c              |   17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
index 790651b..ac6b8ee 100644
--- a/include/linux/shrinker.h
+++ b/include/linux/shrinker.h
@@ -34,7 +34,7 @@ struct shrinker {
 
 	/* These are for internal use */
 	struct list_head list;
-	long nr;	/* objs pending delete */
+	atomic_long_t nr_in_batch; /* objs pending delete */
 };
 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
 extern void register_shrinker(struct shrinker *);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f174561..e31c3e2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -184,7 +184,7 @@ static unsigned long zone_nr_lru_pages(struct zone *zone,
  */
 void register_shrinker(struct shrinker *shrinker)
 {
-	shrinker->nr = 0;
+	atomic_long_set(&shrinker->nr_in_batch, 0);
 	down_write(&shrinker_rwsem);
 	list_add_tail(&shrinker->list, &shrinker_list);
 	up_write(&shrinker_rwsem);
@@ -265,9 +265,7 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		 * and zero it so that other concurrent shrinker invocations
 		 * don't also do this scanning work.
 		 */
-		do {
-			nr = shrinker->nr;
-		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
+		nr = atomic_long_xchg(&shrinker->nr_in_batch, 0);
 
 		total_scan = nr;
 		delta = (4 * nr_pages_scanned) / shrinker->seeks;
@@ -329,12 +327,11 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 		 * manner that handles concurrent updates. If we exhausted the
 		 * scan, there is no need to do an update.
 		 */
-		do {
-			nr = shrinker->nr;
-			new_nr = total_scan + nr;
-			if (total_scan <= 0)
-				break;
-		} while (cmpxchg(&shrinker->nr, nr, new_nr) != nr);
+		if (total_scan > 0)
+			new_nr = atomic_long_add_return(total_scan,
+					&shrinker->nr_in_batch);
+		else
+			new_nr = atomic_long_read(&shrinker->nr_in_batch);
 
 		trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);
 	}

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 11:17 ` Konstantin Khlebnikov
@ 2011-08-22 21:30   ` Andrew Morton
  -1 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 21:30 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, linux-kernel, Dave Chinner

On Mon, 22 Aug 2011 14:17:21 +0300
Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:

> Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.

Yes, that looks like a significant oversight.

> Also make total_scan signed, otherwise check (total_scan < 0) below never works.

Hopefully a smaller oversight.

> ---
>  mm/vmscan.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 29b3612..f174561 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -248,14 +248,18 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>  
>  	list_for_each_entry(shrinker, &shrinker_list, list) {
>  		unsigned long long delta;
> -		unsigned long total_scan;
> -		unsigned long max_pass;
> +		long total_scan;
> +		long max_pass;
>  		int shrink_ret = 0;
>  		long nr;
>  		long new_nr;
>  		long batch_size = shrinker->batch ? shrinker->batch
>  						  : SHRINK_BATCH;
>  
> +		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
> +		if (max_pass <= 0)
> +			continue;
> +
>  		/*
>  		 * copy the current shrinker scan count into a local variable
>  		 * and zero it so that other concurrent shrinker invocations
> @@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>  		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
>  
>  		total_scan = nr;
> -		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>  		delta = (4 * nr_pages_scanned) / shrinker->seeks;
>  		delta *= max_pass;
>  		do_div(delta, lru_pages + 1);

Why was the shrinker call moved to before the alteration of shrinker->nr?

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 21:30   ` Andrew Morton
  0 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 21:30 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, linux-kernel, Dave Chinner

On Mon, 22 Aug 2011 14:17:21 +0300
Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:

> Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.

Yes, that looks like a significant oversight.

> Also make total_scan signed, otherwise check (total_scan < 0) below never works.

Hopefully a smaller oversight.

> ---
>  mm/vmscan.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 29b3612..f174561 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -248,14 +248,18 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>  
>  	list_for_each_entry(shrinker, &shrinker_list, list) {
>  		unsigned long long delta;
> -		unsigned long total_scan;
> -		unsigned long max_pass;
> +		long total_scan;
> +		long max_pass;
>  		int shrink_ret = 0;
>  		long nr;
>  		long new_nr;
>  		long batch_size = shrinker->batch ? shrinker->batch
>  						  : SHRINK_BATCH;
>  
> +		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
> +		if (max_pass <= 0)
> +			continue;
> +
>  		/*
>  		 * copy the current shrinker scan count into a local variable
>  		 * and zero it so that other concurrent shrinker invocations
> @@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>  		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
>  
>  		total_scan = nr;
> -		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>  		delta = (4 * nr_pages_scanned) / shrinker->seeks;
>  		delta *= max_pass;
>  		do_div(delta, lru_pages + 1);

Why was the shrinker call moved to before the alteration of shrinker->nr?

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
  2011-08-22 11:17   ` Konstantin Khlebnikov
@ 2011-08-22 21:39     ` Andrew Morton
  -1 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 21:39 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, linux-kernel, Dave Chinner

On Mon, 22 Aug 2011 14:17:27 +0300
Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:

> Use atomic-long operations instead of looping around cmpxchg().
> 

Seems nice.

> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
> index 790651b..ac6b8ee 100644
> --- a/include/linux/shrinker.h
> +++ b/include/linux/shrinker.h
> @@ -34,7 +34,7 @@ struct shrinker {
>  
>  	/* These are for internal use */
>  	struct list_head list;
> -	long nr;	/* objs pending delete */
> +	atomic_long_t nr_in_batch; /* objs pending delete */
>  };

This makes shrinker.h have a dependency on atomic.h.  shrinker.h is a
strange thing that doesn't include its own dependent header files - the
shrinker.h includer is responsible for that.  And they both need
fixups, for safety's sake:

 include/linux/fs.h |    2 +-
 include/linux/mm.h |    1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

--- a/include/linux/mm.h~vmscan-use-atomic-long-for-shrinker-batching-fix
+++ a/include/linux/mm.h
@@ -10,6 +10,7 @@
 #include <linux/mmzone.h>
 #include <linux/rbtree.h>
 #include <linux/prio_tree.h>
+#include <linux/atomic.h>
 #include <linux/debug_locks.h>
 #include <linux/mm_types.h>
 #include <linux/range.h>
--- a/include/linux/fs.h~vmscan-use-atomic-long-for-shrinker-batching-fix
+++ a/include/linux/fs.h
@@ -394,8 +394,8 @@ struct inodes_stat_t {
 #include <linux/semaphore.h>
 #include <linux/fiemap.h>
 #include <linux/rculist_bl.h>
-#include <linux/shrinker.h>
 #include <linux/atomic.h>
+#include <linux/shrinker.h>
 
 #include <asm/byteorder.h>
 
_


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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
@ 2011-08-22 21:39     ` Andrew Morton
  0 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 21:39 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, linux-kernel, Dave Chinner

On Mon, 22 Aug 2011 14:17:27 +0300
Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:

> Use atomic-long operations instead of looping around cmpxchg().
> 

Seems nice.

> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
> index 790651b..ac6b8ee 100644
> --- a/include/linux/shrinker.h
> +++ b/include/linux/shrinker.h
> @@ -34,7 +34,7 @@ struct shrinker {
>  
>  	/* These are for internal use */
>  	struct list_head list;
> -	long nr;	/* objs pending delete */
> +	atomic_long_t nr_in_batch; /* objs pending delete */
>  };

This makes shrinker.h have a dependency on atomic.h.  shrinker.h is a
strange thing that doesn't include its own dependent header files - the
shrinker.h includer is responsible for that.  And they both need
fixups, for safety's sake:

 include/linux/fs.h |    2 +-
 include/linux/mm.h |    1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

--- a/include/linux/mm.h~vmscan-use-atomic-long-for-shrinker-batching-fix
+++ a/include/linux/mm.h
@@ -10,6 +10,7 @@
 #include <linux/mmzone.h>
 #include <linux/rbtree.h>
 #include <linux/prio_tree.h>
+#include <linux/atomic.h>
 #include <linux/debug_locks.h>
 #include <linux/mm_types.h>
 #include <linux/range.h>
--- a/include/linux/fs.h~vmscan-use-atomic-long-for-shrinker-batching-fix
+++ a/include/linux/fs.h
@@ -394,8 +394,8 @@ struct inodes_stat_t {
 #include <linux/semaphore.h>
 #include <linux/fiemap.h>
 #include <linux/rculist_bl.h>
-#include <linux/shrinker.h>
 #include <linux/atomic.h>
+#include <linux/shrinker.h>
 
 #include <asm/byteorder.h>
 
_

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 11:17 ` Konstantin Khlebnikov
@ 2011-08-22 23:22   ` Dave Chinner
  -1 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:22 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, Andrew Morton, linux-kernel

On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> 
> Also make total_scan signed, otherwise check (total_scan < 0) below never works.

I've got a patch set I am going to post out today that makes this
irrelevant.

The patch set splits the shrinker api into 2 callbacks - a "count
objects" callback and an "scan objects" callback, getting rid of
this messy "pass nr-to_scan == 0 to count objects" wart altogether.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 23:22   ` Dave Chinner
  0 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:22 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, Andrew Morton, linux-kernel

On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> 
> Also make total_scan signed, otherwise check (total_scan < 0) below never works.

I've got a patch set I am going to post out today that makes this
irrelevant.

The patch set splits the shrinker api into 2 callbacks - a "count
objects" callback and an "scan objects" callback, getting rid of
this messy "pass nr-to_scan == 0 to count objects" wart altogether.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
  2011-08-22 11:17   ` Konstantin Khlebnikov
@ 2011-08-22 23:26     ` Dave Chinner
  -1 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:26 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, Andrew Morton, linux-kernel

On Mon, Aug 22, 2011 at 02:17:27PM +0300, Konstantin Khlebnikov wrote:
> Use atomic-long operations instead of looping around cmpxchg().
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
> ---
>  include/linux/shrinker.h |    2 +-
>  mm/vmscan.c              |   17 +++++++----------
>  2 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
> index 790651b..ac6b8ee 100644
> --- a/include/linux/shrinker.h
> +++ b/include/linux/shrinker.h
> @@ -34,7 +34,7 @@ struct shrinker {
>  
>  	/* These are for internal use */
>  	struct list_head list;
> -	long nr;	/* objs pending delete */
> +	atomic_long_t nr_in_batch; /* objs pending delete */

It's not really the number in a batch - we use the "batch" term to
refer to the value we set sc->nr_to_scan for each shrinker scan call.
This is more the overflow of unscanned objects - objects pending
delete, as the comment says. So renaming it "nr_pending" might be
better.

As it is, this is a good change - I'll fold it into the series I
already have.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
@ 2011-08-22 23:26     ` Dave Chinner
  0 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:26 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-mm, Andrew Morton, linux-kernel

On Mon, Aug 22, 2011 at 02:17:27PM +0300, Konstantin Khlebnikov wrote:
> Use atomic-long operations instead of looping around cmpxchg().
> 
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
> ---
>  include/linux/shrinker.h |    2 +-
>  mm/vmscan.c              |   17 +++++++----------
>  2 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
> index 790651b..ac6b8ee 100644
> --- a/include/linux/shrinker.h
> +++ b/include/linux/shrinker.h
> @@ -34,7 +34,7 @@ struct shrinker {
>  
>  	/* These are for internal use */
>  	struct list_head list;
> -	long nr;	/* objs pending delete */
> +	atomic_long_t nr_in_batch; /* objs pending delete */

It's not really the number in a batch - we use the "batch" term to
refer to the value we set sc->nr_to_scan for each shrinker scan call.
This is more the overflow of unscanned objects - objects pending
delete, as the comment says. So renaming it "nr_pending" might be
better.

As it is, this is a good change - I'll fold it into the series I
already have.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 21:30   ` Andrew Morton
@ 2011-08-22 23:28     ` Dave Chinner
  -1 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Mon, Aug 22, 2011 at 02:30:06PM -0700, Andrew Morton wrote:
> On Mon, 22 Aug 2011 14:17:21 +0300
> Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:
> 
> > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> 
> Yes, that looks like a significant oversight.
> 
> > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> 
> Hopefully a smaller oversight.

Yeah, it was, but is harmless because it is caught by the next check
of total_scanned. I've made similar "make everything signed" changes
as well.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 23:28     ` Dave Chinner
  0 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-22 23:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Mon, Aug 22, 2011 at 02:30:06PM -0700, Andrew Morton wrote:
> On Mon, 22 Aug 2011 14:17:21 +0300
> Konstantin Khlebnikov <khlebnikov@openvz.org> wrote:
> 
> > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> 
> Yes, that looks like a significant oversight.
> 
> > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> 
> Hopefully a smaller oversight.

Yeah, it was, but is harmless because it is caught by the next check
of total_scanned. I've made similar "make everything signed" changes
as well.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 23:22   ` Dave Chinner
@ 2011-08-22 23:38     ` Andrew Morton
  -1 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 23:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, 23 Aug 2011 09:22:57 +1000
Dave Chinner <david@fromorbit.com> wrote:

> On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > 
> > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> 
> I've got a patch set I am going to post out today that makes this
> irrelevant.

Well, how serious is the bug?  If it's a non-issue then we can leave
the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
patch to fix up 3.1 and 3.0.x.


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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-22 23:38     ` Andrew Morton
  0 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-08-22 23:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, 23 Aug 2011 09:22:57 +1000
Dave Chinner <david@fromorbit.com> wrote:

> On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > 
> > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> 
> I've got a patch set I am going to post out today that makes this
> irrelevant.

Well, how serious is the bug?  If it's a non-issue then we can leave
the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
patch to fix up 3.1 and 3.0.x.

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 23:38     ` Andrew Morton
@ 2011-08-23  0:00       ` Dave Chinner
  -1 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-23  0:00 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> On Tue, 23 Aug 2011 09:22:57 +1000
> Dave Chinner <david@fromorbit.com> wrote:
> 
> > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > 
> > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > 
> > I've got a patch set I am going to post out today that makes this
> > irrelevant.
> 
> Well, how serious is the bug?  If it's a non-issue then we can leave
> the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> patch to fix up 3.1 and 3.0.x.

I'm pretty sure it's a non-issue. I'm pretty sure all of the
shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
== 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
of -1 isn't going to happen very often....

And with total_scan being unsigned, the negative check is followed
by a "if (total_scan > max_pass * 2)" check, which will catch
numbers that would have gone negative anyway because max_pass won't
be negative....

So, grotty code but I don't think there is even a problem that can
be tripped right now.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-23  0:00       ` Dave Chinner
  0 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2011-08-23  0:00 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Konstantin Khlebnikov, linux-mm, linux-kernel

On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> On Tue, 23 Aug 2011 09:22:57 +1000
> Dave Chinner <david@fromorbit.com> wrote:
> 
> > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > 
> > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > 
> > I've got a patch set I am going to post out today that makes this
> > irrelevant.
> 
> Well, how serious is the bug?  If it's a non-issue then we can leave
> the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> patch to fix up 3.1 and 3.0.x.

I'm pretty sure it's a non-issue. I'm pretty sure all of the
shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
== 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
of -1 isn't going to happen very often....

And with total_scan being unsigned, the negative check is followed
by a "if (total_scan > max_pass * 2)" check, which will catch
numbers that would have gone negative anyway because max_pass won't
be negative....

So, grotty code but I don't think there is even a problem that can
be tripped right now.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-22 21:30   ` Andrew Morton
@ 2011-08-23  6:47     ` Konstantin Khlebnikov
  -1 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-23  6:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Dave Chinner

Andrew Morton wrote:
<snip>
>>   		long new_nr;
>>   		long batch_size = shrinker->batch ? shrinker->batch
>>   						  : SHRINK_BATCH;
>>
>> +		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>> +		if (max_pass<= 0)
>> +			continue;
>> +
>>   		/*
>>   		 * copy the current shrinker scan count into a local variable
>>   		 * and zero it so that other concurrent shrinker invocations
>> @@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>>   		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
>>
>>   		total_scan = nr;
>> -		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>>   		delta = (4 * nr_pages_scanned) / shrinker->seeks;
>>   		delta *= max_pass;
>>   		do_div(delta, lru_pages + 1);
>
> Why was the shrinker call moved to before the alteration of shrinker->nr?

I think, if we skip shrinker we shouldn't reset accumulated pressure,
because next reclaimer (for example with less strict gfp) can use it.

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-08-23  6:47     ` Konstantin Khlebnikov
  0 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-23  6:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Dave Chinner

Andrew Morton wrote:
<snip>
>>   		long new_nr;
>>   		long batch_size = shrinker->batch ? shrinker->batch
>>   						  : SHRINK_BATCH;
>>
>> +		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>> +		if (max_pass<= 0)
>> +			continue;
>> +
>>   		/*
>>   		 * copy the current shrinker scan count into a local variable
>>   		 * and zero it so that other concurrent shrinker invocations
>> @@ -266,7 +270,6 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>>   		} while (cmpxchg(&shrinker->nr, nr, 0) != nr);
>>
>>   		total_scan = nr;
>> -		max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>>   		delta = (4 * nr_pages_scanned) / shrinker->seeks;
>>   		delta *= max_pass;
>>   		do_div(delta, lru_pages + 1);
>
> Why was the shrinker call moved to before the alteration of shrinker->nr?

I think, if we skip shrinker we shouldn't reset accumulated pressure,
because next reclaimer (for example with less strict gfp) can use it.

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
  2011-08-22 11:17   ` Konstantin Khlebnikov
@ 2011-08-23  6:56     ` Konstantin Khlebnikov
  -1 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-23  6:56 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel, Dave Chinner

Konstantin Khlebnikov wrote:
>   		delta = (4 * nr_pages_scanned) / shrinker->seeks;
> @@ -329,12 +327,11 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>   		 * manner that handles concurrent updates. If we exhausted the
>   		 * scan, there is no need to do an update.
>   		 */
> -		do {
> -			nr = shrinker->nr;
> -			new_nr = total_scan + nr;
> -			if (total_scan<= 0)
> -				break;
> -		} while (cmpxchg(&shrinker->nr, nr, new_nr) != nr);
> +		if (total_scan>  0)
> +			new_nr = atomic_long_add_return(total_scan,
> +					&shrinker->nr_in_batch);
> +		else
> +			new_nr = atomic_long_read(&shrinker->nr_in_batch);
>
>   		trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);

BTW, new_nr required only for tracing, maybe this will be better/faster,
because atomic accuracy there isn't required at all.

	if (total_scan > 0)
		atomic_long_add(total_scan, &shrinker->nr_in_batch);

	new_nr = atomic_long_read(&shrinker->nr_in_batch);
	trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);

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

* Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching
@ 2011-08-23  6:56     ` Konstantin Khlebnikov
  0 siblings, 0 replies; 28+ messages in thread
From: Konstantin Khlebnikov @ 2011-08-23  6:56 UTC (permalink / raw)
  To: linux-mm, Andrew Morton; +Cc: linux-kernel, Dave Chinner

Konstantin Khlebnikov wrote:
>   		delta = (4 * nr_pages_scanned) / shrinker->seeks;
> @@ -329,12 +327,11 @@ unsigned long shrink_slab(struct shrink_control *shrink,
>   		 * manner that handles concurrent updates. If we exhausted the
>   		 * scan, there is no need to do an update.
>   		 */
> -		do {
> -			nr = shrinker->nr;
> -			new_nr = total_scan + nr;
> -			if (total_scan<= 0)
> -				break;
> -		} while (cmpxchg(&shrinker->nr, nr, new_nr) != nr);
> +		if (total_scan>  0)
> +			new_nr = atomic_long_add_return(total_scan,
> +					&shrinker->nr_in_batch);
> +		else
> +			new_nr = atomic_long_read(&shrinker->nr_in_batch);
>
>   		trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);

BTW, new_nr required only for tracing, maybe this will be better/faster,
because atomic accuracy there isn't required at all.

	if (total_scan > 0)
		atomic_long_add(total_scan, &shrinker->nr_in_batch);

	new_nr = atomic_long_read(&shrinker->nr_in_batch);
	trace_mm_shrink_slab_end(shrinker, shrink_ret, nr, new_nr);

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-08-23  0:00       ` Dave Chinner
@ 2011-09-13 18:38         ` Johannes Weiner
  -1 siblings, 0 replies; 28+ messages in thread
From: Johannes Weiner @ 2011-09-13 18:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Andrew Morton, Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > On Tue, 23 Aug 2011 09:22:57 +1000
> > Dave Chinner <david@fromorbit.com> wrote:
> > 
> > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > 
> > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > 
> > > I've got a patch set I am going to post out today that makes this
> > > irrelevant.
> > 
> > Well, how serious is the bug?  If it's a non-issue then we can leave
> > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > patch to fix up 3.1 and 3.0.x.
> 
> I'm pretty sure it's a non-issue. I'm pretty sure all of the
> shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> of -1 isn't going to happen very often....

Except for the case which Konstantin laid out, grabbing the super
block reference.  How likely is that?  And why isn't once enough to
build up quite a high number?

> And with total_scan being unsigned, the negative check is followed
> by a "if (total_scan > max_pass * 2)" check, which will catch
> numbers that would have gone negative anyway because max_pass won't
> be negative....

                total_scan = nr;
                max_pass = do_shrinker_shrink(shrinker, shrink, 0);
                delta = (4 * nr_pages_scanned) / shrinker->seeks;
                delta *= max_pass;
                do_div(delta, lru_pages + 1);
                total_scan += delta;

max_pass, an unsigned long, is what the shrinker returned, so
ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?

Even for high values of delta (lots of pages scanned, few lru pages
left), it won't come nowhere near max_pass such that the product of
the two is a reasonable number again.

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-09-13 18:38         ` Johannes Weiner
  0 siblings, 0 replies; 28+ messages in thread
From: Johannes Weiner @ 2011-09-13 18:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Andrew Morton, Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > On Tue, 23 Aug 2011 09:22:57 +1000
> > Dave Chinner <david@fromorbit.com> wrote:
> > 
> > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > 
> > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > 
> > > I've got a patch set I am going to post out today that makes this
> > > irrelevant.
> > 
> > Well, how serious is the bug?  If it's a non-issue then we can leave
> > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > patch to fix up 3.1 and 3.0.x.
> 
> I'm pretty sure it's a non-issue. I'm pretty sure all of the
> shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> of -1 isn't going to happen very often....

Except for the case which Konstantin laid out, grabbing the super
block reference.  How likely is that?  And why isn't once enough to
build up quite a high number?

> And with total_scan being unsigned, the negative check is followed
> by a "if (total_scan > max_pass * 2)" check, which will catch
> numbers that would have gone negative anyway because max_pass won't
> be negative....

                total_scan = nr;
                max_pass = do_shrinker_shrink(shrinker, shrink, 0);
                delta = (4 * nr_pages_scanned) / shrinker->seeks;
                delta *= max_pass;
                do_div(delta, lru_pages + 1);
                total_scan += delta;

max_pass, an unsigned long, is what the shrinker returned, so
ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?

Even for high values of delta (lots of pages scanned, few lru pages
left), it won't come nowhere near max_pass such that the product of
the two is a reasonable number again.

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-09-13 18:38         ` Johannes Weiner
@ 2011-10-05 21:52           ` Johannes Weiner
  -1 siblings, 0 replies; 28+ messages in thread
From: Johannes Weiner @ 2011-10-05 21:52 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Andrew Morton, Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, Sep 13, 2011 at 08:38:36PM +0200, Johannes Weiner wrote:
> On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> > On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > > On Tue, 23 Aug 2011 09:22:57 +1000
> > > Dave Chinner <david@fromorbit.com> wrote:
> > > 
> > > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > > 
> > > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > > 
> > > > I've got a patch set I am going to post out today that makes this
> > > > irrelevant.
> > > 
> > > Well, how serious is the bug?  If it's a non-issue then we can leave
> > > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > > patch to fix up 3.1 and 3.0.x.
> > 
> > I'm pretty sure it's a non-issue. I'm pretty sure all of the
> > shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> > == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> > of -1 isn't going to happen very often....
> 
> Except for the case which Konstantin laid out, grabbing the super
> block reference.  How likely is that?  And why isn't once enough to
> build up quite a high number?
> 
> > And with total_scan being unsigned, the negative check is followed
> > by a "if (total_scan > max_pass * 2)" check, which will catch
> > numbers that would have gone negative anyway because max_pass won't
> > be negative....
> 
>                 total_scan = nr;
>                 max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>                 delta = (4 * nr_pages_scanned) / shrinker->seeks;
>                 delta *= max_pass;
>                 do_div(delta, lru_pages + 1);
>                 total_scan += delta;
> 
> max_pass, an unsigned long, is what the shrinker returned, so
> ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?
> 
> Even for high values of delta (lots of pages scanned, few lru pages
> left), it won't come nowhere near max_pass such that the product of
> the two is a reasonable number again.

Ping?

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-10-05 21:52           ` Johannes Weiner
  0 siblings, 0 replies; 28+ messages in thread
From: Johannes Weiner @ 2011-10-05 21:52 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Andrew Morton, Konstantin Khlebnikov, linux-mm, linux-kernel

On Tue, Sep 13, 2011 at 08:38:36PM +0200, Johannes Weiner wrote:
> On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> > On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > > On Tue, 23 Aug 2011 09:22:57 +1000
> > > Dave Chinner <david@fromorbit.com> wrote:
> > > 
> > > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > > 
> > > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > > 
> > > > I've got a patch set I am going to post out today that makes this
> > > > irrelevant.
> > > 
> > > Well, how serious is the bug?  If it's a non-issue then we can leave
> > > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > > patch to fix up 3.1 and 3.0.x.
> > 
> > I'm pretty sure it's a non-issue. I'm pretty sure all of the
> > shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> > == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> > of -1 isn't going to happen very often....
> 
> Except for the case which Konstantin laid out, grabbing the super
> block reference.  How likely is that?  And why isn't once enough to
> build up quite a high number?
> 
> > And with total_scan being unsigned, the negative check is followed
> > by a "if (total_scan > max_pass * 2)" check, which will catch
> > numbers that would have gone negative anyway because max_pass won't
> > be negative....
> 
>                 total_scan = nr;
>                 max_pass = do_shrinker_shrink(shrinker, shrink, 0);
>                 delta = (4 * nr_pages_scanned) / shrinker->seeks;
>                 delta *= max_pass;
>                 do_div(delta, lru_pages + 1);
>                 total_scan += delta;
> 
> max_pass, an unsigned long, is what the shrinker returned, so
> ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?
> 
> Even for high values of delta (lots of pages scanned, few lru pages
> left), it won't come nowhere near max_pass such that the product of
> the two is a reasonable number again.

Ping?

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
  2011-10-05 21:52           ` Johannes Weiner
@ 2011-10-05 21:58             ` Andrew Morton
  -1 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-10-05 21:58 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Dave Chinner, Konstantin Khlebnikov, linux-mm, linux-kernel

On Wed, 5 Oct 2011 23:52:05 +0200
Johannes Weiner <jweiner@redhat.com> wrote:

> On Tue, Sep 13, 2011 at 08:38:36PM +0200, Johannes Weiner wrote:
> > On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> > > On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > > > On Tue, 23 Aug 2011 09:22:57 +1000
> > > > Dave Chinner <david@fromorbit.com> wrote:
> > > > 
> > > > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > > > 
> > > > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > > > 
> > > > > I've got a patch set I am going to post out today that makes this
> > > > > irrelevant.
> > > > 
> > > > Well, how serious is the bug?  If it's a non-issue then we can leave
> > > > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > > > patch to fix up 3.1 and 3.0.x.
> > > 
> > > I'm pretty sure it's a non-issue. I'm pretty sure all of the
> > > shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> > > == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> > > of -1 isn't going to happen very often....
> > 
> > Except for the case which Konstantin laid out, grabbing the super
> > block reference.  How likely is that?  And why isn't once enough to
> > build up quite a high number?
> > 
> > > And with total_scan being unsigned, the negative check is followed
> > > by a "if (total_scan > max_pass * 2)" check, which will catch
> > > numbers that would have gone negative anyway because max_pass won't
> > > be negative....
> > 
> >                 total_scan = nr;
> >                 max_pass = do_shrinker_shrink(shrinker, shrink, 0);
> >                 delta = (4 * nr_pages_scanned) / shrinker->seeks;
> >                 delta *= max_pass;
> >                 do_div(delta, lru_pages + 1);
> >                 total_scan += delta;
> > 
> > max_pass, an unsigned long, is what the shrinker returned, so
> > ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?
> > 
> > Even for high values of delta (lots of pages scanned, few lru pages
> > left), it won't come nowhere near max_pass such that the product of
> > the two is a reasonable number again.
> 
> Ping?

I have a note against that patch that David was working on some
alternative.  So ...  ping, indeed.


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

* Re: [PATCH 1/2] vmscan: fix initial shrinker size handling
@ 2011-10-05 21:58             ` Andrew Morton
  0 siblings, 0 replies; 28+ messages in thread
From: Andrew Morton @ 2011-10-05 21:58 UTC (permalink / raw)
  To: Johannes Weiner
  Cc: Dave Chinner, Konstantin Khlebnikov, linux-mm, linux-kernel

On Wed, 5 Oct 2011 23:52:05 +0200
Johannes Weiner <jweiner@redhat.com> wrote:

> On Tue, Sep 13, 2011 at 08:38:36PM +0200, Johannes Weiner wrote:
> > On Tue, Aug 23, 2011 at 10:00:54AM +1000, Dave Chinner wrote:
> > > On Mon, Aug 22, 2011 at 04:38:21PM -0700, Andrew Morton wrote:
> > > > On Tue, 23 Aug 2011 09:22:57 +1000
> > > > Dave Chinner <david@fromorbit.com> wrote:
> > > > 
> > > > > On Mon, Aug 22, 2011 at 02:17:21PM +0300, Konstantin Khlebnikov wrote:
> > > > > > Shrinker function can returns -1, it means it cannot do anything without a risk of deadlock.
> > > > > > For example prune_super() do this if it cannot grab superblock refrence, even if nr_to_scan=0.
> > > > > > Currenly we interpret this like ULONG_MAX size shrinker, evaluate total_scan according this,
> > > > > > and next time this shrinker can get really big pressure. Let's skip such shrinkers instead.
> > > > > > 
> > > > > > Also make total_scan signed, otherwise check (total_scan < 0) below never works.
> > > > > 
> > > > > I've got a patch set I am going to post out today that makes this
> > > > > irrelevant.
> > > > 
> > > > Well, how serious is the bug?  If it's a non-issue then we can leave
> > > > the fix until 3.1.  If it's a non-non-issue then we'd need a minimal
> > > > patch to fix up 3.1 and 3.0.x.
> > > 
> > > I'm pretty sure it's a non-issue. I'm pretty sure all of the
> > > shrinkers return a count >= 0 rather than -1 when passed nr_to_scan
> > > == 0 (i.e.  they skip the GFP_NOFS checking), so getting a max_pass
> > > of -1 isn't going to happen very often....
> > 
> > Except for the case which Konstantin laid out, grabbing the super
> > block reference.  How likely is that?  And why isn't once enough to
> > build up quite a high number?
> > 
> > > And with total_scan being unsigned, the negative check is followed
> > > by a "if (total_scan > max_pass * 2)" check, which will catch
> > > numbers that would have gone negative anyway because max_pass won't
> > > be negative....
> > 
> >                 total_scan = nr;
> >                 max_pass = do_shrinker_shrink(shrinker, shrink, 0);
> >                 delta = (4 * nr_pages_scanned) / shrinker->seeks;
> >                 delta *= max_pass;
> >                 do_div(delta, lru_pages + 1);
> >                 total_scan += delta;
> > 
> > max_pass, an unsigned long, is what the shrinker returned, so
> > ULONG_MAX.  ULONG_MAX * 2 is ULONG_MAX - 1, still pretty big?
> > 
> > Even for high values of delta (lots of pages scanned, few lru pages
> > left), it won't come nowhere near max_pass such that the product of
> > the two is a reasonable number again.
> 
> Ping?

I have a note against that patch that David was working on some
alternative.  So ...  ping, indeed.

--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2011-10-05 21:58 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-22 11:17 [PATCH 1/2] vmscan: fix initial shrinker size handling Konstantin Khlebnikov
2011-08-22 11:17 ` Konstantin Khlebnikov
2011-08-22 11:17 ` [PATCH 2/2] vmscan: use atomic-long for shrinker batching Konstantin Khlebnikov
2011-08-22 11:17   ` Konstantin Khlebnikov
2011-08-22 21:39   ` Andrew Morton
2011-08-22 21:39     ` Andrew Morton
2011-08-22 23:26   ` Dave Chinner
2011-08-22 23:26     ` Dave Chinner
2011-08-23  6:56   ` Konstantin Khlebnikov
2011-08-23  6:56     ` Konstantin Khlebnikov
2011-08-22 21:30 ` [PATCH 1/2] vmscan: fix initial shrinker size handling Andrew Morton
2011-08-22 21:30   ` Andrew Morton
2011-08-22 23:28   ` Dave Chinner
2011-08-22 23:28     ` Dave Chinner
2011-08-23  6:47   ` Konstantin Khlebnikov
2011-08-23  6:47     ` Konstantin Khlebnikov
2011-08-22 23:22 ` Dave Chinner
2011-08-22 23:22   ` Dave Chinner
2011-08-22 23:38   ` Andrew Morton
2011-08-22 23:38     ` Andrew Morton
2011-08-23  0:00     ` Dave Chinner
2011-08-23  0:00       ` Dave Chinner
2011-09-13 18:38       ` Johannes Weiner
2011-09-13 18:38         ` Johannes Weiner
2011-10-05 21:52         ` Johannes Weiner
2011-10-05 21:52           ` Johannes Weiner
2011-10-05 21:58           ` Andrew Morton
2011-10-05 21:58             ` Andrew Morton

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.