blk-mq: introduce tag starvation observability
Subsystems (2)
v3 cover blk-mq: introduce tag starvation observability
Hi Jens, Steve, Masami,
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices are starved of available tags. Currently, diagnosing this specific queue contention requires deploying dynamic kprobes or inferring sleep states, which lacks a simple, out-of-the-box diagnostic path.
This short series introduces dedicated, low-overhead observability for tag exhaustion events in the block layer:
- Patch 1 introduces the "block_rq_tag_wait" tracepoint in the tag allocation slow-path to capture precise, event-based starvation.
- Patch 2 complements this by exposing "wait_on_hw_tag" and "wait_on_sched_tag" atomic counters via debugfs for quick, point-in-time cumulative polling.
Together, these provide storage engineers with zero-configuration mechanisms to definitively identify shared-tag bottlenecks.
Please let me know your thoughts.
Changes since v2 [1]:
- Added "Reviewed-by:" and "Tested-by:" tags for patch 1
- Evaluate is_sched_tag directly within TP_fast_assign (Steven Rostedt)
- Introduced atomic counters via debugfs
Changes since v1 [2]:
- Improved the description of the trace point (Damien Le Moal)
- Removed the redundant "active requests" (Laurence Oberman)
- Introduced pool-specific starvation tracking
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
Aaron Tomlin (2):
blk-mq: add tracepoint block_rq_tag_wait
blk-mq: expose tag starvation counts via debugfs
block/blk-mq-debugfs.c | 56 ++++++++++++++++++++++++++++++++++++ block/blk-mq-debugfs.h | 7 +++++ block/blk-mq-tag.c | 8 ++++++ include/linux/blk-mq.h | 10 +++++++ include/trace/events/block.h | 43 +++++++++++++++++++++++++++ 5 files changed, 124 insertions(+)
Signature · 1 line
2.51.0
PATCH v3 1/2 blk-mq: add tracepoint block_rq_tag_wait
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices (SSDs) are starved of hardware tags when sharing the same blk_mq_tag_set.
Currently, diagnosing this specific hardware queue contention is difficult. When a CPU thread exhausts the tag pool, blk_mq_get_tag() forces the current thread to block uninterruptible via io_schedule(). While this can be inferred via sched:sched_switch or dynamically traced by attaching a kprobe to blk_mq_mark_tag_wait(), there is no dedicated, out-of-the-box observability for this event.
This patch introduces the block_rq_tag_wait trace point in the tag allocation slow-path. It triggers immediately before the thread yields the CPU, exposing the exact hardware context (hctx) that is starved, the specific pool experiencing starvation (hardware or software scheduler), and the total pool depth.
This provides storage engineers and performance monitoring agents with a zero-configuration, low-overhead mechanism to definitively identify shared-tag bottlenecks and tune I/O schedulers or cgroup throttling accordingly.
--- block/blk-mq-tag.c | 4 ++++ include/trace/events/block.h | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
block/blk-mq-tag.c +4 -0
@@ -13,6 +13,7 @@#include <linux/kmemleak.h> #include <linux/delay.h> +#include <trace/events/block.h> #include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h"
@@ -187,6 +188,9 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)if (tag !=BLK_MQ_NO_TAG )break ; +trace_block_rq_tag_wait (data->q, data->hctx, + data->rq_flags &RQF_SCHED_TAGS ); + bt_prev = bt;io_schedule ();
include/trace/events/block.h +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v3 2/2 blk-mq: expose tag starvation counts via debugfs
In reply to Aaron TomlinIn high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices are starved of available tags.
This patch introduces two new debugfs attributes for each block hardware queue:
- /sys/kernel/debug/block/[device]/hctxN/wait_on_hw_tag
- /sys/kernel/debug/block/[device]/hctxN/wait_on_sched_tag
These files expose atomic counters that increment each time a submitting context is forced into an uninterruptible sleep via io_schedule() due to the complete exhaustion of physical driver tags or software scheduler tags, respectively.
To guarantee zero performance overhead for production kernels compiled without debugfs, the underlying atomic_t variables and their associated increment routines are strictly guarded behind CONFIG_BLK_DEBUG_FS. When this configuration is disabled, the tracking logic compiles down to a safe no-op.
--- block/blk-mq-debugfs.c | 56 ++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-debugfs.h | 7 ++++++ block/blk-mq-tag.c | 4 +++ include/linux/blk-mq.h | 10 ++++++++ 4 files changed, 77 insertions(+)
block/blk-mq-debugfs.c +56 -0
@@ -483,6 +483,42 @@ static int hctx_dispatch_busy_show(void *data, struct seq_file *m)return 0 ; } +/** +* hctx_wait_on_hw_tag_show - display hardware tag starvation count +* @data: generic pointer to the associated hardware context (hctx) +* @m: seq_file pointer for debugfs output formatting +* +* Prints the cumulative number of times a submitting context was forced +* to block due to the exhaustion of physical hardware driver tags. +* +* Return: 0 on success. +*/ +static int hctx_wait_on_hw_tag_show (void *data,struct seq_file *m) +{ +struct blk_mq_hw_ctx *hctx = data; + +seq_printf (m,"%d\n" ,atomic_read (&hctx->wait_on_hw_tag)); +return 0 ; +} + +/** +* hctx_wait_on_sched_tag_show - display scheduler tag starvation count +* @data: generic pointer to the associated hardware context (hctx) +* @m: seq_file pointer for debugfs output formatting +* +* Prints the cumulative number of times a submitting context was forced +* to block due to the exhaustion of software scheduler tags. +* +* Return: 0 on success. +*/ +static int hctx_wait_on_sched_tag_show (void *data,struct seq_file *m) +{ +struct blk_mq_hw_ctx *hctx = data; + +seq_printf (m,"%d\n" ,atomic_read (&hctx->wait_on_sched_tag)); +return 0 ; +} +#define CTX_RQ_SEQ_OPS (name, type) \ static void *ctx_##name##_rq_list_start(struct seq_file *m, loff_t *pos) \ __acquires(&ctx->lock) \
@@ -598,6 +634,8 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { {"active", 0400, hctx_active_show}, {"dispatch_busy", 0400, hctx_dispatch_busy_show}, {"type", 0400, hctx_type_show}, + {"wait_on_hw_tag", 0400, hctx_wait_on_hw_tag_show}, + {"wait_on_sched_tag", 0400, hctx_wait_on_sched_tag_show}, {}, };
@@ -814,3 +852,21 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)debugfs_remove_recursive (hctx->sched_debugfs_dir); hctx->sched_debugfs_dir =NULL ; } + +/** +* blk_mq_debugfs_inc_wait_tags - increment the tag starvation counters +* @hctx: hardware context associated with the tag allocation +* @is_sched: boolean indicating whether the starved pool is the software scheduler +* +* Evaluates the exhausted tag pool and increments the appropriate debugfs +* starvation counter. This is invoked immediately before the submitting +* context is forced into an uninterruptible sleep via io_schedule(). +*/ +void blk_mq_debugfs_inc_wait_tags (struct blk_mq_hw_ctx *hctx, +bool is_sched) +{ +if (is_sched) +atomic_inc (&hctx->wait_on_sched_tag); +else +atomic_inc (&hctx->wait_on_hw_tag); +}
block/blk-mq-debugfs.h +7 -0
@@ -34,6 +34,8 @@ void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,void blk_mq_debugfs_unregister_sched_hctx (struct blk_mq_hw_ctx *hctx);void blk_mq_debugfs_register_rq_qos (struct request_queue *q); +void blk_mq_debugfs_inc_wait_tags (struct blk_mq_hw_ctx *hctx, +bool is_sched);#else static inline void blk_mq_debugfs_register (struct request_queue *q) {
@@ -77,6 +79,11 @@ static inline void blk_mq_debugfs_register_rq_qos(struct request_queue *q) { } +static inline void blk_mq_debugfs_inc_wait_tags (struct blk_mq_hw_ctx *hctx, +bool is_sched) +{ +} +#endif #if defined(CONFIG_BLK_DEV_ZONED ) && defined(CONFIG_BLK_DEBUG_FS )
block/blk-mq-tag.c +4 -0
@@ -17,6 +17,7 @@#include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h" +#include "blk-mq-debugfs.h" /* * Recalculate wakeup batch when tag is shared by hctx.
@@ -191,6 +192,9 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)trace_block_rq_tag_wait (data->q, data->hctx, data->rq_flags &RQF_SCHED_TAGS ); +blk_mq_debugfs_inc_wait_tags (data->hctx, + data->rq_flags &RQF_SCHED_TAGS ); + bt_prev = bt;io_schedule ();
include/linux/blk-mq.h +10 -0
@@ -453,6 +453,16 @@ struct blk_mq_hw_ctx {struct dentry *debugfs_dir;/** @sched_debugfs_dir: debugfs directory for the scheduler. */ struct dentry *sched_debugfs_dir; +/** +* @wait_on_hw_tag: Cumulative counter incremented each time a submitting +* context is forced to block due to physical hardware driver tag exhaustion. +*/ +atomic_t wait_on_hw_tag; +/** +* @wait_on_sched_tag: Cumulative counter incremented each time a submitting +* context is forced to block due to software scheduler tag exhaustion. +*/ +atomic_t wait_on_sched_tag;#endif /**
Signature · 1 line
2.51.0
Re: [PATCH v3 2/2] blk-mq: expose tag starvation counts via debugfs
Quoted 206 lines · Aaron Tomlin
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (
BLK_MQ_F_TAG_HCTX_SHARED), severe
latency spikes can occur when fast devices are starved of available tags.This patch introduces two new debugfs attributes for each block hardware queue:
- /sys/kernel/debug/block/[device]/hctxN/wait_on_hw_tag
- /sys/kernel/debug/block/[device]/hctxN/wait_on_sched_tagThese files expose atomic counters that increment each time a submitting
context is forced into an uninterruptible sleep viaio_schedule()due to
the complete exhaustion of physical driver tags or software scheduler tags, respectively.To guarantee zero performance overhead for production kernels compiled
without debugfs, the underlyingatomic_tvariables and their associated
increment routines are strictly guarded behindCONFIG_BLK_DEBUG_FS. When this configuration is disabled, the tracking logic compiles down to a safe no-op.Signed-off-by Aaron Tomlin <[email protected]>---
block/blk-mq-debugfs.c | 56
++++++++++++++++++++++++++++++++++++++++++
block/blk-mq-debugfs.h | 7 ++++++
block/blk-mq-tag.c | 4 +++
include/linux/blk-mq.h | 10 ++++++++4 files changed, 77 insertions(+)block/blk-mq-debugfs.c +0
-0@@ -483,6 +483,42 @@ static int hctx_dispatch_busy_show(void *data, struct seq_file *m) return 0; }
+/**
+ *hctx_wait_on_hw_tag_show- display hardware tag starvation count
+ * @data: generic pointer to the associated hardware context (hctx)
+ * @m:seq_filepointer for debugfs output formatting
+ *
+ * Prints the cumulative number of times a submitting context was forced
+ * to block due to the exhaustion of physical hardware driver tags.
+ *
+ * Return: 0 on success.
+ */block/blk-mq-debugfs.c +10
-0+static int hctx_wait_on_hw_tag_show (void *data,struct seq_file *m) +{ +struct blk_mq_hw_ctx *hctx = data; + +seq_printf (m,"%d\n" ,atomic_read (&hctx->wait_on_hw_tag)); +return 0 ; +} + +/** +* hctx_wait_on_sched_tag_show - display scheduler tag starvation count
+ * @data: generic pointer to the associated hardware context (hctx)
+ * @m:seq_filepointer for debugfs output formatting
+ *
+ * Prints the cumulative number of times a submitting context was forced
+ * to block due to the exhaustion of software scheduler tags.
+ *
+ * Return: 0 on success.
+ */
+static inthctx_wait_on_sched_tag_show(void *data, struct seq_file *m)block/blk-mq-debugfs.c +4
-0+{ +struct blk_mq_hw_ctx *hctx = data; + + seq_printf(m, "%d\n", atomic_read(&hctx-Quoted 1 line
wait_on_sched_tag));block/blk-mq-debugfs.c +3
-0+return 0 ; +} +#define CTX_RQ_SEQ_OPS(name,
type) \
static void *ctx_##name##_rq_list_start(structseq_file*m,loff_t*pos) \
__acquires(&ctx-Quoted 1 line
lock) \
block/blk-mq-debugfs.c +2
-0@@ -598,6 +634,8 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { {"active", 0400, hctx_active_show}, {"dispatch_busy", 0400, hctx_dispatch_busy_show}, {"type", 0400, hctx_type_show}, + {"wait_on_hw_tag" ,0400 , hctx_wait_on_hw_tag_show}, + {"wait_on_sched_tag" ,0400 , hctx_wait_on_sched_tag_show}, {}, };block/blk-mq-debugfs.c +0
-0@@ -814,3 +852,21 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx) debugfs_remove_recursive(hctx->sched_debugfs_dir); hctx->sched_debugfs_dir = NULL;}
block/blk-mq-debugfs.c +3
-0+ +/** +* blk_mq_debugfs_inc_wait_tags - increment the tag starvation counters
+ * @hctx: hardware context associated with the tag allocation
+ * @is_sched: boolean indicating whether the starved pool is the software scheduler
+ *
+ * Evaluates the exhausted tag pool and increments the appropriate debugfs
+ * starvation counter. This is invoked immediately before the submitting
+ * context is forced into an uninterruptible sleep viaio_schedule().
+ */block/blk-mq-debugfs.c +8
-0+void blk_mq_debugfs_inc_wait_tags (struct blk_mq_hw_ctx *hctx, + bool is_sched) +{ +if (is_sched) +atomic_inc (&hctx->wait_on_sched_tag); +else +atomic_inc (&hctx->wait_on_hw_tag); +}block/blk-mq-debugfs.h +0
-0@@ -34,6 +34,8 @@ void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,void
blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);
voidblk_mq_debugfs_register_rq_qos(struct request_queue *q);block/blk-mq-debugfs.h +2
-0+void blk_mq_debugfs_inc_wait_tags (struct blk_mq_hw_ctx *hctx, + bool is_sched);#else
static inline voidblk_mq_debugfs_register(struct request_queue *q){block/blk-mq-debugfs.h +0
-0@@ -77,6 +79,11 @@ static inline void blk_mq_debugfs_register_rq_qos(struct request_queue *q) { }
+static inline void blk_mq_debugfs_inc_wait_tags(structblk_mq_hw_ctx*hctx,block/blk-mq-debugfs.h +4
-0+ bool is_sched) +{ +} +#endif
#ifdefined(CONFIG_BLK_DEV_ZONED)&&defined(CONFIG_BLK_DEBUG_FS)block/blk-mq-tag.c +1
-0@@ -17,6 +17,7 @@ #include "blk.h" #include "blk-mq.h" #include "blk-mq-sched.h" +#include "blk-mq-debugfs.h"
/*
* Recalculate wakeup batch when tag is shared by hctx.block/blk-mq-tag.c +0
-0@@ -191,6 +192,9 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data) trace_block_rq_tag_wait(data->q, data->hctx,
data->rq_flags&RQF_SCHED_TAGS);block/blk-mq-tag.c +2
-0+ blk_mq_debugfs_inc_wait_tags(data->hctx, + data->rq_flags &
RQF_SCHED_TAGS);
+
bt_prev= bt;
io_schedule();include/linux/blk-mq.h +0
-0@@ -453,6 +453,16 @@ struct blk_mq_hw_ctx { struct dentry *debugfs_dir; /** @sched_debugfs_dir: debugfs directory for thescheduler. */
struct dentry*sched_debugfs_dir;include/linux/blk-mq.h +2
-0+/** +* @wait_on_hw_tag: Cumulative counter incremented each time a submitting
include/linux/blk-mq.h +1
-0+* context is forced to block due to physical hardware driver tag exhaustion.
include/linux/blk-mq.h +4
-0+*/ +atomic_t wait_on_hw_tag; +/** +* @wait_on_sched_tag: Cumulative counter incremented each time a submitting
include/linux/blk-mq.h +1
-0+* context is forced to block due to software scheduler tag exhaustion.
include/linux/blk-mq.h +2
-0+*/ +atomic_t wait_on_sched_tag;
Quoted 3 lines
#endif
/**
For [PATCH v3 2/2] blk-mq: expose tag starvation counts via debugfs
Every 10.0s: grep . /sys/kernel/debug/block/nvme0n1/hctx0/wait_on_*
rhel95: Fri Mar 20 11:04:15 2026
/sys/kernel/debug/block/nvme0n1/hctx0/wait_on_hw_tag:103260 <--- cumulative /sys/kernel/debug/block/nvme0n1/hctx0/wait_on_sched_tag:0
The patch to me looks good, but will need others to confirm
Re: [PATCH v3 2/2] blk-mq: expose tag starvation counts via debugfs
In reply to Aaron TomlinQuoted 5 lines · Aaron Tomlin
To guarantee zero performance overhead for production kernels compiled without debugfs, the underlying
atomic_tvariables and their associated increment routines are strictly guarded behindCONFIG_BLK_DEBUG_FS. When this configuration is disabled, the tracking logic compiles down to a safe no-op.
I don't think that's sufficient. Please use per-cpu counters to minimize the overhead for kernels in which debugfs is enabled.
Thanks,
Bart.
Jens Axboe
maintainerRe: [PATCH v3 2/2] blk-mq: expose tag starvation counts via debugfs
Quoted 9 lines · Bart Van Assche
Quoted 5 lines · Aaron Tomlin
To guarantee zero performance overhead for production kernels compiled without debugfs, the underlying
atomic_tvariables and their associated increment routines are strictly guarded behindCONFIG_BLK_DEBUG_FS. When this configuration is disabled, the tracking logic compiles down to a safe no-op.I don't think that's sufficient. Please use per-cpu counters to minimize the overhead for kernels in which debugfs is enabled.
Agree, this is the usual nonsense of thinking you can hide any overhead behind a config option, when in practice production kernels very much DO have CONFIG_DEBUGFS enabled.
Signature · 1 line
Jens Axboe
Re: [PATCH v3 2/2] blk-mq: expose tag starvation counts via debugfs
Quoted 8 lines · Jens Axboe
Quoted 7 lines · Bart Van Assche
Quoted 5 lines · Aaron Tomlin
To guarantee zero performance overhead for production kernels compiled without debugfs, the underlying
atomic_tvariables and their associated increment routines are strictly guarded behindCONFIG_BLK_DEBUG_FS. When this configuration is disabled, the tracking logic compiles down to a safe no-op.
Quoted 6 lines
Quoted 2 lines
I don't think that's sufficient. Please use per-cpu counters to minimize the overhead for kernels in which debugfs is enabled.
Agree, this is the usual nonsense of thinking you can hide any overhead behind a config option, when in practice production kernels very much DO have
CONFIG_DEBUGFSenabled.
Hi Bart, Jens,
Thank you both for the candid feedback.
I concede that relying on CONFIG_BLK_DEBUG_FS to mitigate the performance impact was a short-sighted approach, as you are absolutely right that debugfs is routinely enabled in modern production environments. The use of an atomic_t variable in this case would indeed introduce unacceptable cache line contention under heavy workloads.
I shall address this in the next iteration by transitioning the tracking logic entirely to per-CPU counters. This will ensure the overhead is strictly minimised, irrespective of the build configuration.
Thank you again for your time and guidance on this matter.
Kind regards,
Signature · 1 line
Aaron Tomlin
Quoted 13 lines · Aaron Tomlin
In high-performance storage environments, particularly when utilising RAID controllers with shared tag sets (
BLK_MQ_F_TAG_HCTX_SHARED), severe latency spikes can occur when fast devices are starved of available tags. Currently, diagnosing this specific queue contention requires deploying dynamic kprobes or inferring sleep states, which lacks a simple, out-of-the-box diagnostic path.This short series introduces dedicated, low-overhead observability for tag exhaustion events in the block layer:
- Patch 1 introduces the "
block_rq_tag_wait" tracepoint in the tag allocation slow-path to capture precise, event-based starvation.
Quoted 6 lines
- Patch 2 complements this by exposing "
wait_on_hw_tag" and "wait_on_sched_tag" atomic counters via debugfs for quick, point-in-time cumulative polling.Together, these provide storage engineers with zero-configuration mechanisms to definitively identify shared-tag bottlenecks.
Hi Jens, Steve, Masami,
Just a friendly ping on this patch.
Please let me know if there is any feedback, or if you need me to make any adjustments.
Kind regards,
Signature · 1 line
Aaron Tomlin