* [PATCH v7] block: propagate in_flight to whole disk on partition I/O
@ 2026-05-26 2:15 Tang Yizhou
2026-05-27 14:10 ` Christoph Hellwig
2026-06-09 16:13 ` Jens Axboe
0 siblings, 2 replies; 4+ messages in thread
From: Tang Yizhou @ 2026-05-26 2:15 UTC (permalink / raw)
To: axboe, hch, kbusch
Cc: yukuai, linux-block, linux-kernel, Tang Yizhou, Leon Hwang
From: Tang Yizhou <yizhou.tang@shopee.com>
Now when I/O is submitted to a partition, the per-CPU in_flight[]
counter is incremented only on the partition's block_device, not on the
underlying whole disk. This leads to a problem which can be shown by a
fio test:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
mydev 252:1 0 20G 0 disk
└─mydev1 259:0 0 10G 0 part
iostat -xp 1
Device r/s rkB/s ... aqu-sz %util
mydev 128153.00 512612.00 ... 13.22 72.20
mydev1 128154.00 512616.00 ... 13.22 100.00
%util is different between mydev and mydev1, which is unexpected.
This is the cumulative effect of a series of patches. The root cause is
commit e016b78201a2 ("block: return just one value from part_in_flight"),
which deleted the branch in part_in_flight() that aggregated the whole-disk
in_flight count on top of the partition's. Then the second commit is
commit 10ec5e86f9b8 ("block: merge part_{inc,dev}_in_flight into their
only callers"), which folded the whole-disk in_flight accounting into
generic_start_io_acct() and generic_end_io_acct(). Those two helpers
were then removed by commit e722fff238bb ("block: remove
generic_{start,end}_io_acct"), and from that point on the whole disk's
in_flight is no longer accounted at all.
In update_io_ticks(), if calling bdev_count_inflight() finds that the
inflight value of the whole device is 0, the accumulation of io_ticks will
be skipped, causing the reported util% value to be underestimated.
Fix it by restoring the whole-disk in_flight accounting.
Fixes: e016b78201a2 ("block: return just one value from part_in_flight")
Suggested-by: Leon Hwang <leon.huangfu@shopee.com>
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Tang Yizhou <yizhou.tang@shopee.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
v2: Update commit message.
v3: Take Christoph's advice and factor the common code into two helpers.
v4: Remove my redundant new line in blk.h. Add Christoph's Reviewed-by
tag.
v5: Remove the changelog from the commit message.
v6: Accept Keith's suggestion and fix the bug in bdev_end_io_acct().
v7: Address the review feedback from Claude Opus 4.7 and update
blk_account_io_merge_request().
block/blk-core.c | 4 ++--
block/blk-merge.c | 3 +--
block/blk-mq.c | 5 ++---
block/blk.h | 21 +++++++++++++++++++++
4 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index 17450058ea6d..cee4e4a37503 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1042,7 +1042,7 @@ unsigned long bdev_start_io_acct(struct block_device *bdev, enum req_op op,
{
part_stat_lock();
update_io_ticks(bdev, start_time, false);
- part_stat_local_inc(bdev, in_flight[op_is_write(op)]);
+ bdev_inc_in_flight(bdev, op);
part_stat_unlock();
return start_time;
@@ -1073,7 +1073,7 @@ void bdev_end_io_acct(struct block_device *bdev, enum req_op op,
part_stat_inc(bdev, ios[sgrp]);
part_stat_add(bdev, sectors[sgrp], sectors);
part_stat_add(bdev, nsecs[sgrp], jiffies_to_nsecs(duration));
- part_stat_local_dec(bdev, in_flight[op_is_write(op)]);
+ bdev_dec_in_flight(bdev, op);
part_stat_unlock();
}
EXPORT_SYMBOL(bdev_end_io_acct);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index fcf09325b22e..62d68a72f569 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -723,8 +723,7 @@ static void blk_account_io_merge_request(struct request *req)
if (req->rq_flags & RQF_IO_STAT) {
part_stat_lock();
part_stat_inc(req->part, merges[op_stat_group(req_op(req))]);
- part_stat_local_dec(req->part,
- in_flight[op_is_write(req_op(req))]);
+ bdev_dec_in_flight(req->part, req_op(req));
part_stat_unlock();
}
}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index d0c37daf568f..6bdfe642bd93 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1082,8 +1082,7 @@ static inline void blk_account_io_done(struct request *req, u64 now)
update_io_ticks(req->part, jiffies, true);
part_stat_inc(req->part, ios[sgrp]);
part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns);
- part_stat_local_dec(req->part,
- in_flight[op_is_write(req_op(req))]);
+ bdev_dec_in_flight(req->part, req_op(req));
part_stat_unlock();
}
}
@@ -1143,7 +1142,7 @@ static inline void blk_account_io_start(struct request *req)
part_stat_lock();
update_io_ticks(req->part, jiffies, false);
- part_stat_local_inc(req->part, in_flight[op_is_write(req_op(req))]);
+ bdev_inc_in_flight(req->part, req_op(req));
part_stat_unlock();
}
diff --git a/block/blk.h b/block/blk.h
index b998a7761faf..11245a494c43 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -4,6 +4,7 @@
#include <linux/bio-integrity.h>
#include <linux/blk-crypto.h>
+#include <linux/part_stat.h>
#include <linux/lockdep.h>
#include <linux/memblock.h> /* for max_pfn/max_low_pfn */
#include <linux/sched/sysctl.h>
@@ -485,6 +486,26 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)
q->last_merge = NULL;
}
+static inline void bdev_inc_in_flight(struct block_device *bdev,
+ enum req_op op)
+{
+ bool rw = op_is_write(op);
+
+ part_stat_local_inc(bdev, in_flight[rw]);
+ if (bdev_is_partition(bdev))
+ part_stat_local_inc(bdev_whole(bdev), in_flight[rw]);
+}
+
+static inline void bdev_dec_in_flight(struct block_device *bdev,
+ enum req_op op)
+{
+ bool rw = op_is_write(op);
+
+ part_stat_local_dec(bdev, in_flight[rw]);
+ if (bdev_is_partition(bdev))
+ part_stat_local_dec(bdev_whole(bdev), in_flight[rw]);
+}
+
/*
* Internal io_context interface
*/
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v7] block: propagate in_flight to whole disk on partition I/O
2026-05-26 2:15 [PATCH v7] block: propagate in_flight to whole disk on partition I/O Tang Yizhou
@ 2026-05-27 14:10 ` Christoph Hellwig
2026-06-09 15:28 ` Yizhou Tang
2026-06-09 16:13 ` Jens Axboe
1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2026-05-27 14:10 UTC (permalink / raw)
To: Tang Yizhou; +Cc: axboe, kbusch, yukuai, linux-block, linux-kernel, Leon Hwang
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v7] block: propagate in_flight to whole disk on partition I/O
2026-05-27 14:10 ` Christoph Hellwig
@ 2026-06-09 15:28 ` Yizhou Tang
0 siblings, 0 replies; 4+ messages in thread
From: Yizhou Tang @ 2026-06-09 15:28 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Tang Yizhou, axboe, kbusch, yukuai, linux-block, linux-kernel,
Leon Hwang
On Wed, May 27, 2026 at 10:11 PM Christoph Hellwig <hch@lst.de> wrote:
>
> Looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
Hi Jens,
This patch has been on the list for over two weeks without any new
review comments. If you have no objections, please consider picking it
up for the next merge window.
Best regards,
Yi
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v7] block: propagate in_flight to whole disk on partition I/O
2026-05-26 2:15 [PATCH v7] block: propagate in_flight to whole disk on partition I/O Tang Yizhou
2026-05-27 14:10 ` Christoph Hellwig
@ 2026-06-09 16:13 ` Jens Axboe
1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-06-09 16:13 UTC (permalink / raw)
To: hch, kbusch, Tang Yizhou; +Cc: yukuai, linux-block, linux-kernel, Leon Hwang
On Tue, 26 May 2026 10:15:55 +0800, Tang Yizhou wrote:
> Now when I/O is submitted to a partition, the per-CPU in_flight[]
> counter is incremented only on the partition's block_device, not on the
> underlying whole disk. This leads to a problem which can be shown by a
> fio test:
>
> lsblk
> NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
> mydev 252:1 0 20G 0 disk
> └─mydev1 259:0 0 10G 0 part
>
> [...]
Applied, thanks!
[1/1] block: propagate in_flight to whole disk on partition I/O
commit: 5bdb8ec58b54b0e86672ba1991087611c7e52de5
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-09 16:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 2:15 [PATCH v7] block: propagate in_flight to whole disk on partition I/O Tang Yizhou
2026-05-27 14:10 ` Christoph Hellwig
2026-06-09 15:28 ` Yizhou Tang
2026-06-09 16:13 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox