From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
John Garry <john.garry@linux.dev>,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH RFC v2 2/2] nvme-multipath: fix diskstats for partitions
Date: Tue, 18 Aug 2026 12:08:54 +0000 [thread overview]
Message-ID: <20260818120854.3151628-3-john.g.garry@oracle.com> (raw)
In-Reply-To: <20260818120854.3151628-1-john.g.garry@oracle.com>
From: John Garry <john.garry@linux.dev>
Currently diskstats for partitions are never updated:
$ ./fio_read nvme1n1p1 # run traffic on /dev/nvme1n1p1
...
$ more /proc/diskstats | grep nvme1
259 2 nvme1c1n1 49857 0 400344 768565 0 0 0 0 0 2334 768565 0 0 0 0 0 0
259 3 nvme1n1 99710 0 800680 1599285 0 0 0 0 0 2346 1599285 0 0 0 0 0 0
259 5 nvme1n1p1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
259 4 nvme1c2n1 49853 0 400336 831472 0 0 0 0 0 2315 831472 0 0 0 0 0 0
This is because we only ever update the diskstats for the multipath disk in
nvme_mpath_end_request(), and we never take into account that the original
bi_bdev may been a partition of this disk.
Functions bdev_start_io_acct() and bdev_start_io_acct() do handle
updating diskstats for a partition, in that they also update the whole
disk also (if a partition), so use the partition (if applicable) when
calling those functions.
Change any functionality which used to lookup the gendisk part0 to now
lookup the specific gendisk partition.
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
drivers/nvme/host/multipath.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 75dbb58286a32..5c95a2ab7755f 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -144,6 +144,19 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
blk_freeze_queue_start(h->disk->queue);
}
+static struct block_device *nvme_to_disk_part(struct gendisk *disk, u8 partno)
+{
+ struct block_device *bdev;
+
+ /* Quick lookup for whole disk */
+ if (!partno)
+ return disk->part0;
+ rcu_read_lock();
+ bdev = xa_load(&disk->part_tbl, partno);
+ rcu_read_unlock();
+ return bdev;
+}
+
void nvme_failover_req(struct request *req)
{
struct nvme_ns *ns = req->q->queuedata;
@@ -165,8 +178,10 @@ void nvme_failover_req(struct request *req)
}
spin_lock_irqsave(&ns->head->requeue_lock, flags);
- for (bio = req->bio; bio; bio = bio->bi_next)
- bio_set_dev(bio, ns->head->disk->part0);
+ for (bio = req->bio; bio; bio = bio->bi_next) {
+ bio_set_dev(bio, nvme_to_disk_part(ns->head->disk,
+ bdev_partno(bio->bi_bdev)));
+ }
blk_steal_bios(&ns->head->requeue_list, req);
spin_unlock_irqrestore(&ns->head->requeue_lock, flags);
@@ -194,8 +209,9 @@ void nvme_mpath_start_request(struct request *rq)
return;
nvme_req(rq)->flags |= NVME_MPATH_IO_STATS;
- nvme_req(rq)->start_time = bdev_start_io_acct(disk->part0, req_op(rq),
- jiffies);
+ nvme_req(rq)->start_time = bdev_start_io_acct(
+ nvme_to_disk_part(disk, bdev_partno(rq->part)),
+ req_op(rq), jiffies);
}
EXPORT_SYMBOL_GPL(nvme_mpath_start_request);
@@ -208,7 +224,8 @@ void nvme_mpath_end_request(struct request *rq)
if (!(nvme_req(rq)->flags & NVME_MPATH_IO_STATS))
return;
- bdev_end_io_acct(ns->head->disk->part0, req_op(rq),
+ bdev_end_io_acct(nvme_to_disk_part(ns->head->disk,
+ bdev_partno(rq->part)), req_op(rq),
blk_rq_bytes(rq) >> SECTOR_SHIFT,
nvme_req(rq)->start_time);
}
@@ -549,7 +566,9 @@ static void nvme_ns_head_submit_bio(struct bio *bio)
srcu_idx = srcu_read_lock(&head->srcu);
ns = nvme_find_path(head);
if (likely(ns)) {
- bio_set_dev(bio, ns->disk->part0);
+ bio_set_dev(bio, nvme_to_disk_part(ns->disk,
+ bdev_partno(bio->bi_bdev)));
+
/*
* Use BIO_REMAPPED to skip bio_check_eod() when this bio
* enters submit_bio_noacct() for the per-path device. The EOD
--
2.43.7
prev parent reply other threads:[~2026-08-18 12:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 12:08 [PATCH RFC v2 0/2] fix NVMe multipath partition diskstats John Garry
2026-08-18 12:08 ` [PATCH RFC v2 1/2] block: scan partitions for hidden disks John Garry
2026-08-19 9:00 ` Christoph Hellwig
2026-08-19 9:12 ` John Garry
2026-08-19 9:13 ` Christoph Hellwig
2026-08-19 9:43 ` John Garry
2026-08-18 12:08 ` John Garry [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818120854.3151628-3-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=john.garry@linux.dev \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox