[PATCH v1] blk-wbt: limit wb_recent_wait() boost under reads and throttling

From: Xing Ma

Date: Tue Dec 01 2026 - 11:38:58 EST


In get_limit(), wb_recent_wait() currently shares the REQ_HIPRIO branch
and unconditionally raises the writeback depth limit to max_depth.
Under sustained buffered writes (where tasks regularly pause in
balance_dirty_pages()), wb_recent_wait() stays true almost continuously,
causing two issues:

1. Competing reads (close_io()) and REQ_BACKGROUND are completely
bypassed. On high-QD NVMe devices (e.g., nr_requests=1023,
max_depth=767, wb_background=192), async writeback jumps 4x straight
to max_depth, saturating the device and eliminating the headroom
between wb_normal and max_depth reserved for REQ_HIPRIO
(REQ_SYNC | REQ_META | REQ_PRIO | REQ_SWAP).

2. Active latency throttling (scale_step > 0) creates a positive
feedback loop: throttling slows writeback, which causes foreground
writers to sleep in balance_dirty_pages(), which sets
wb_recent_wait() and immediately lifts the writeback limit 4x back
to max_depth, defeating WBT's own throttling.

Add rq_depth_throttled() in blk-rq-qos.h (with paired WRITE_ONCE() on
scale_step updates) and a shared wb_recent_wait_boost() predicate used
symmetrically by both get_limit() and wbt_rqw_done():

- Keep REQ_HIPRIO at max_depth.
- When actively throttling (rq_depth_throttled()), disable the
wb_recent_wait() boost on both admission (get_limit()) and write-cache
wakeup (wbt_rqw_done()), breaking the feedback loop and avoiding
spurious wakeups.
- When not actively throttling, promote writeback by one tier on
wb_recent_wait(): wb_background -> wb_normal under competing reads
(preserving REQ_HIPRIO headroom), or wb_normal -> max_depth when no
competing reads are present (!close_io()) so pure-write throughput is
unchanged.

KVM NVMe testing (nr_requests=1023, wbt_lat_usec=2000, 4KB randread at
400 IOPS + 2x 512KB buffered writers):

- 150 MB/s bandwidth-saturated NVMe mixed R/W: read IOPS 96.3 -> 161.4
(+68%), mean latency 82.57ms -> 49.34ms (-40%), P50 55.84ms -> 28.70ms
(-49%), P95 223.35ms -> 141.56ms (-37%), peak inflight 28 -> 15 (-46%),
disk write 143 -> 143 MB/s (0% loss).
- Unthrottled NVMe write-burst then read: read mean 4.48ms -> 3.38ms
(-25%), P95 30.54ms -> 18.48ms (-39%), P99 64.75ms -> 52.69ms (-19%),
disk write 1125 -> 1125 MB/s (0% loss).
- Unthrottled NVMe mixed R/W: read P99 66.85ms -> 54.79ms (-18%),
max 108.63ms -> 88.36ms (-19%), disk write 1144 -> 1151 MB/s (+0.6%).
- Saturated NVMe pure buffered write (no reads): 167 -> 166 MB/s.

Signed-off-by: Xing Ma <maxing.lan@xxxxxxxxxxxxx>
---
block/blk-rq-qos.c | 6 +++---
block/blk-rq-qos.h | 5 +++++
block/blk-wbt.c | 23 +++++++++++++++++++----
3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 85cf74402a09..8ba06e64e112 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -163,7 +163,7 @@ bool rq_depth_scale_up(struct rq_depth *rqd)
if (rqd->scaled_max)
return false;

- rqd->scale_step--;
+ WRITE_ONCE(rqd->scale_step, rqd->scale_step - 1);

rqd->scaled_max = rq_depth_calc_max_depth(rqd);
return true;
@@ -185,9 +185,9 @@ bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle)
return false;

if (rqd->scale_step < 0 && hard_throttle)
- rqd->scale_step = 0;
+ WRITE_ONCE(rqd->scale_step, 0);
else
- rqd->scale_step++;
+ WRITE_ONCE(rqd->scale_step, rqd->scale_step + 1);

rqd->scaled_max = false;
rq_depth_calc_max_depth(rqd);
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index a747a504fe42..799760bef1f0 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -100,6 +100,11 @@ bool rq_depth_scale_up(struct rq_depth *rqd);
bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
bool rq_depth_calc_max_depth(struct rq_depth *rqd);

+static inline bool rq_depth_throttled(const struct rq_depth *rqd)
+{
+ return READ_ONCE(rqd->scale_step) > 0;
+}
+
void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
void __rq_qos_done(struct rq_qos *rqos, struct request *rq);
void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 953d400fd013..93f5fe60f4e2 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -172,6 +172,15 @@ static bool wb_recent_wait(struct rq_wb *rwb)
return time_before(jiffies, bdi->last_bdp_sleep + HZ);
}

+/*
+ * Only boost writeback limits for a recent balance_dirty_pages() sleep when
+ * WBT is not actively throttling for read latency violations.
+ */
+static bool wb_recent_wait_boost(struct rq_wb *rwb)
+{
+ return !rq_depth_throttled(&rwb->rq_depth) && wb_recent_wait(rwb);
+}
+
static inline struct rq_wait *get_rq_wait(struct rq_wb *rwb,
enum wbt_flags wb_acct)
{
@@ -210,7 +219,7 @@ static void wbt_rqw_done(struct rq_wb *rwb, struct rq_wait *rqw,
if (wb_acct & WBT_DISCARD)
limit = rwb->wb_background;
else if (blk_queue_write_cache(rwb->rqos.disk->queue) &&
- !wb_recent_wait(rwb))
+ !wb_recent_wait_boost(rwb))
limit = 0;
else
limit = rwb->wb_normal;
@@ -484,7 +493,7 @@ static void wbt_update_limits(struct rq_wb *rwb)
{
struct rq_depth *rqd = &rwb->rq_depth;

- rqd->scale_step = 0;
+ WRITE_ONCE(rqd->scale_step, 0);
rqd->scaled_max = false;

rq_depth_calc_max_depth(rqd);
@@ -545,12 +554,18 @@ static inline unsigned int get_limit(struct rq_wb *rwb, blk_opf_t opf)
* At this point we know it's a buffered write. If this is
* swap trying to free memory, or REQ_SYNC is set, then
* it's WB_SYNC_ALL writeback, and we'll use the max limit for
- * that. If the write is marked as a background write, then use
+ * that. If a task recently waited in balance_dirty_pages() and
+ * we are not actively throttling for read latency violations,
+ * boost the cleaning limit to wb_normal under competing reads
+ * (preserving headroom for REQ_HIPRIO) or max_depth otherwise.
+ * If the write is marked as a background write, then use
* the idle limit, or go to normal if we haven't had competing
* IO for a bit.
*/
- if ((opf & REQ_HIPRIO) || wb_recent_wait(rwb))
+ if (opf & REQ_HIPRIO)
limit = rwb->rq_depth.max_depth;
+ else if (wb_recent_wait_boost(rwb))
+ limit = close_io(rwb) ? rwb->wb_normal : rwb->rq_depth.max_depth;
else if ((opf & REQ_BACKGROUND) || close_io(rwb)) {
/*
* If less than 100ms since we completed unrelated IO,

base-commit: 38f76ad44f86d3d70262ebb2777eac459808638b
--
2.39.5