Skip to content

Commit 5025da3

Browse files
Tang Junhuigregkh
authored andcommitted
bcache: initialize dirty stripes in flash_dev_run()
commit 175206cf9ab63161dec74d9cd7f9992e062491f5 upstream. bcache uses a Proportion-Differentiation Controller algorithm to control writeback rate to cached devices. In the PD controller algorithm, dirty stripes of thin flash device should not be counted in, because flash only volumes never write back dirty data. Currently dirty stripe counter for thin flash device is not initialized when the thin flash device starts. Which means the following calculation in PD controller will reference an undefined dirty stripes number, and all cached devices attached to the same cache set where the thin flash device lies on may have an inaccurate writeback rate. This patch calles bch_sectors_dirty_init() in flash_dev_run(), to correctly initialize dirty stripe counter when the thin flash device starts to run. This patch also does following parameter data type change, -void bch_sectors_dirty_init(struct cached_dev *dc); +void bch_sectors_dirty_init(struct bcache_device *); to call this function conveniently in flash_dev_run(). (Commit log is composed by Coly Li) Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn> Reviewed-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4931578 commit 5025da3

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/md/bcache/super.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
10231023
}
10241024

10251025
if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
1026-
bch_sectors_dirty_init(dc);
1026+
bch_sectors_dirty_init(&dc->disk);
10271027
atomic_set(&dc->has_dirty, 1);
10281028
atomic_inc(&dc->count);
10291029
bch_writeback_queue(dc);
@@ -1227,6 +1227,7 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
12271227
goto err;
12281228

12291229
bcache_device_attach(d, c, u - c->uuids);
1230+
bch_sectors_dirty_init(d);
12301231
bch_flash_dev_request_init(d);
12311232
add_disk(d->disk);
12321233

drivers/md/bcache/writeback.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,17 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
488488
return MAP_CONTINUE;
489489
}
490490

491-
void bch_sectors_dirty_init(struct cached_dev *dc)
491+
void bch_sectors_dirty_init(struct bcache_device *d)
492492
{
493493
struct sectors_dirty_init op;
494494

495495
bch_btree_op_init(&op.op, -1);
496-
op.inode = dc->disk.id;
496+
op.inode = d->id;
497497

498-
bch_btree_map_keys(&op.op, dc->disk.c, &KEY(op.inode, 0, 0),
498+
bch_btree_map_keys(&op.op, d->c, &KEY(op.inode, 0, 0),
499499
sectors_dirty_init_fn, 0);
500500

501-
dc->disk.sectors_dirty_last = bcache_dev_sectors_dirty(&dc->disk);
501+
d->sectors_dirty_last = bcache_dev_sectors_dirty(d);
502502
}
503503

504504
void bch_cached_dev_writeback_init(struct cached_dev *dc)

drivers/md/bcache/writeback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static inline void bch_writeback_add(struct cached_dev *dc)
8585

8686
void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
8787

88-
void bch_sectors_dirty_init(struct cached_dev *dc);
88+
void bch_sectors_dirty_init(struct bcache_device *);
8989
void bch_cached_dev_writeback_init(struct cached_dev *);
9090
int bch_cached_dev_writeback_start(struct cached_dev *);
9191

0 commit comments

Comments
 (0)