Skip to content

Commit 175206c

Browse files
Tang Junhuiaxboe
authored andcommitted
bcache: initialize dirty stripes in flash_dev_run()
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 <[email protected]> Reviewed-by: Coly Li <[email protected]> Cc: [email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent bf09375 commit 175206c

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

drivers/md/bcache/super.c

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

10281028
if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
1029-
bch_sectors_dirty_init(dc);
1029+
bch_sectors_dirty_init(&dc->disk);
10301030
atomic_set(&dc->has_dirty, 1);
10311031
atomic_inc(&dc->count);
10321032
bch_writeback_queue(dc);
@@ -1230,6 +1230,7 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
12301230
goto err;
12311231

12321232
bcache_device_attach(d, c, u - c->uuids);
1233+
bch_sectors_dirty_init(d);
12331234
bch_flash_dev_request_init(d);
12341235
add_disk(d->disk);
12351236

drivers/md/bcache/writeback.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,17 @@ static int sectors_dirty_init_fn(struct btree_op *_op, struct btree *b,
482482
return MAP_CONTINUE;
483483
}
484484

485-
void bch_sectors_dirty_init(struct cached_dev *dc)
485+
void bch_sectors_dirty_init(struct bcache_device *d)
486486
{
487487
struct sectors_dirty_init op;
488488

489489
bch_btree_op_init(&op.op, -1);
490-
op.inode = dc->disk.id;
490+
op.inode = d->id;
491491

492-
bch_btree_map_keys(&op.op, dc->disk.c, &KEY(op.inode, 0, 0),
492+
bch_btree_map_keys(&op.op, d->c, &KEY(op.inode, 0, 0),
493493
sectors_dirty_init_fn, 0);
494494

495-
dc->disk.sectors_dirty_last = bcache_dev_sectors_dirty(&dc->disk);
495+
d->sectors_dirty_last = bcache_dev_sectors_dirty(d);
496496
}
497497

498498
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
@@ -103,7 +103,7 @@ static inline void bch_writeback_add(struct cached_dev *dc)
103103

104104
void bcache_dev_sectors_dirty_add(struct cache_set *, unsigned, uint64_t, int);
105105

106-
void bch_sectors_dirty_init(struct cached_dev *dc);
106+
void bch_sectors_dirty_init(struct bcache_device *);
107107
void bch_cached_dev_writeback_init(struct cached_dev *);
108108
int bch_cached_dev_writeback_start(struct cached_dev *);
109109

0 commit comments

Comments
 (0)