From patchwork Thu Jun 6 03:35:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13687791 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 3B0A1C25B75 for ; Thu, 6 Jun 2024 03:37:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 918C66B00A1; Wed, 5 Jun 2024 23:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C8766B00A2; Wed, 5 Jun 2024 23:37:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 791846B00A3; Wed, 5 Jun 2024 23:37:03 -0400 (EDT) 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 5C65D6B00A1 for ; Wed, 5 Jun 2024 23:37:03 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0975DC1093 for ; Thu, 6 Jun 2024 03:37:03 +0000 (UTC) X-FDA: 82199052726.30.9B92BFA Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 4F23610000B for ; Thu, 6 Jun 2024 03:36:58 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717645021; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=U2u6QjJNDn7eZ+0Jnnj0QLYHOONA3gX6R1KpdWuhwyM=; b=qwMcnsr+ha29Rk1Bxa0LudceCoCii7fQj+QLpr1QNjL6VJRkfso+bYlZXKS4ixHKQoxcfV dNThvygCDbdsLGGjTxTX/qxpZgXvupJMZBNpITPaLau+gxJN2ypFL6G1ec8er3l20qKaHq 4Exi1oW7XvgbZ1zdoj6K1YAG5PLmDFM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717645021; a=rsa-sha256; cv=none; b=ScfTNAF5HxasobBIeYba35RrGWC352CgqNxvRrLAmdaz71eKAqSOU0Njt7Z4PK08CQwh8m DThNkVerDV33UhhvufXW/eOBU4m5lDPKz0dVxSxK9hgubJSmnYVUmvRLI8m14SItCTwItU 5sRsdAimP6VwmvUnHfhgU+S2RFJIhhU= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vvqkl4Mnsz4f3jtN for ; Thu, 6 Jun 2024 11:36:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id EDB171A0840 for ; Thu, 6 Jun 2024 11:36:53 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP3 (Coremail) with SMTP id _Ch0CgAn6J_VLmFmIDPrOQ--.6770S2; Thu, 06 Jun 2024 11:36:53 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] writeback: factor out balance_wb_limits to remove repeated code Date: Thu, 6 Jun 2024 11:35:47 +0800 Message-Id: <20240606033547.344376-1-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAn6J_VLmFmIDPrOQ--.6770S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WFyUKrW7Ww1ktrWxWFW3ZFb_yoW8Cw4kpF Z2ya10yr4kJF1Sqa9IyFZrurWaqrsayFWfJ348Gw4ftF4fKr17KFyavry0vF17ArnrGrW5 Zr4DtF97Gw1rCFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCj c4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4 CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1x MIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Wr1j6r W3Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUv cSsGvfC2KfnxnUUI43ZEXa7IU1wL05UUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Queue-Id: 4F23610000B X-Stat-Signature: ajez3m8xyhobzm5knn7o68sgyqg4ih99 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1717645018-561923 X-HE-Meta: U2FsdGVkX1+eJs91NU/KBQVjvVMU71khnqcEBRSIPNf+aTHtvd9d1bB263tBoyCfMxJqDyTl6O7xmZm+a3q7UAX5tok8/lCzTe7rwphIdxW5wMsv44Std/HrZVju7AkLIDNAmRL/6H+WEDty4mm5237o8knwdsd9V++kY9w1RYx9Zvw7N2Dx2p0eWPdCGgYlalg4uwSpGoy/+4R1P3AONTj/Le1Ojf6kxhtUU1NEnxY4q7pZyejnOaULua3ZjkoGHYtoenbjdhhiSE/J2nf2oOIjDeM8CguIxgHssGZjz3DWeameLIHpAOSU3pc0b9ljcSaC4YkwJyzB0MceYWltx0Hu33IB6O8FDoXlvd0b7c6VU0wJiMFEYRFCtDjTa657HXPN1xHdh50vRq0pQaA6kdQKbDpjg0VGjhp83COMX4E6ZAqgPz5bMyJ48Al5QSbxuY4oTYYh4u46fEeXBfqZ+PCB7/8Qq8dy1mZMLwPOj4tpxEEZJYvfrfkAz5QJ6D8eaAxJEkkzsE8W41cMtzLu4UFsjnXi26Si64Cb37puCo9JKGjFcqIViguaa/9n8nuBcWVxVFYzAE6Ou/gGwr2XeRsy9gGXYghCNcudqxKpvb8y5rj3oidEhkqJbVUKqooIJPeqCILVQHixscAvPoWYvIYawqapuaSLietR4C8CYE4WjvJnOZUXMXLqFB5bBWaReODPw/3h4mNpGcx/P++pXiaLxeVh7sgeCrvDNaHUZt1bFgCnhxfI1Pj/wbEk+JDzE6f2y4sSWQhn8tSwalEqVKEyM1EMHGk1iO+SPNtZdj1b7t+mz5ycjbizdQk9d02+MkXBVKEYxbDhpY4MKHfkXclUgDl5n+wQC2MkfXGu3fpXsB3jHQngFT9FTpYqFWSK2bLUPMD7yrWWnRx5UZPryhq1oJH8esamwcoSSGNjFJcte6/N23NZC8ollnIINN7HUM9qMTJLfaXZMqA8y8s wYEhqfIO BsKPbaw2MJUbsdb3BGCBdhSKzajIq+CY7HLRtsfzhz6Vz/l/jWbCEU/MkckQPGBEJWeQVPOXbTzYeAPl7syyoYynZy/x9gx+PpL2BmWNrs/AI0kQdVAQ9V9WySHjCC6UzWMeJsg3jblHolRDm7kJmhJQqaHmkBIMPG3kE2/O3BdcnJxHZEKHVKTv7v4AesOhbuyj3um/wWuJPM31zFj6yX4kNaumtyMw94hJ5PIPAIK79/sLUp3R09wcbQ9TH/pNEOGs1dmHKaZcPhnU= 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: Factor out balance_wb_limits to remove repeated code Signed-off-by: Kemeng Shi --- mm/page-writeback.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index bf050abd9053..f611272d3c5b 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1783,6 +1783,21 @@ static inline void wb_dirty_exceeded(struct dirty_throttle_control *dtc, ((dtc->dirty > dtc->thresh) || strictlimit); } +/* + * The limits fileds dirty_exceeded and pos_ratio won't be updated if wb is + * in freerun state. Please don't use these invalid fileds in freerun case. + */ +static void balance_wb_limits(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + wb_dirty_freerun(dtc, strictlimit); + if (dtc->freerun) + return; + + wb_dirty_exceeded(dtc, strictlimit); + wb_position_ratio(dtc); +} + /* * balance_dirty_pages() must be called by processes which are generating dirty * data. It looks at the number of dirty pages in the machine and will force @@ -1869,12 +1884,9 @@ static int balance_dirty_pages(struct bdi_writeback *wb, * Calculate global domain's pos_ratio and select the * global dtc by default. */ - wb_dirty_freerun(gdtc, strictlimit); + balance_wb_limits(gdtc, strictlimit); if (gdtc->freerun) goto free_running; - - wb_dirty_exceeded(gdtc, strictlimit); - wb_position_ratio(gdtc); sdtc = gdtc; if (mdtc) { @@ -1884,12 +1896,9 @@ static int balance_dirty_pages(struct bdi_writeback *wb, * both global and memcg domains. Choose the one * w/ lower pos_ratio. */ - wb_dirty_freerun(mdtc, strictlimit); + balance_wb_limits(mdtc, strictlimit); if (mdtc->freerun) goto free_running; - - wb_dirty_exceeded(mdtc, strictlimit); - wb_position_ratio(mdtc); if (mdtc->pos_ratio < gdtc->pos_ratio) sdtc = mdtc; }