Skip to content

Commit b2676e1

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm writecache: count number of blocks written, not number of write bios
Change dm-writecache, so that it counts the number of blocks written instead of the number of write bios. Bios can be split and requeued using the dm_accept_partial_bio function, so counting bios caused inaccurate results. Fixes: e3a35d0 ("dm writecache: add event counters") Reported-by: Yu Kuai <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 2c6e755 commit b2676e1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Documentation/admin-guide/device-mapper/writecache.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ Status:
8282
4. the number of blocks under writeback
8383
5. the number of read blocks
8484
6. the number of read blocks that hit the cache
85-
7. the number of write requests
86-
8. the number of write requests that hit uncommitted block
87-
9. the number of write requests that hit committed block
88-
10. the number of write requests that bypass the cache
89-
11. the number of write requests that are allocated in the cache
85+
7. the number of write blocks
86+
8. the number of write blocks that hit uncommitted block
87+
9. the number of write blocks that hit committed block
88+
10. the number of write blocks that bypass the cache
89+
11. the number of write blocks that are allocated in the cache
9090
12. the number of write requests that are blocked on the freelist
9191
13. the number of flush requests
9292
14. the number of discard requests

drivers/md/dm-writecache.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,9 @@ static void writecache_bio_copy_ssd(struct dm_writecache *wc, struct bio *bio,
14131413
bio->bi_iter.bi_sector = start_cache_sec;
14141414
dm_accept_partial_bio(bio, bio_size >> SECTOR_SHIFT);
14151415

1416+
wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
1417+
wc->stats.writes_allocate += (bio->bi_iter.bi_size - wc->block_size) >> wc->block_size_bits;
1418+
14161419
if (unlikely(wc->uncommitted_blocks >= wc->autocommit_blocks)) {
14171420
wc->uncommitted_blocks = 0;
14181421
queue_work(wc->writeback_wq, &wc->flush_work);
@@ -1428,9 +1431,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
14281431
do {
14291432
bool found_entry = false;
14301433
bool search_used = false;
1431-
wc->stats.writes++;
1432-
if (writecache_has_error(wc))
1434+
if (writecache_has_error(wc)) {
1435+
wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
14331436
return WC_MAP_ERROR;
1437+
}
14341438
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0);
14351439
if (e) {
14361440
if (!writecache_entry_is_committed(wc, e)) {
@@ -1454,9 +1458,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
14541458
if (unlikely(!e)) {
14551459
if (!WC_MODE_PMEM(wc) && !found_entry) {
14561460
direct_write:
1457-
wc->stats.writes_around++;
14581461
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING);
14591462
writecache_map_remap_origin(wc, bio, e);
1463+
wc->stats.writes_around += bio->bi_iter.bi_size >> wc->block_size_bits;
1464+
wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
14601465
return WC_MAP_REMAP_ORIGIN;
14611466
}
14621467
wc->stats.writes_blocked_on_freelist++;
@@ -1470,6 +1475,7 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
14701475
bio_copy:
14711476
if (WC_MODE_PMEM(wc)) {
14721477
bio_copy_block(wc, bio, memory_data(wc, e));
1478+
wc->stats.writes++;
14731479
} else {
14741480
writecache_bio_copy_ssd(wc, bio, e, search_used);
14751481
return WC_MAP_REMAP;

0 commit comments

Comments
 (0)