Commit e9299f5058595a655c3b207cda9635e28b9197e6
Committed by
Al Viro
1 parent
3567b59aa8
Exists in
master
and in
6 other branches
vmscan: add customisable shrinker batch size
For shrinkers that have their own cond_resched* calls, having shrink_slab break the work down into small batches is not paticularly efficient. Add a custom batchsize field to the struct shrinker so that shrinkers can use a larger batch size if they desire. A value of zero (uninitialised) means "use the default", so behaviour is unchanged by this patch. Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 2 changed files with 7 additions and 5 deletions Side-by-side Diff
include/linux/mm.h
... | ... | @@ -1150,6 +1150,7 @@ |
1150 | 1150 | struct shrinker { |
1151 | 1151 | int (*shrink)(struct shrinker *, struct shrink_control *sc); |
1152 | 1152 | int seeks; /* seeks to recreate an obj */ |
1153 | + long batch; /* reclaim batch size, 0 = default */ | |
1153 | 1154 | |
1154 | 1155 | /* These are for internal use */ |
1155 | 1156 | struct list_head list; |
mm/vmscan.c
... | ... | @@ -253,6 +253,8 @@ |
253 | 253 | int shrink_ret = 0; |
254 | 254 | long nr; |
255 | 255 | long new_nr; |
256 | + long batch_size = shrinker->batch ? shrinker->batch | |
257 | + : SHRINK_BATCH; | |
256 | 258 | |
257 | 259 | /* |
258 | 260 | * copy the current shrinker scan count into a local variable |
259 | 261 | |
260 | 262 | |
... | ... | @@ -303,19 +305,18 @@ |
303 | 305 | nr_pages_scanned, lru_pages, |
304 | 306 | max_pass, delta, total_scan); |
305 | 307 | |
306 | - while (total_scan >= SHRINK_BATCH) { | |
307 | - long this_scan = SHRINK_BATCH; | |
308 | + while (total_scan >= batch_size) { | |
308 | 309 | int nr_before; |
309 | 310 | |
310 | 311 | nr_before = do_shrinker_shrink(shrinker, shrink, 0); |
311 | 312 | shrink_ret = do_shrinker_shrink(shrinker, shrink, |
312 | - this_scan); | |
313 | + batch_size); | |
313 | 314 | if (shrink_ret == -1) |
314 | 315 | break; |
315 | 316 | if (shrink_ret < nr_before) |
316 | 317 | ret += nr_before - shrink_ret; |
317 | - count_vm_events(SLABS_SCANNED, this_scan); | |
318 | - total_scan -= this_scan; | |
318 | + count_vm_events(SLABS_SCANNED, batch_size); | |
319 | + total_scan -= batch_size; | |
319 | 320 | |
320 | 321 | cond_resched(); |
321 | 322 | } |