Commit 06eed768 authored by Mike Snitzer's avatar Mike Snitzer

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: default avatarMike Snitzer <snitzer@kernel.org>
parent 526d1006
...@@ -487,51 +487,50 @@ u64 dm_start_time_ns_from_clone(struct bio *bio) ...@@ -487,51 +487,50 @@ u64 dm_start_time_ns_from_clone(struct bio *bio)
} }
EXPORT_SYMBOL_GPL(dm_start_time_ns_from_clone); EXPORT_SYMBOL_GPL(dm_start_time_ns_from_clone);
static bool bio_is_flush_with_data(struct bio *bio) static inline bool bio_is_flush_with_data(struct bio *bio)
{ {
return ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size); return ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size);
} }
static void dm_io_acct(struct dm_io *io, bool end) static inline unsigned int dm_io_sectors(struct dm_io *io, struct bio *bio)
{ {
struct dm_stats_aux *stats_aux = &io->stats_aux;
unsigned long start_time = io->start_time;
struct mapped_device *md = io->md;
struct bio *bio = io->orig_bio;
unsigned int sectors;
/* /*
* If REQ_PREFLUSH set, don't account payload, it will be * If REQ_PREFLUSH set, don't account payload, it will be
* submitted (and accounted) after this flush completes. * submitted (and accounted) after this flush completes.
*/ */
if (bio_is_flush_with_data(bio)) if (bio_is_flush_with_data(bio))
sectors = 0; return 0;
else if (likely(!(dm_io_flagged(io, DM_IO_WAS_SPLIT)))) if (unlikely(dm_io_flagged(io, DM_IO_WAS_SPLIT)))
sectors = bio_sectors(bio); return io->sectors;
else return bio_sectors(bio);
sectors = io->sectors; }
static void dm_io_acct(struct dm_io *io, bool end)
{
struct bio *bio = io->orig_bio;
if (dm_io_flagged(io, DM_IO_BLK_STAT)) { if (dm_io_flagged(io, DM_IO_BLK_STAT)) {
if (!end) if (!end)
bdev_start_io_acct(bio->bi_bdev, bio_op(bio), bdev_start_io_acct(bio->bi_bdev, bio_op(bio),
start_time); io->start_time);
else else
bdev_end_io_acct(bio->bi_bdev, bio_op(bio), bdev_end_io_acct(bio->bi_bdev, bio_op(bio),
sectors, start_time); dm_io_sectors(io, bio),
io->start_time);
} }
if (static_branch_unlikely(&stats_enabled) && if (static_branch_unlikely(&stats_enabled) &&
unlikely(dm_stats_used(&md->stats))) { unlikely(dm_stats_used(&io->md->stats))) {
sector_t sector; sector_t sector;
if (likely(!dm_io_flagged(io, DM_IO_WAS_SPLIT))) if (unlikely(dm_io_flagged(io, DM_IO_WAS_SPLIT)))
sector = bio->bi_iter.bi_sector;
else
sector = bio_end_sector(bio) - io->sector_offset; sector = bio_end_sector(bio) - io->sector_offset;
else
sector = bio->bi_iter.bi_sector;
dm_stats_account_io(&md->stats, bio_data_dir(bio), dm_stats_account_io(&io->md->stats, bio_data_dir(bio),
sector, sectors, sector, dm_io_sectors(io, bio),
end, start_time, stats_aux); end, io->start_time, &io->stats_aux);
} }
} }
......
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