summaryrefslogtreecommitdiff
path: root/block/genhd.c
diff options
context:
space:
mode:
authorYu Kuai <yukuai3@huawei.com>2025-05-06 15:48:59 +0300
committerYu Kuai <yukuai3@huawei.com>2025-05-10 11:11:49 +0300
commitf2987c5816bda01a8ffdd4eb5dfaaa2b41b67039 (patch)
treee2888571239e81a2341b39a04179b892e9903f13 /block/genhd.c
parent6b6c3a97abdebfafa25ef0f4b6b0b8b412b57bbb (diff)
downloadlinux-f2987c5816bda01a8ffdd4eb5dfaaa2b41b67039.tar.xz
block: export API to get the number of bdev inflight IO
- rename part_in_{flight, flight_rw} to bdev_count_{inflight, inflight_rw} - export bdev_count_inflight, to fix a problem in mdraid that foreground IO can be starved by background sync IO in later patches Link: https://lore.kernel.org/linux-raid/20250506124903.2540268-6-yukuai1@huaweicloud.com Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 1c1a642b321e..8171a6bc3210 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -125,7 +125,7 @@ static void part_stat_read_all(struct block_device *part,
}
}
-static void part_in_flight_rw(struct block_device *part,
+static void bdev_count_inflight_rw(struct block_device *part,
unsigned int inflight[2], bool mq_driver)
{
int cpu;
@@ -147,14 +147,24 @@ static void part_in_flight_rw(struct block_device *part,
inflight[WRITE] = 0;
}
-unsigned int part_in_flight(struct block_device *part)
+/**
+ * bdev_count_inflight - get the number of inflight IOs for a block device.
+ *
+ * @part: the block device.
+ *
+ * Inflight here means started IO accounting, from bdev_start_io_acct() for
+ * bio-based block device, and from blk_account_io_start() for rq-based block
+ * device.
+ */
+unsigned int bdev_count_inflight(struct block_device *part)
{
unsigned int inflight[2] = {0};
- part_in_flight_rw(part, inflight, false);
+ bdev_count_inflight_rw(part, inflight, false);
return inflight[READ] + inflight[WRITE];
}
+EXPORT_SYMBOL_GPL(bdev_count_inflight);
/*
* Can be deleted altogether. Later.
@@ -1052,7 +1062,7 @@ ssize_t part_stat_show(struct device *dev,
struct disk_stats stat;
unsigned int inflight;
- inflight = part_in_flight(bdev);
+ inflight = bdev_count_inflight(bdev);
if (inflight) {
part_stat_lock();
update_io_ticks(bdev, jiffies, true);
@@ -1101,7 +1111,7 @@ ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
struct request_queue *q = bdev_get_queue(bdev);
unsigned int inflight[2] = {0};
- part_in_flight_rw(bdev, inflight, queue_is_mq(q));
+ bdev_count_inflight_rw(bdev, inflight, queue_is_mq(q));
return sysfs_emit(buf, "%8u %8u\n", inflight[READ], inflight[WRITE]);
}
@@ -1356,7 +1366,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
if (bdev_is_partition(hd) && !bdev_nr_sectors(hd))
continue;
- inflight = part_in_flight(hd);
+ inflight = bdev_count_inflight(hd);
if (inflight) {
part_stat_lock();
update_io_ticks(hd, jiffies, true);