From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.114 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796143136; b=wrzbeW6puPySYuXW7Y9i1kH+CAYY+JTYiRkzsmtUvEym5ruD5UdYfiJmYEERavJtf+Bn z1bBmUeDlE24gInpZSp3Wxf9jKZGFpQ/YhZGte9qZx1xbrX1DMT61+I8p2sCtMJ0D6AFs ejhJctQO/B7qIUMhyrCNk/vwe/lsqvpagdAeEsJamL7Hekz2/nzFObwD7m6gLL3Y3HxOR wrlaxeR3QHbBCUagwluNYIcHXTRgZNTwJPWdyMAgCkhPhpSptOeYZmQ6Azr0QkXqeZIGa 2Klsw3uMpMWT0YvKvpnyEHtn2hdd+/0mSmX+Kg71shXqMCjkoVzfSXcXGTikzcCpmsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143136; h=DMARC-Filter:DKIM-Signature:To:Message-Id:X-Lms-Return-Path: Content-Type:From:Subject:Date:Content-Transfer-Encoding:Mime-Version: Cc:X-Original-From; bh=YfeFTZCwZInXvy1yeKCkLNv78/Tj+e6GF/P8fhCvvQ0=; b=0BtM0VV8Qcq11lGgSFsYI0Wc36EKW/dDgBKWVd+T+SvWMY1OjFQi1G2rlElCLTEo5Rap kvgEN46D1ZQiZYohPkDybL0hj8LcyEOLxtniM3QoTGEHJBQTqChoi3Pdq90bOgyP2HxYE ZnE8R7NY0UvpTX+8BqMxxVNOuEzS0CMWUJ8SIUCokSYpQbvc1GwJt8niTK+oqwS6ZWXdW C94aYSzeCU3oFFn5Mhbqortn3lO1SNx2ORBoM0ANMaip5bnkM5ak9OdaDZxVkPtQXzoKv UXhf5UQSz+Jekx6vV1W7bf1V48dWwjgusI0bnaj2xKiwJ/GYzX9QFIoxwzr/UIX1yCA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=J70JQDtr; arc=none smtp.remote-ip=209.127.231.114 Received: from va-2-114.ptr.blmpb.com (va-2-114.ptr.blmpb.com [209.127.231.114]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91531606A320 for ; Tue, 1 Dec 2026 16:38:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 91531606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=J70JQDtr DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796143130; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=YfeFTZCwZInXvy1yeKCkLNv78/Tj+e6GF/P8fhCvvQ0=; b=J70JQDtrMjKT09J1IKNgGnGp1ujD/l+qkOx+kRPIEOjBgOuvL5DoAbSgv67IwI48/JtP/7 wP/y8/DYzfzEM5PDuIx8WVd50sQACyeUOe+gKMUWmIOwfWDm9JaIK2HWWVSlS7txzC14Di U1hyTGtJrN6T1gdEAP8GB7DAPLdxdaIwmRkw8rAy3cT24JMF/+fQWWYNNNQXUjL+xLc+E/ 03xBVXXDkpA9gXnYkq4ylICtQdRzRaMbGXyJFTAD27tENdabcF5Hhee4NNCcclaWMCSm7r D+HVXZPCHixlq1D6jeR4eJ1ipug4wiorA3z4QN+Kru2uT7E5ajXIy4Vtwqxkig== To: Message-Id: <20261202003837.3486664-1-maxing.lan@bytedance.com> X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 From: "Xing Ma" Subject: [PATCH v1] blk-wbt: limit wb_recent_wait() boost under reads and throttling Date: Wed, 02 Dec 2026 00:38:37 +0800 Content-Transfer-Encoding: 7bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Cc: , X-Original-From: Xing Ma 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 --- 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