Skip to content

Commit 49895bc

Browse files
author
NeilBrown
committed
md/raid5: don't let shrink_slab shrink too far.
I have a report of drop_one_stripe() called from raid5_cache_scan() apparently finding ->max_nr_stripes == 0. This should not be allowed. So add a test to keep max_nr_stripes above min_nr_stripes. Also use a 'mask' rather than a 'mod' in drop_one_stripe to ensure 'hash' is valid even if max_nr_stripes does reach zero. Fixes: edbe83a ("md/raid5: allow the stripe_cache to grow and shrink.") Cc: [email protected] (4.1 - please release with 2d5b569) Reported-by: Tomas Papan <[email protected]> Signed-off-by: NeilBrown <[email protected]>
1 parent b6878d9 commit 49895bc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/md/raid5.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
22562256
static int drop_one_stripe(struct r5conf *conf)
22572257
{
22582258
struct stripe_head *sh;
2259-
int hash = (conf->max_nr_stripes - 1) % NR_STRIPE_HASH_LOCKS;
2259+
int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK;
22602260

22612261
spin_lock_irq(conf->hash_locks + hash);
22622262
sh = get_free_stripe(conf, hash);
@@ -6388,7 +6388,8 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink,
63886388

63896389
if (mutex_trylock(&conf->cache_size_mutex)) {
63906390
ret= 0;
6391-
while (ret < sc->nr_to_scan) {
6391+
while (ret < sc->nr_to_scan &&
6392+
conf->max_nr_stripes > conf->min_nr_stripes) {
63926393
if (drop_one_stripe(conf) == 0) {
63936394
ret = SHRINK_STOP;
63946395
break;

0 commit comments

Comments
 (0)