From patchwork Thu Nov 21 10:05:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Zhao X-Patchwork-Id: 13895582 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 B8160E77170 for ; Thu, 5 Dec 2024 15:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BAAA6B0125; Thu, 5 Dec 2024 10:19:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AFA616B0111; 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 EA7986B011C; Thu, 5 Dec 2024 10:19:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4E94C6B007B for ; Thu, 21 Nov 2024 05:05:50 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A589F1408F4 for ; Thu, 21 Nov 2024 10:05:49 +0000 (UTC) X-FDA: 82809668130.13.31375F9 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf15.hostedemail.com (Postfix) with ESMTP id F1E24A0009 for ; Thu, 21 Nov 2024 10:04:53 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ogcw81JY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.214.194 as permitted sender) smtp.mailfrom=jimzhao.ai@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732183480; a=rsa-sha256; cv=none; b=dq7BQK8gciiob5IVLhm69UFpq5pDkyOkF5ItAKtP8AOQXiCqe67rEmnYtHHMCt9ps32Xy/ ZaeQnwWGTr0xet9tOH5VTWNqxYIY1r1BD8Wva7erSRp8JWVRXXYcWxKfnks370o+6umDyH wkPKtC0IepCsMUcx/dgw1ZEq/ZldFGM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ogcw81JY; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of jimzhao.ai@gmail.com designates 209.85.214.194 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=1732183480; 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=CUrUVwBo4XxPjlkazoAS4h6kGrnp7h/1FcU9qVjOigg=; b=zu1aAktlL1KWgH3Zc5MAL2LZer6jvzDQ7a/QEeJ5pL42Q149qCoQPDcZ3Wt7oufWXPSK7V 7hBgS3NekYbixjvpZSn10FiYy1vTl0d2cT9KM+OxO+7qcpMekS2xdxcOvHdo1QTUlPwRww aJHEXnS5IlKwnMHEtdHlHsn269RiVpI= Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-211fb27cc6bso6929925ad.0 for ; Thu, 21 Nov 2024 02:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732183546; x=1732788346; 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=CUrUVwBo4XxPjlkazoAS4h6kGrnp7h/1FcU9qVjOigg=; b=Ogcw81JYhbXcAxJGsEGm1njymODvwccVShEA+UXyDHVgj5u/PpYkYsMftQp3zJi49M atLOmU09JNWG/7Q90NIfgAFUSMzfZ0/ZWKD4FcnSFyMTjSN91oVISbciYp2DXwJVoaQp IhyTIxR0kFJr4RQHFTeqhw9MVmNlP4QrYKOXMG915QzU3B916Jqo3jtAMEmTRj79zagu bAV1jQBA+LtIMXXUpGt852Utp13FdBlNY9vo3w5BJvOonbngpOMTy7rC8yu9JEWi5n6I Va3ZTBMVfqFDfVuGTWcG0lEmMMRFxbMhRCMMdEKWEVZptApGKZ8EXRJ/PipxGdQlDjl+ J+eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732183546; x=1732788346; 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=CUrUVwBo4XxPjlkazoAS4h6kGrnp7h/1FcU9qVjOigg=; b=Pp/QjsxRqbw9/a6a/gH++20xSflRSddWOU9ZZqNvBTf6CO48XXnTd+LDw5+pUH9x2M 65AOZYAqJIJlAtaPT1G5i1+5t2DB8Y1z2SFcfcnOpV/I97ck8f9fGIvRhIZXV1f5DCxF kqyyZ2g0MT3CRrnPlN93esBlXxbFwoeF9BRq4aocKYuqJS7dDXPR6wYJJelf6tIkRxK5 spwlWxe+bKmiuhNZ3vGMdD4VtmTrjyU5TpQkAIKGoEo1t4cg14SEfdBhm9BsjcU2fbXZ nDIP3Pw7cAf6ZgLaNNZyXMaubbkv0iSHIIExpaLlgK7WDOMLmIEh4ee+Nqd8duL/dfCf aZ8g== X-Forwarded-Encrypted: i=1; AJvYcCWOrZ3/0Sdd82LdkeYIL1m+y2I/QxyinTUlKtBqWLigkjzLw8w4DmnVo9BlkEX2+IOccePjTsKd7A==@kvack.org X-Gm-Message-State: AOJu0Yx3B/BOZoOaGHLlb0yrP1QV2pE7m78QYlxtPlscdSgskXx+3jBM zh5pfVZi2ArHWgUCAJQBYADuMcp1s8wRwsaFOXh6Emii6yQghjdD X-Google-Smtp-Source: AGHT+IEmnMMPsdelV/V/PG0DRmKJhSB4OuIOdsqaA4YHEYyzfR7yABVt/N/ruR2LECG+LHaZQ1GuBQ== X-Received: by 2002:a17:902:ec82:b0:212:46c2:6329 with SMTP id d9443c01a7336-2126cb371f5mr61197935ad.47.1732183544931; Thu, 21 Nov 2024 02:05:44 -0800 (PST) Received: from localhost.localdomain ([43.154.34.99]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21288400139sm10024715ad.252.2024.11.21.02.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 02:05:44 -0800 (PST) From: Jim Zhao To: akpm@linux-foundation.org Cc: jack@suse.cz, willy@infradead.org, jimzhao.ai@gmail.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm/page-writeback: Consolidate wb_thresh bumping logic into __wb_calc_thresh Date: Thu, 21 Nov 2024 18:05:39 +0800 Message-Id: <20241121100539.605818-1-jimzhao.ai@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: F1E24A0009 X-Rspamd-Server: rspam11 X-Stat-Signature: ik9p315yow76mn1epe4d7sw89ii8g66q X-HE-Tag: 1732183493-190388 X-HE-Meta: U2FsdGVkX18vB8NCBKnlDyGPaedNhEcapDCQjyVfeIySSz8ft2nMuURdmn5VNFKELN1i1GmXPRd2yb6WV6cYtAmCil9kItB8V1j0Sr9AXnuuVHgeChGFAngGSoJPs9L086GRq8HV58LswtUYMd7Jba4pvgtzHzR++U259BYxr6tx5Tc24uopRtpI9QOHpDG3Xto2mqFmgUKWUSdiu/gxP6R8Q3p2Z7g9MjpJcbczUS55PbccVEIsyXv7M84Vjdn+urwkp8gCMPg/26B72lhllHnOLUSs2R7HMlMyzBBe/hRAbdzw0kdnEzDgD+szTebdjwDvaLEZnzE9+P6DDKF9O0Kdf7duskHFQtazzqQaCh4dTNjuzZzc+kmLMrFZr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0A+FoRAyGM+/I9Zs/FL6MBj3r5OEc3/q/R793n4/OXHK9sCf03vg83PXwr9JK6vP6+6URcrBJDr6+ZQNzxsAiuu3rPOHEINi8J5/TJ/jZifbF+KQ015813QJHrXLJiGV7LW2Ioy9Sl65sSs9fcMZKmkeo3KkMcXzgVyIguVKBzTUPvtkfTGXJ1nAk9wI19P97c24= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Address the feedback from "mm/page-writeback: raise wb_thresh to prevent write blocking with strictlimit"(39ac99852fca98ca44d52716d792dfaf24981f53). The wb_thresh bumping logic is scattered across wb_position_ratio, __wb_calc_thresh, and wb_update_dirty_ratelimit. For consistency, consolidate all wb_thresh bumping logic into __wb_calc_thresh. Reviewed-by: Jan Kara Signed-off-by: Jim Zhao --- mm/page-writeback.c | 53 ++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index d213ead95675..8b13bcb42de3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -936,26 +936,25 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio); wb_thresh += (thresh * wb_min_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. + * 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 (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)); + 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; } @@ -963,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); } @@ -1139,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; @@ -1215,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 @@ -1478,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) {