Skip to contentSkip to conversation

vmscan: fix initial shrinker size handling

PATCH In review Konstantin Khlebnikov 4 participants 14 messages Aug 22, 2011 – Oct 5, 2011

Subsystems (6)
Memory management VFS MM core MGLRU +2 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vmscan: fix initial shrinker size handling

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.

---
 mm/vmscan.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
mm/vmscan.c +6 -3
index 29b3612..f174561 100644
@@ -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 [email protected]. 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:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 2/2 vmscan: use atomic-long for shrinker batching

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

---
 include/linux/shrinker.h |    2 +-
 mm/vmscan.c              |   17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)
include/linux/shrinker.h +1 -1
index 790651b..ac6b8ee 100644
@@ -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 *);
mm/vmscan.c +7 -10
index f174561..e31c3e2 100644
@@ -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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#2 lore raw

Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching

Quoted 2 lines · On Mon, 22 Aug 2011 14:17:27 +0300 Konstantin Khlebnikov…

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

Seems nice.

include/linux/shrinker.h struct shrinker { · line 38

Quoted 11 lines
include/linux/shrinker.h +1 -1
index 790651b..ac6b8ee 100644
@@ -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(-)
include/linux/mm.h renamed from include/linux/mm.h~vmscan-use-atomic-long-for-shrinker-batching-fix +1 -0
@@ -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>
include/linux/fs.h renamed from include/linux/fs.h~vmscan-use-atomic-long-for-shrinker-batching-fix +1 -1
@@ -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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw

Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching

In reply to Konstantin Khlebnikov
Quoted 13 lines · Konstantin Khlebnikov

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

---
 include/linux/shrinker.h |    2 +-
 mm/vmscan.c              |   17 +++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)
include/linux/shrinker.h +0 -0
index 790651b..ac6b8ee 100644

include/linux/shrinker.h struct shrinker { · line 37

Quoted 5 lines
include/linux/shrinker.h +1 -1
@@ -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.

Signature · 9 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

Re: [PATCH 2/2] vmscan: use atomic-long for shrinker batching

In reply to Konstantin Khlebnikov
Quoted 8 lines · Konstantin Khlebnikov
  		delta = (4 * nr_pages_scanned) / shrinker->seeks;
mm/vmscan.c +0 -3
@@ -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;

mm/vmscan.c unsigned long shrink_slab(struct shrink_control *shrink, · line 336

Quoted 10 lines
mm/vmscan.c +5 -3
-			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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#5 lore raw
In reply to Konstantin Khlebnikov
Quoted 4 lines · On Mon, 22 Aug 2011 14:17:21 +0300 Konstantin Khlebnikov…

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.

Quoted 1 line

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

Hopefully a smaller oversight.

Quoted 30 lines
---
 mm/vmscan.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
mm/vmscan.c +6 -2
index 29b3612..f174561 100644
@@ -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

mm/vmscan.c unsigned long shrink_slab(struct shrink_control *shrink, · line 275

Quoted 7 lines
mm/vmscan.c +0 -1
@@ -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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#6 lore raw
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Mon, 22 Aug 2011 14:17:21 +0300 Konstantin Khlebnikov…

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.

Quoted 5 lines

Yes, that looks like a significant oversight.

Quoted 1 line

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.

Signature · 9 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw
In reply to Andrew Morton

Andrew Morton wrote:
<snip>

Quoted 14 lines
Quoted 14 lines

long new_nr;
long batch_size = shrinker->batch ? shrinker->batch
: SHRINK_BATCH;

mm/vmscan.c +4 -0
+		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);
 
Quoted 7 lines

mm/vmscan.c unsigned long shrink_slab(struct shrink_control *shrink, · line 275

Quoted 5 lines
mm/vmscan.c +0 -1
  		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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#8 lore raw
In reply to Konstantin Khlebnikov
Quoted 6 lines · Konstantin Khlebnikov

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.

Signature · 9 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#9 lore raw
Quoted 10 lines · On Tue, 23 Aug 2011 09:22:57 +1000 Dave Chinner <[email protected]> wrote:
Quoted 6 lines · Konstantin Khlebnikov

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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#10 lore raw
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Tue, 23 Aug 2011 09:22:57 +1000 Dave Chinner <[email protected]> wrote:
Quoted 5 lines · Konstantin Khlebnikov

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.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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.

Signature · 9 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw
Quoted 15 lines · Dave Chinner
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Aug 2011 09:22:57 +1000 Dave Chinner <[email protected]> wrote:
Quoted 6 lines · Konstantin Khlebnikov

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.

Quoted 8 lines
Quoted 3 lines

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?

Quoted 4 lines

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 [email protected]. 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:"[email protected]"> [email protected] </a>

#12 lore raw
Quoted 41 lines · Johannes Weiner
Quoted 15 lines · Dave Chinner
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Aug 2011 09:22:57 +1000 Dave Chinner <[email protected]> wrote:
Quoted 6 lines · Konstantin Khlebnikov

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.

Quoted 8 lines
Quoted 3 lines

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?

Quoted 4 lines

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;
Quoted 6 lines

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 [email protected]. 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:"[email protected]"> [email protected] </a>

maintainer
#13 lore raw
Quoted 42 lines · On Wed, 5 Oct 2011 23:52:05 +0200 Johannes Weiner <[email protected]> wrote:
Quoted 41 lines · Johannes Weiner
Quoted 15 lines · Dave Chinner
Quoted 14 lines · Andrew Morton
Quoted 10 lines · On Tue, 23 Aug 2011 09:22:57 +1000 Dave Chinner <[email protected]> wrote:
Quoted 6 lines · Konstantin Khlebnikov

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.

Quoted 8 lines
Quoted 3 lines

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?

Quoted 4 lines

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;
Quoted 8 lines
Quoted 6 lines

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.