From patchwork Tue Nov 19 11:44:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Zhao X-Patchwork-Id: 13895580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77D8AE77172 for ; Thu, 5 Dec 2024 15:31:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2BC06B00C8; Thu, 5 Dec 2024 10:19:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9051E6B00B5; Thu, 5 Dec 2024 10:19:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04D606B00B5; Thu, 5 Dec 2024 10:19:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 497F16B009F for ; Tue, 19 Nov 2024 06:46:15 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6619C403E5 for ; Tue, 19 Nov 2024 11:46:14 +0000 (UTC) X-FDA: 82802664840.12.F9AC7F8 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf23.hostedemail.com (Postfix) with ESMTP id 925DA140003 for ; Tue, 19 Nov 2024 11:45:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OoOAcaT5; spf=pass (imf23.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.214.196 as permitted sender) smtp.mailfrom=jimzhao.ai@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732016623; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H4STO0iPgmcM5FLfwGndSr+i7SPybq2xxxE85AAR0y4=; b=GV6Xxw+TPy0cDTCfYfyghDHvNc8UYY+xiFqbgYhsiNjQPzcBhcrtbvhLzEx9kKjvRJgwCP ffKOvEjYthPTbRgPEYWMySb56r+ddcLfQfZbYnsERqBLjPY0aYvmoAY4UlY8ES3Gx2LhR+ +ljuzIMOvlercsyVUPAJ53CbjrFuHSw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732016623; a=rsa-sha256; cv=none; b=moakbDJpFXJ3xj8UwvpBXO7WbugteCaTyZAw39c9Gq3ztXbbBA/v+2pgAVtVyXTUZFcWzG LJ8bAS7OvPRPo4sKzVp9fBDt2L14FBkuJUStfrf2Kkf1aYfmHoZ8B++98aLdb7E2QA1UIB I3qP06SgZT3qgE6HOPNFmhA4UQRzspQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OoOAcaT5; spf=pass (imf23.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.214.196 as permitted sender) smtp.mailfrom=jimzhao.ai@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-211fb27cc6bso26378415ad.0 for ; Tue, 19 Nov 2024 03:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732016771; x=1732621571; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H4STO0iPgmcM5FLfwGndSr+i7SPybq2xxxE85AAR0y4=; b=OoOAcaT5Zeet7lqG7vvsFkgH149AjdPMWk4Rm/SwJa0AsDa9WkVJ1+3Yl+PJnKajnq wGtjFHq2O5WKhN0mIcmWyihEp+UEfdqW7JrXaHIPPTGGsRAWflFegQHCWlG3Al4u8D+o bz/rZ9ipZ3m6Y2HXhba9OsyP5sxJsw4pePmRX0IbHfU8iyeXKhzyKTj3l1JNCoAAqszb HoQf9LxqqO09eR3p1LAnyn12DgmWrsYULoeIWgBE9VhDZ11zzRjAQDgNSwfL5PMbgUPq gp+nTAczJh5AT0hqroooZuI+siCkTcBu8Um3uhwe1w+F1pZMltp9trsSd8VHJVJCUCoZ mlhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732016771; x=1732621571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H4STO0iPgmcM5FLfwGndSr+i7SPybq2xxxE85AAR0y4=; b=SDqV1hW+SkFLOp3BAT2A4DMNbBkrAoi2WeovkF083T3ubI/F/KCCOwrIEd2jtaPfMa e7sS+BUPYcHez6K0At2vVeCEpxC/SKovYLDjmmkidrjplYfdGKA3syifv50SAYZcEcuq gpEtOC+FbJGHAb69l70ShCYlqATjxeXmjzP/EXce4BMqTN2fLe+kTkjCUsHWtU9ThSyX e1tYXZMU7qzq/HVtr7NYFJ70xQi0s/xSppsL1HhrIF51xIOxApVNiyeTGWFqRcZvF+e/ YkWs9/WPs0mOMczttrwYA8HsDMnaVOL7p0oeTnJOaFcC1VxpbLfkSO+H5RvpDnl84VIh EYFw== X-Forwarded-Encrypted: i=1; AJvYcCV5JpNWAAR7jXe5UqDqD1ohNyGHMHNWhcNCWuLQmiHzFalR7z+uh5tD57gvtNKfg0DIEVQ6E40B2w==@kvack.org X-Gm-Message-State: AOJu0YxZopUxTQ6KZS1NNY4m0bCM208lLSjGGPIGkYq8RYe22z0eDlyz NDcmIKcV4Y5RecDwA+kE6/LKZWhxsQUvg1qhiiOLAaBNszwbCxv8 X-Google-Smtp-Source: AGHT+IF0AWadxz0cWwHYidBQa9AYa+e5jib+lfeOkhLDfGyXzY8wZsXdzJNfC5G6279qRUp9jyrQKg== X-Received: by 2002:a17:902:e748:b0:211:ff13:8652 with SMTP id d9443c01a7336-211ff138fd5mr153530625ad.28.1732016771107; Tue, 19 Nov 2024 03:46:11 -0800 (PST) Received: from localhost.localdomain ([43.154.34.99]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2124ce8040asm13547225ad.134.2024.11.19.03.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 03:46:10 -0800 (PST) From: Jim Zhao To: jimzhao.ai@gmail.com Cc: jack@suse.cz, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org Subject: [PATCH v2] mm/page-writeback: raise wb_thresh to prevent write blocking with strictlimit Date: Tue, 19 Nov 2024 19:44:42 +0800 Message-Id: <20241119114444.3925495-1-jimzhao.ai@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241113100735.4jafa56p4td66z7a@quack3> References: <20241113100735.4jafa56p4td66z7a@quack3> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 925DA140003 X-Stat-Signature: zqxxmhqdqeykgnk6de3tc5eoirjjuirb X-HE-Tag: 1732016739-49254 X-HE-Meta: U2FsdGVkX1+YHRKF1MqJr245i0UhMa8HMH928iI3Yht6wU6HoVkq4SRLF+K4wIlHcVRh0f/xC+r79xK2TpN0t4YFgiAqyqksxqGVsbWZUzanR7pBOZ40Y44pUGUSt3yCjNnd+8agvKJIy3E+2iCpmQaeoLdQZEUkweXPmr2BxQKBtOePIvLX8U8EbyFh5ecJMFHHjlqzaFY7k2pJVMX2J4SDrnox2lkEBYH4B90mq5pa5ISGPKxRNZOAFlc7C5CBVQW2jL67FTqkNM1ve3Zj726isXCu5lpWu7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zCRYYwW3fkcCrWXemyMzR6wpxCwKOkF2udUYXunXVFM17LFxDDRODBJw4fOCOqqF/F9uMJG0P8H2ff3oQPdOA1dYf0uxTZ8tR7SCmmpMYE5gPzC1L3qpDUg/w5w09f+cao7rbDaSNiizeXpvx1rVj7zinPKgKQ3eE53Ljp/6PMvh6fsJA6YcodAXwvPdFR9f+u/L3SWC3Fxq7k2M4X2h1XxSJcWcocDxLKxpvuUyuRXzX4EZ8SITDJzS8jZ1EUZTml8A30cVqnj6if2J016cnI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With the strictlimit flag, wb_thresh acts as a hard limit in balance_dirty_pages() and wb_position_ratio(). When device write operations are inactive, wb_thresh can drop to 0, causing writes to be blocked. The issue occasionally occurs in fuse fs, particularly with network backends, the write thread is blocked frequently during a period. To address it, this patch raises the minimum wb_thresh to a controllable level, similar to the non-strictlimit case. Signed-off-by: Jim Zhao --- Changes in v2: 1. Consolidate all wb_thresh bumping logic in __wb_calc_thresh for consistency; 2. Replace the limit variable with thresh for calculating the bump value, as __wb_calc_thresh is also used to calculate the background threshold; 3. Add domain_dirty_avail in wb_calc_thresh to get dtc->dirty. --- mm/page-writeback.c | 48 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index e5a9eb795f99..8b13bcb42de3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -917,7 +917,9 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, unsigned long thresh) { struct wb_domain *dom = dtc_dom(dtc); + struct bdi_writeback *wb = dtc->wb; u64 wb_thresh; + u64 wb_max_thresh; unsigned long numerator, denominator; unsigned long wb_min_ratio, wb_max_ratio; @@ -931,11 +933,27 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, wb_thresh *= numerator; wb_thresh = div64_ul(wb_thresh, denominator); - wb_min_max_ratio(dtc->wb, &wb_min_ratio, &wb_max_ratio); + wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio); wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE); - if (wb_thresh > (thresh * wb_max_ratio) / (100 * BDI_RATIO_SCALE)) - wb_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); + + /* + * It's very possible that wb_thresh is close to 0 not because the + * device is slow, but that it has remained inactive for long time. + * Honour such devices a reasonable good (hopefully IO efficient) + * threshold, so that the occasional writes won't be blocked and active + * writes can rampup the threshold quickly. + */ + if (thresh > dtc->dirty) { + if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) + wb_thresh = max(wb_thresh, (thresh - dtc->dirty) / 100); + else + wb_thresh = max(wb_thresh, (thresh - dtc->dirty) / 8); + } + + wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); + if (wb_thresh > wb_max_thresh) + wb_thresh = wb_max_thresh; return wb_thresh; } @@ -944,6 +962,7 @@ unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh) { struct dirty_throttle_control gdtc = { GDTC_INIT(wb) }; + domain_dirty_avail(&gdtc, true); return __wb_calc_thresh(&gdtc, thresh); } @@ -1120,12 +1139,6 @@ static void wb_position_ratio(struct dirty_throttle_control *dtc) if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { long long wb_pos_ratio; - if (dtc->wb_dirty < 8) { - dtc->pos_ratio = min_t(long long, pos_ratio * 2, - 2 << RATELIMIT_CALC_SHIFT); - return; - } - if (dtc->wb_dirty >= wb_thresh) return; @@ -1196,14 +1209,6 @@ static void wb_position_ratio(struct dirty_throttle_control *dtc) */ if (unlikely(wb_thresh > dtc->thresh)) wb_thresh = dtc->thresh; - /* - * It's very possible that wb_thresh is close to 0 not because the - * device is slow, but that it has remained inactive for long time. - * Honour such devices a reasonable good (hopefully IO efficient) - * threshold, so that the occasional writes won't be blocked and active - * writes can rampup the threshold quickly. - */ - wb_thresh = max(wb_thresh, (limit - dtc->dirty) / 8); /* * scale global setpoint to wb's: * wb_setpoint = setpoint * wb_thresh / thresh @@ -1459,17 +1464,10 @@ static void wb_update_dirty_ratelimit(struct dirty_throttle_control *dtc, * balanced_dirty_ratelimit = task_ratelimit * write_bw / dirty_rate). * Hence, to calculate "step" properly, we have to use wb_dirty as * "dirty" and wb_setpoint as "setpoint". - * - * We rampup dirty_ratelimit forcibly if wb_dirty is low because - * it's possible that wb_thresh is close to zero due to inactivity - * of backing device. */ if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { dirty = dtc->wb_dirty; - if (dtc->wb_dirty < 8) - setpoint = dtc->wb_dirty + 1; - else - setpoint = (dtc->wb_thresh + dtc->wb_bg_thresh) / 2; + setpoint = (dtc->wb_thresh + dtc->wb_bg_thresh) / 2; } if (dirty < setpoint) {