Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: Fix GC_SECTORS_USED() calculation

Part of the job of garbage collection is to add up however many sectors
of live data it finds in each bucket, but that doesn't work very well if
it doesn't reset GC_SECTORS_USED() when it starts. Whoops.

This wouldn't have broken anything horribly, but allocation tries to
preferentially reclaim buckets that are mostly empty and that's not
gonna work with an incorrect GC_SECTORS_USED() value.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10

+3 -1
+3 -1
drivers/md/bcache/btree.c
··· 1410 1410 for_each_cache(ca, c, i) 1411 1411 for_each_bucket(b, ca) { 1412 1412 b->gc_gen = b->gen; 1413 - if (!atomic_read(&b->pin)) 1413 + if (!atomic_read(&b->pin)) { 1414 1414 SET_GC_MARK(b, GC_MARK_RECLAIMABLE); 1415 + SET_GC_SECTORS_USED(b, 0); 1416 + } 1415 1417 } 1416 1418 1417 1419 mutex_unlock(&c->bucket_lock);