Skip to content

Commit 526d100

Browse files
Li NanMike Snitzer
authored andcommitted
dm: support turning off block-core's io stats accounting
Commit bc58ba9 ("block: add sysfs file for controlling io stats accounting") allowed users to turn off disk stat accounting completely by checking if queue flag QUEUE_FLAG_IO_STAT is set. In dm, this flag is neither set nor checked: so block-core's io stats are continuously counted and cannot be turned off. Add support for turning off block-core's io stats accounting for dm. Set QUEUE_FLAG_IO_STAT for dm's request_queue. If QUEUE_FLAG_IO_STAT is set when an io starts, record the need for block core's io stats by setting the DM_IO_BLK_STAT dm_io flag to avoid io stats being disabled in the middle of the io. DM statistics (dm-stats) is independent of block-core's io stats and remains unchanged. Signed-off-by: Li Nan <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent e118029 commit 526d100

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

drivers/md/dm-core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ struct dm_io {
306306
*/
307307
enum {
308308
DM_IO_ACCOUNTED,
309-
DM_IO_WAS_SPLIT
309+
DM_IO_WAS_SPLIT,
310+
DM_IO_BLK_STAT
310311
};
311312

312313
static inline bool dm_io_flagged(struct dm_io *io, unsigned int bit)

drivers/md/dm.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,14 @@ static void dm_io_acct(struct dm_io *io, bool end)
511511
else
512512
sectors = io->sectors;
513513

514-
if (!end)
515-
bdev_start_io_acct(bio->bi_bdev, bio_op(bio), start_time);
516-
else
517-
bdev_end_io_acct(bio->bi_bdev, bio_op(bio), sectors,
518-
start_time);
514+
if (dm_io_flagged(io, DM_IO_BLK_STAT)) {
515+
if (!end)
516+
bdev_start_io_acct(bio->bi_bdev, bio_op(bio),
517+
start_time);
518+
else
519+
bdev_end_io_acct(bio->bi_bdev, bio_op(bio),
520+
sectors, start_time);
521+
}
519522

520523
if (static_branch_unlikely(&stats_enabled) &&
521524
unlikely(dm_stats_used(&md->stats))) {
@@ -592,6 +595,8 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
592595
spin_lock_init(&io->lock);
593596
io->start_time = jiffies;
594597
io->flags = 0;
598+
if (blk_queue_io_stat(md->queue))
599+
dm_io_set_flag(io, DM_IO_BLK_STAT);
595600

596601
if (static_branch_unlikely(&stats_enabled))
597602
dm_stats_record_start(&md->stats, &io->stats_aux);
@@ -2341,6 +2346,7 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
23412346
break;
23422347
case DM_TYPE_BIO_BASED:
23432348
case DM_TYPE_DAX_BIO_BASED:
2349+
blk_queue_flag_set(QUEUE_FLAG_IO_STAT, md->queue);
23442350
break;
23452351
case DM_TYPE_NONE:
23462352
WARN_ON_ONCE(true);

0 commit comments

Comments
 (0)