Commit b2676e14 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

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: e3a35d03 ("dm writecache: add event counters")
Reported-by: default avatarYu Kuai <yukuai1@huaweicloud.com>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent 2c6e755b
...@@ -82,11 +82,11 @@ Status: ...@@ -82,11 +82,11 @@ Status:
4. the number of blocks under writeback 4. the number of blocks under writeback
5. the number of read blocks 5. the number of read blocks
6. the number of read blocks that hit the cache 6. the number of read blocks that hit the cache
7. the number of write requests 7. the number of write blocks
8. the number of write requests that hit uncommitted block 8. the number of write blocks that hit uncommitted block
9. the number of write requests that hit committed block 9. the number of write blocks that hit committed block
10. the number of write requests that bypass the cache 10. the number of write blocks that bypass the cache
11. the number of write requests that are allocated in the cache 11. the number of write blocks that are allocated in the cache
12. the number of write requests that are blocked on the freelist 12. the number of write requests that are blocked on the freelist
13. the number of flush requests 13. the number of flush requests
14. the number of discard requests 14. the number of discard requests
......
...@@ -1413,6 +1413,9 @@ static void writecache_bio_copy_ssd(struct dm_writecache *wc, struct bio *bio, ...@@ -1413,6 +1413,9 @@ static void writecache_bio_copy_ssd(struct dm_writecache *wc, struct bio *bio,
bio->bi_iter.bi_sector = start_cache_sec; bio->bi_iter.bi_sector = start_cache_sec;
dm_accept_partial_bio(bio, bio_size >> SECTOR_SHIFT); dm_accept_partial_bio(bio, bio_size >> SECTOR_SHIFT);
wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
wc->stats.writes_allocate += (bio->bi_iter.bi_size - wc->block_size) >> wc->block_size_bits;
if (unlikely(wc->uncommitted_blocks >= wc->autocommit_blocks)) { if (unlikely(wc->uncommitted_blocks >= wc->autocommit_blocks)) {
wc->uncommitted_blocks = 0; wc->uncommitted_blocks = 0;
queue_work(wc->writeback_wq, &wc->flush_work); 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 ...@@ -1428,9 +1431,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
do { do {
bool found_entry = false; bool found_entry = false;
bool search_used = false; bool search_used = false;
wc->stats.writes++; if (writecache_has_error(wc)) {
if (writecache_has_error(wc)) wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
return WC_MAP_ERROR; return WC_MAP_ERROR;
}
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0); e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0);
if (e) { if (e) {
if (!writecache_entry_is_committed(wc, e)) { 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 ...@@ -1454,9 +1458,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
if (unlikely(!e)) { if (unlikely(!e)) {
if (!WC_MODE_PMEM(wc) && !found_entry) { if (!WC_MODE_PMEM(wc) && !found_entry) {
direct_write: direct_write:
wc->stats.writes_around++;
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING); e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING);
writecache_map_remap_origin(wc, bio, e); writecache_map_remap_origin(wc, bio, e);
wc->stats.writes_around += bio->bi_iter.bi_size >> wc->block_size_bits;
wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits;
return WC_MAP_REMAP_ORIGIN; return WC_MAP_REMAP_ORIGIN;
} }
wc->stats.writes_blocked_on_freelist++; wc->stats.writes_blocked_on_freelist++;
...@@ -1470,6 +1475,7 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio ...@@ -1470,6 +1475,7 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio
bio_copy: bio_copy:
if (WC_MODE_PMEM(wc)) { if (WC_MODE_PMEM(wc)) {
bio_copy_block(wc, bio, memory_data(wc, e)); bio_copy_block(wc, bio, memory_data(wc, e));
wc->stats.writes++;
} else { } else {
writecache_bio_copy_ssd(wc, bio, e, search_used); writecache_bio_copy_ssd(wc, bio, e, search_used);
return WC_MAP_REMAP; return WC_MAP_REMAP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment