From patchwork Wed Oct 23 10:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Zhao X-Patchwork-Id: 13895550 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 C291DE7716D for ; Thu, 5 Dec 2024 15:22:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 579926B0110; Thu, 5 Dec 2024 10:19:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 110626B00C2; Thu, 5 Dec 2024 10:19:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF9B26B00AA; Thu, 5 Dec 2024 10:19:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D85856B0083 for ; Wed, 23 Oct 2024 06:00:42 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 94FCCC0852 for ; Wed, 23 Oct 2024 10:00:23 +0000 (UTC) X-FDA: 82704422220.30.AF1611B Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf12.hostedemail.com (Postfix) with ESMTP id 8152440019 for ; Wed, 23 Oct 2024 10:00:32 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="D/Oo/RdL"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.210.196 as permitted sender) smtp.mailfrom=jimzhao.ai@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729677516; a=rsa-sha256; cv=none; b=MZpEso5+g8Qt3nyzjBtyZKYDMhWSIgk17Zfx35l2PdzQkFEMY8LWPzcxEogQlaq4gsyydK WRRL5THO5Cv8gzk1ki44hj4uTrABtG8ApN99oiRzoeJ8tssUYpsKfOIbhmAfucUpoAHSIj smi7EiIr014XoY3Xss6Kq8Tbhqt3z7w= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="D/Oo/RdL"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.210.196 as permitted sender) smtp.mailfrom=jimzhao.ai@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729677516; 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:references:dkim-signature; bh=KSQE6SQbrKXZnPv2r6mQCXvpZn+sFkfLG+STLAgtJ1s=; b=Rwd0f1CPSQbMF9pKQVTqUWzpK/y9tGysCj+eXPTKMdKnOEVa3oTXuM30R1vyBfu/vf2tII fN0FET6sT4ymf18ofctGOgwF8Ky27ZVgeG2yVlGmylFNq42pB1UCCvCbUv1qGQvawIkarw +tUiAQaaSe6ROAXlywgP08JDrB2YrQo= Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-71e625b00bcso4843830b3a.3 for ; Wed, 23 Oct 2024 03:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729677639; x=1730282439; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KSQE6SQbrKXZnPv2r6mQCXvpZn+sFkfLG+STLAgtJ1s=; b=D/Oo/RdLKk+9OygtsEv/ypY+4EkXvlXM+TxtiqOr+4tspxM0WGY2kdk1rqbfh05q2M ua/yDm373/6+1bTez/+RZqcJb27FW+9CZ/WSLDjoG59v+1TGw8W7dpdq63gOTxS0ZsNY fAeQZEgngV1J5dpw+3V8faujNOIGI8/MINp2LmbOSOeW7xRx5xguMySaK475oK6NMFyK rFC6vkcfd4ea9l5W+mkGk0yuUFnIYVOiMnf74QO/FaiwxS3b3xOHdXEgz3FrTaEdSI0C CQADZDJtp0hzy111cdRdRRhzJJ8yE+nChSpoGMzTTxs4zGsWsj9NkC0zQUTLxEMXYqmG BwRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729677639; x=1730282439; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KSQE6SQbrKXZnPv2r6mQCXvpZn+sFkfLG+STLAgtJ1s=; b=O56uStfpsgLfmEpTXLKrrQINQlJE/runmo6NQnaF1jPohjQ2Ip5azwu7cB8KrC+MKm PF68qiVlgoBWf242trRE0JhfoQkUUXV59ole8z5pPPDtBrvLPvOH4K0UqmrY/VKm6Q0d mE6hfdXBAxiBTVIPHx1DdXfJr/7Tz2T1pB0tUCPVopJlfxkOcF5e0+IGdYvxQRwgyr+V WyNmiacEdvGBXpxV+W8/avl0vmGohxpwf7H2jZmatRMo1LVdmb8L4mefkblxME6fQoAd WwohOyTACT0wa0QOJukc5bcsgF6B/H8iJhTd2IXFJNSzaNzBRWdeSgdpY2fIp8MZeHMl yp2A== X-Forwarded-Encrypted: i=1; AJvYcCVoN2/sFZPZlBdNCBJy8LcJN2DFu/mNh3ReL3QGpigq0VcBwuYHAwoMO5pnslbEapKVqNTW6+Nelw==@kvack.org X-Gm-Message-State: AOJu0YyZ6sw2C3Kb/gk3te0YPl85KLBOAP0pP0WrVUuanZyXW2sLX+Ti LCNsxggIgPMXN1+jOuPlNny7y9RW/NgPThFLIW6Y3Mv5zVN40/a/ X-Google-Smtp-Source: AGHT+IFPcgWD0iVBg1dYapMOvCPbQ1/TT72U4Wjg4YR+NdcpBagP3VTSghprJ92B59k4x8IJ9+x8gA== X-Received: by 2002:a05:6a00:1390:b0:71e:6f4d:1fa4 with SMTP id d2e1a72fcca58-72030a4b659mr3027019b3a.10.1729677638895; Wed, 23 Oct 2024 03:00:38 -0700 (PDT) Received: from localhost.localdomain ([43.154.34.99]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d74cbsm6033316b3a.138.2024.10.23.03.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 03:00:38 -0700 (PDT) From: Jim Zhao To: willy@infradead.org, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jim Zhao Subject: [PATCH] mm/page-writeback: Raise wb_thresh to prevent write blocking with strictlimit Date: Wed, 23 Oct 2024 18:00:32 +0800 Message-Id: <20241023100032.62952-1-jimzhao.ai@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8152440019 X-Stat-Signature: 1kzs15uuoqyi9nbr8jo8brkwxucc4bxw X-Rspam-User: X-HE-Tag: 1729677632-796033 X-HE-Meta: U2FsdGVkX1+FuQElTXtvQ4oXzKGSrt9T/l3xN73Vwl8l8biF5Yi9GMDoHJJ+Hui5M5fckV6gtacrwwCv+Rqa0qsdk2uf6k4cM7/WasH2kvDGDCE7IMWUoI5yMZspZyl5ZSXkGjv3EIPhZfTVaIff0vtw6sjwTtuAr9oEsExY8Hb+sNcOVJxsJeH54fNT1DCsgVUB1QgH7IkPxE9I+BvoKfFwpjK8/Y/2VK/Fu3m5GUyvSVYv0Ff1+9HYuNPuRfjufK2SJEDpsKBDr394IA5eHnA2fOfJCpfo45QYCRngxiTW+lF0JcPPmBllNbCufsWRmtETDZURhjdyEKWaIZVhefo95pn5vIoTVxmz8cZyOxSlXydQBzLrbOjO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/lcyLAtpkd2BQonnfaRvgipmVxgLwDVK/YCdQng6vF/Wbi8w/nV9PtUDgrdS4UrhmHGWGfPQmlr3oXNPRCwBGypR7b/8ALAYoy+9nJgf3qxsaEw3+vEUNgfPCRXb5axG5jxw7VfLnritu2aNUFdAgq8RQO09KQjlk0TC2pYVaYNImDvI3/fF+OekRZ5xxg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 --- mm/page-writeback.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 72a5d8836425..f21d856c408b 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,28 @@ 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); + wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); + if (wb_thresh > wb_max_thresh) + wb_thresh = wb_max_thresh; + + /* + * With strictlimit flag, the wb_thresh is treated as + * a hard limit in balance_dirty_pages() and wb_position_ratio(). + * It's possible that wb_thresh is close to zero, not because + * the device is slow, but because it has been inactive. + * To prevent occasional writes from being blocked, we raise wb_thresh. + */ + if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { + unsigned long limit = hard_dirty_limit(dom, dtc->thresh); + u64 wb_scale_thresh = 0; + + if (limit > dtc->dirty) + wb_scale_thresh = (limit - dtc->dirty) / 100; + wb_thresh = max(wb_thresh, min(wb_scale_thresh, wb_max_thresh / 4)); + } return wb_thresh; }