[dm-devel] dm: fix dm_stats accounting

Mike Snitzer snitzer at redhat.com
Fri Feb 11 16:08:05 UTC 2022


On Fri, Feb 11 2022 at 10:01P -0500,
Mikulas Patocka <mpatocka at redhat.com> wrote:

> Exactly the same sector number and length must be passed to both calls of
> dm_stats_account_io, otherwise its per-zone in_flight counters go out of
> sync. This patch fixes it.
> 
> Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>
> 
> ---
>  drivers/md/dm.c |   10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> Index: linux-dm/drivers/md/dm.c
> ===================================================================
> --- linux-dm.orig/drivers/md/dm.c	2022-02-11 15:32:56.000000000 +0100
> +++ linux-dm/drivers/md/dm.c	2022-02-11 15:40:11.000000000 +0100
> @@ -487,16 +487,20 @@ EXPORT_SYMBOL_GPL(dm_start_time_ns_from_
>  
>  static void start_io_acct(struct dm_io *io, struct bio *bio)
>  {
> +	struct bio *orig_bio;
> +
>  	/* Ensure IO accounting is only ever started once */
>  	if (xchg(&io->was_accounted, 1) == 1)
>  		return;
>  
> +	orig_bio = io->orig_bio;
> +
>  	bio_start_io_acct_remapped(bio, io->start_time,
> -				   io->orig_bio->bi_bdev);
> +				   orig_bio->bi_bdev);
>  
>  	if (unlikely(dm_stats_used(&io->md->stats)))
> -		dm_stats_account_io(&io->md->stats, bio_data_dir(bio),
> -				    bio->bi_iter.bi_sector, bio_sectors(bio),
> +		dm_stats_account_io(&io->md->stats, bio_data_dir(orig_bio),
> +				    orig_bio->bi_iter.bi_sector, bio_sectors(orig_bio),
>  				    false, 0, &io->stats_aux);
>  }
>  
> 

You cannot account using the orig_bio because it doesn't reflect
splits that occurred.  orig_bio will be updated to reflect the split
after __map_bio returns all the way back to dm_split_and_process_bio.

So there is no imbalance between start_io_acct and end_io_acct's calls
to dm_stats_account_io.

Also, in_flight counters don't (or shouldn't) care about the payload.

So again, I'm not following the reasoning on this patch.

Mike




More information about the dm-devel mailing list