Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a14a68b

Browse files
yangdongshengaxboe
authored andcommitted
bcache: allow allocator to invalidate bucket in gc
Currently, if the gc is running, when the allocator found free_inc is empty, allocator has to wait the gc finish. Before that, the IO is blocked. But actually, there would be some buckets is reclaimable before gc, and gc will never mark this kind of bucket to be unreclaimable. So we can put these buckets into free_inc in gc running to avoid IO being blocked. Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn> Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn> Signed-off-by: Coly Li <colyli@suse.de> Link: https://lore.kernel.org/r/20240528120914.28705-2-colyli@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e993db2 commit a14a68b

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

drivers/md/bcache/alloc.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,9 @@ static inline bool can_inc_bucket_gen(struct bucket *b)
129129

130130
bool bch_can_invalidate_bucket(struct cache *ca, struct bucket *b)
131131
{
132-
BUG_ON(!ca->set->gc_mark_valid);
133-
134-
return (!GC_MARK(b) ||
135-
GC_MARK(b) == GC_MARK_RECLAIMABLE) &&
136-
!atomic_read(&b->pin) &&
137-
can_inc_bucket_gen(b);
132+
return (ca->set->gc_mark_valid || b->reclaimable_in_gc) &&
133+
((!GC_MARK(b) || GC_MARK(b) == GC_MARK_RECLAIMABLE) &&
134+
!atomic_read(&b->pin) && can_inc_bucket_gen(b));
138135
}
139136

140137
void __bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
@@ -148,6 +145,7 @@ void __bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
148145
bch_inc_gen(ca, b);
149146
b->prio = INITIAL_PRIO;
150147
atomic_inc(&b->pin);
148+
b->reclaimable_in_gc = 0;
151149
}
152150

153151
static void bch_invalidate_one_bucket(struct cache *ca, struct bucket *b)
@@ -352,8 +350,7 @@ static int bch_allocator_thread(void *arg)
352350
*/
353351

354352
retry_invalidate:
355-
allocator_wait(ca, ca->set->gc_mark_valid &&
356-
!ca->invalidate_needs_gc);
353+
allocator_wait(ca, !ca->invalidate_needs_gc);
357354
invalidate_buckets(ca);
358355

359356
/*

drivers/md/bcache/bcache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct bucket {
200200
uint8_t gen;
201201
uint8_t last_gc; /* Most out of date gen in the btree */
202202
uint16_t gc_mark; /* Bitfield used by GC. See below for field */
203+
uint16_t reclaimable_in_gc:1;
203204
};
204205

205206
/*

drivers/md/bcache/btree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,18 +1741,20 @@ static void btree_gc_start(struct cache_set *c)
17411741

17421742
mutex_lock(&c->bucket_lock);
17431743

1744-
c->gc_mark_valid = 0;
17451744
c->gc_done = ZERO_KEY;
17461745

17471746
ca = c->cache;
17481747
for_each_bucket(b, ca) {
17491748
b->last_gc = b->gen;
1749+
if (bch_can_invalidate_bucket(ca, b))
1750+
b->reclaimable_in_gc = 1;
17501751
if (!atomic_read(&b->pin)) {
17511752
SET_GC_MARK(b, 0);
17521753
SET_GC_SECTORS_USED(b, 0);
17531754
}
17541755
}
17551756

1757+
c->gc_mark_valid = 0;
17561758
mutex_unlock(&c->bucket_lock);
17571759
}
17581760

@@ -1809,6 +1811,9 @@ static void bch_btree_gc_finish(struct cache_set *c)
18091811
for_each_bucket(b, ca) {
18101812
c->need_gc = max(c->need_gc, bucket_gc_gen(b));
18111813

1814+
if (b->reclaimable_in_gc)
1815+
b->reclaimable_in_gc = 0;
1816+
18121817
if (atomic_read(&b->pin))
18131818
continue;
18141819

0 commit comments

Comments
 (0)