[Devel] [PATCH RHEL10 COMMIT] block/bio: add bio_issue_elapsed_ns()

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jul 31 15:11:53 MSK 2026


The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.1.vz10
------>
commit 469205863651d1adfc736b2420c90615c7af1212
Author: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
Date:   Mon Jul 27 19:32:45 2026 +0300

    block/bio: add bio_issue_elapsed_ns()
    
    If blkcgroup is present, each bio is stamped at the issue time.
    Expose this via bio_issue_elapsed_ns() so we can accurately
    calculate total time spent in the block layer.
    
    https://virtuozzo.atlassian.net/browse/VSTOR-103846
    Feature: dm-stats: latency and histogram enhancements
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
    Reviewed-by: Vasileios Almpanis <vasileios.almpanis at virtuozzo.com>
    Reviewed-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 block/bio.c         | 23 +++++++++++++++++++++++
 include/linux/bio.h |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/block/bio.c b/block/bio.c
index 3c0a558c90f52..c26babfc5e1ce 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1827,6 +1827,29 @@ int bioset_init(struct bio_set *bs,
 }
 EXPORT_SYMBOL(bioset_init);
 
+/*
+ * bio_issue_elapsed_ns - calculate elapsed time since issue
+ * @bio:	bio
+ *
+ * Return the elapsed nanoseconds since bio issue until now,
+ * handling the 51-bit wraparound.
+ */
+u64 bio_issue_elapsed_ns(struct bio *bio)
+{
+#ifdef CONFIG_BLK_CGROUP
+	u64 now, elapsed;
+
+	/* Mask both operands to 51 bits before the modular subtraction. */
+	now = __bio_issue_time(blk_time_get_ns());
+	elapsed = now - bio_issue_time(&bio->bi_issue);
+
+	return elapsed & BIO_ISSUE_TIME_MASK;
+#else
+	return 0;
+#endif
+}
+EXPORT_SYMBOL_GPL(bio_issue_elapsed_ns);
+
 static int __init init_bio(void)
 {
 	int i;
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 46ffac5caab78..00c116207a25a 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -714,4 +714,6 @@ struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new);
 struct bio *blk_alloc_discard_bio(struct block_device *bdev,
 		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
 
+u64 bio_issue_elapsed_ns(struct bio *bio);
+
 #endif /* __LINUX_BIO_H */


More information about the Devel mailing list