Hi Tang Junhui-- On 03/05/2018 11:53 PM, tang.junhui@xxxxxxxxxx wrote: > From: Tang Junhui <tang.junhui@xxxxxxxxxx> > > In bch_mca_scan(), There are some confusion and logical error in the use of > loop variables. In this patch, we clarify them as: > 1) nr: the number of btree nodes needs to scan, which will decrease after > we scan a btree node, and should not be less than 0; > 2) i: the number of btree nodes have scanned, includes both > btree_cache_freeable and btree_cache, which should not be bigger than > btree_cache_used; > 3) freed: the number of btree nodes have freed. Thanks-- this looks better. Applied to my tree. Incidentally, I still get DOS line endings with the patches you send out, and I'm not sure why. I can fix it with checkpatch, so it's not a big deal. Maybe it relates to the git version you're using? Mike > > Signed-off-by: Tang Junhui <tang.junhui@xxxxxxxxxx> > --- > drivers/md/bcache/btree.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c > index 81e8dc3..7487f8e 100644 > --- a/drivers/md/bcache/btree.c > +++ b/drivers/md/bcache/btree.c > @@ -664,6 +664,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, > struct btree *b, *t; > unsigned long i, nr = sc->nr_to_scan; > unsigned long freed = 0; > + unsigned int btree_cache_used; > > if (c->shrinker_disabled) > return SHRINK_STOP; > @@ -688,9 +689,10 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, > nr = min_t(unsigned long, nr, mca_can_free(c)); > > i = 0; > + btree_cache_used = c->btree_cache_used; > list_for_each_entry_safe(b, t, &c->btree_cache_freeable, list) { > - if (freed >= nr) > - break; > + if (nr <= 0) > + goto out; > > if (++i > 3 && > !mca_reap(b, 0, false)) { > @@ -698,9 +700,10 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, > rw_unlock(true, b); > freed++; > } > + nr--; > } > > - for (i = 0; (nr--) && i < c->btree_cache_used; i++) { > + for (; (nr--) && i < btree_cache_used; i++) { > if (list_empty(&c->btree_cache)) > goto out; > > -- To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html