]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: propagate in_flight to whole disk on partition I/O
authorTang Yizhou <yizhou.tang@shopee.com>
Tue, 26 May 2026 02:15:55 +0000 (10:15 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 9 Jun 2026 16:12:50 +0000 (10:12 -0600)
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>
Link: https://patch.msgid.link/20260526021555.359500-1-yizhou.tang@shopee.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
block/blk-merge.c
block/blk-mq.c
block/blk.h

index b0f0a304ea0b8284445e4e448a087d7d44e8bd71..1c637db79e596da8a96f3f2d929cafc1b22acbd2 100644 (file)
@@ -1038,7 +1038,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;
@@ -1069,7 +1069,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);
index ee1d9213f43ebe3346ad53dd681f5e13b99f7516..ab1161ca69f1e80abc620d022f300ac9d934eb5c 100644 (file)
@@ -721,8 +721,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();
        }
 }
index 629e16003eb7086bf547444092add0e9a6141fc4..32ce757e556f46a477134ca8b6e4657658e2d673 100644 (file)
@@ -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();
        }
 }
@@ -1113,7 +1112,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();
 }
 
index 1a2d9101bba046a1c0da7baaea534b201cec3082..7fdfb9012ce1b392f0ad256a6c6fc5cacd1273c2 100644 (file)
@@ -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>
@@ -487,6 +488,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
  */