Skip to content

Commit 06eed76

Browse files
author
Mike Snitzer
committed
dm: avoid needless dm_io access if all IO accounting is disabled
Update dm_io_acct() to eliminate most dm_io struct accesses if both block core's IO stats and dm-stats are disabled. Signed-off-by: Mike Snitzer <[email protected]>
1 parent 526d100 commit 06eed76

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

drivers/md/dm.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -487,51 +487,50 @@ u64 dm_start_time_ns_from_clone(struct bio *bio)
487487
}
488488
EXPORT_SYMBOL_GPL(dm_start_time_ns_from_clone);
489489

490-
static bool bio_is_flush_with_data(struct bio *bio)
490+
static inline bool bio_is_flush_with_data(struct bio *bio)
491491
{
492492
return ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size);
493493
}
494494

495-
static void dm_io_acct(struct dm_io *io, bool end)
495+
static inline unsigned int dm_io_sectors(struct dm_io *io, struct bio *bio)
496496
{
497-
struct dm_stats_aux *stats_aux = &io->stats_aux;
498-
unsigned long start_time = io->start_time;
499-
struct mapped_device *md = io->md;
500-
struct bio *bio = io->orig_bio;
501-
unsigned int sectors;
502-
503497
/*
504498
* If REQ_PREFLUSH set, don't account payload, it will be
505499
* submitted (and accounted) after this flush completes.
506500
*/
507501
if (bio_is_flush_with_data(bio))
508-
sectors = 0;
509-
else if (likely(!(dm_io_flagged(io, DM_IO_WAS_SPLIT))))
510-
sectors = bio_sectors(bio);
511-
else
512-
sectors = io->sectors;
502+
return 0;
503+
if (unlikely(dm_io_flagged(io, DM_IO_WAS_SPLIT)))
504+
return io->sectors;
505+
return bio_sectors(bio);
506+
}
507+
508+
static void dm_io_acct(struct dm_io *io, bool end)
509+
{
510+
struct bio *bio = io->orig_bio;
513511

514512
if (dm_io_flagged(io, DM_IO_BLK_STAT)) {
515513
if (!end)
516514
bdev_start_io_acct(bio->bi_bdev, bio_op(bio),
517-
start_time);
515+
io->start_time);
518516
else
519517
bdev_end_io_acct(bio->bi_bdev, bio_op(bio),
520-
sectors, start_time);
518+
dm_io_sectors(io, bio),
519+
io->start_time);
521520
}
522521

523522
if (static_branch_unlikely(&stats_enabled) &&
524-
unlikely(dm_stats_used(&md->stats))) {
523+
unlikely(dm_stats_used(&io->md->stats))) {
525524
sector_t sector;
526525

527-
if (likely(!dm_io_flagged(io, DM_IO_WAS_SPLIT)))
528-
sector = bio->bi_iter.bi_sector;
529-
else
526+
if (unlikely(dm_io_flagged(io, DM_IO_WAS_SPLIT)))
530527
sector = bio_end_sector(bio) - io->sector_offset;
528+
else
529+
sector = bio->bi_iter.bi_sector;
531530

532-
dm_stats_account_io(&md->stats, bio_data_dir(bio),
533-
sector, sectors,
534-
end, start_time, stats_aux);
531+
dm_stats_account_io(&io->md->stats, bio_data_dir(bio),
532+
sector, dm_io_sectors(io, bio),
533+
end, io->start_time, &io->stats_aux);
535534
}
536535
}
537536

0 commit comments

Comments
 (0)