Skip to content

Commit

Permalink
md/raid5: don't let shrink_slab shrink too far.
Browse files Browse the repository at this point in the history
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: stable@vger.kernel.org (4.1 - please release with 2d5b569)
Reported-by: Tomas Papan <tomas.papan@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.com>
  • Loading branch information
NeilBrown committed Aug 3, 2015
1 parent b6878d9 commit 49895bc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/md/raid5.c
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
static int drop_one_stripe(struct r5conf *conf)
{
struct stripe_head *sh;
int hash = (conf->max_nr_stripes - 1) % NR_STRIPE_HASH_LOCKS;
int hash = (conf->max_nr_stripes - 1) & STRIPE_HASH_LOCKS_MASK;

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

if (mutex_trylock(&conf->cache_size_mutex)) {
ret= 0;
while (ret < sc->nr_to_scan) {
while (ret < sc->nr_to_scan &&
conf->max_nr_stripes > conf->min_nr_stripes) {
if (drop_one_stripe(conf) == 0) {
ret = SHRINK_STOP;
break;
Expand Down

0 comments on commit 49895bc

Please sign in to comment.