Skip to contentSkip to conversation

slightly change shrinker behaviour for very small object sets

PATCH Superseded Glauber Costa 2 participants 6 messages Dec 19, 2012 – Dec 20, 2012

Subsystems (5)
Memory management VFS cgroup MGLRU +1 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover slightly change shrinker behaviour for very small object sets

Hi,

I've recently noticed some glitches in the object shrinker mechanism when a very small number of objects is used. Those situations are theoretically possible, albeit unlikely. But although it may feel like it is purely theoretical, they can become common in environments with many small containers (cgroups) in a box.

Those patches came from some experimentation I am doing with targetted-shrinking for kmem-limited memory cgroups (Dave Shrinnker is already aware of such work). In such scenarios, one can set the available memory to very low limits, and it becomes easy to see this.

Glauber Costa (2):
super: fix calculation of shrinkable objects for small numbers
vmscan: take at least one pass with shrinkers

 fs/super.c  | 2 +-
 mm/vmscan.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 super: fix calculation of shrinkable objects for small numbers

The sysctl knob sysctl_vfs_cache_pressure is used to determine which percentage of the shrinkable objects in our cache we should actively try to shrink.

It works great in situations in which we have many objects (at least more than 100), because the aproximation errors will be negligible. But if this is not the case, specially when total_objects < 100, we may end up concluding that we have no objects at all (total / 100 = 0, if total < 100).

This is certainly not the biggest killer in the world, but may matter in very low kernel memory situations.

CC Dave Chinner <[email protected]>
CC "Theodore Ts'o" <[email protected]>
CC Al Viro <[email protected]>
---
 fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/super.c +1 -1
index 12f1237..660552c 100644
@@ -104,7 +104,7 @@ static int prune_super(struct shrinker *shrink, struct shrink_control *sc)
 				sb->s_nr_inodes_unused + fs_objects;
 	}
 
-	total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure;
+	total_objects = mult_frac(total_objects, sysctl_vfs_cache_pressure, 100);
 	drop_super(sb);
 	return total_objects;
 }
Signature · 7 lines
1.7.11.7

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

PATCH 2/2 vmscan: take at least one pass with shrinkers

In reply to Glauber Costa

In very low free kernel memory situations, it may be the case that we have less objects to free than our initial batch size. If this is the case, it is better to shrink those, and open space for the new workload then to keep them and fail the new allocations.

More specifically, this happens because we encode this in a loop with the condition: "while (total_scan >= batch_size)". So if we are in such a case, we'll not even enter the loop.

This patch modifies turns it into a do () while {} loop, that will guarantee that we scan it at least once, while keeping the behaviour exactly the same for the cases in which total_scan > batch_size.

CC Dave Chinner <[email protected]>
CC "Theodore Ts'o" <[email protected]>
CC Al Viro <[email protected]>
---
 mm/vmscan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmscan.c +2 -2
index 7f30961..fcd1aa0 100644
@@ -280,7 +280,7 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 					nr_pages_scanned, lru_pages,
 					max_pass, delta, total_scan);
 
-		while (total_scan >= batch_size) {
+		do {
 			int nr_before;
 
 			nr_before = do_shrinker_shrink(shrinker, shrink, 0);
@@ -294,7 +294,7 @@ unsigned long shrink_slab(struct shrink_control *shrink,
 			total_scan -= batch_size;
 
 			cond_resched();
-		}
+		} while (total_scan >= batch_size);
 
 		/*
 		 * move the unused scan count back into the shrinker in a
Signature · 7 lines
1.7.11.7

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

Re: [PATCH 1/2] super: fix calculation of shrinkable objects for small numbers

In reply to Glauber Costa
Quoted 26 lines · Glauber Costa

The sysctl knob sysctl_vfs_cache_pressure is used to determine which percentage of the shrinkable objects in our cache we should actively try to shrink.

It works great in situations in which we have many objects (at least more than 100), because the aproximation errors will be negligible. But if this is not the case, specially when total_objects < 100, we may end up concluding that we have no objects at all (total / 100 = 0, if total < 100).

This is certainly not the biggest killer in the world, but may matter in very low kernel memory situations.

CC Dave Chinner <[email protected]>
CC "Theodore Ts'o" <[email protected]>
CC Al Viro <viro-RmSDqhL/[email protected]>
---
 fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/super.c +0 -0
index 12f1237..660552c 100644

fs/super.c static int prune_super(struct shrinker *shrink, struct shrink_control *sc) · line 109

Quoted 7 lines
fs/super.c +1 -1
@@ -104,7 +104,7 @@ static int prune_super(struct shrinker *shrink, struct shrink_control *sc)
 				sb->s_nr_inodes_unused + fs_objects;
 	}
 
-	total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure;
+	total_objects = mult_frac(total_objects, sysctl_vfs_cache_pressure, 100);
 	drop_super(sb);
 	return total_objects;

Hi Glauber,

sysctl_vfs_cache_pressure all over the place with exactly the same calculation. Can you fix all of them in one pass?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] vmscan: take at least one pass with shrinkers

In reply to Glauber Costa
Quoted 5 lines · Glauber Costa

In very low free kernel memory situations, it may be the case that we have less objects to free than our initial batch size. If this is the case, it is better to shrink those, and open space for the new workload then to keep them and fail the new allocations.

Quoted 7 lines

More specifically, this happens because we encode this in a loop with the condition: "while (total_scan >= batch_size)". So if we are in such a case, we'll not even enter the loop.

This patch modifies turns it into a do () while {} loop, that will guarantee that we scan it at least once, while keeping the behaviour exactly the same for the cases in which total_scan > batch_size.

Looks good to me, seems to work just fine.

Signature · 8 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [PATCH 1/2] super: fix calculation of shrinkable objects for small numbers

In reply to Dave Chinner
Quoted 37 lines · Dave Chinner
Quoted 26 lines · Glauber Costa

The sysctl knob sysctl_vfs_cache_pressure is used to determine which percentage of the shrinkable objects in our cache we should actively try to shrink.

It works great in situations in which we have many objects (at least more than 100), because the aproximation errors will be negligible. But if this is not the case, specially when total_objects < 100, we may end up concluding that we have no objects at all (total / 100 = 0, if total < 100).

This is certainly not the biggest killer in the world, but may matter in very low kernel memory situations.

CC Dave Chinner <[email protected]>
CC "Theodore Ts'o" <[email protected]>
CC Al Viro <[email protected]>
---
 fs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/super.c +0 -0
index 12f1237..660552c 100644

fs/super.c static int prune_super(struct shrinker *shrink, struct shrink_control *sc) · line 109

Quoted 7 lines
fs/super.c +1 -1
@@ -104,7 +104,7 @@ static int prune_super(struct shrinker *shrink, struct shrink_control *sc)
 				sb->s_nr_inodes_unused + fs_objects;
 	}
 
-	total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure;
+	total_objects = mult_frac(total_objects, sysctl_vfs_cache_pressure, 100);
 	drop_super(sb);
 	return total_objects;

Hi Glauber,

Quoted 3 lines

sysctl_vfs_cache_pressure all over the place with exactly the same calculation. Can you fix all of them in one pass?

affirmative, sir!