From patchwork Mon Apr 29 03:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13646252 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 C0E2FC19F53 for ; Mon, 29 Apr 2024 03:48:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CC966B0098; Sun, 28 Apr 2024 23:47:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D97646B008A; Sun, 28 Apr 2024 23:47:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAEA16B0083; Sun, 28 Apr 2024 23:47:55 -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 27AE36B0089 for ; Sun, 28 Apr 2024 23:47:55 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C707E12177F for ; Mon, 29 Apr 2024 03:47:54 +0000 (UTC) X-FDA: 82061185668.20.A7ED0E3 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf15.hostedemail.com (Postfix) with ESMTP id E32F1A0004 for ; Mon, 29 Apr 2024 03:47:51 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714362473; 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; bh=KmjblY363rY1a20QKT/IQxUbZXWoJWRyls9zYaRWvZg=; b=IYa5VYI2YBKTIkVoviIp4fU5gRTr/cxeiw2ae/FdwQXfw3mW0TYk98X59skFPLX2eimd8q D4m2OqNEV0MW5qV7TtRBZDiIno1hHeVNt7kzQsaCA3J5YCG/rS1jIUAYj9E1457vBMv5q3 u5bXa8ypj76j8wCoN0ja4MPsQOhcp2I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714362473; a=rsa-sha256; cv=none; b=2532cpZdLmnTn5b6aQaXRnqFyCjgvZzeT2OWVFlcc5hAMdotbT4mdMM9M8yVn4oFV6tcJ8 A2uh/0zSh6ZISSts7kFOnOVWCPBD82weIc9nKqazrxrkWouwbArVaVK7z5B7BUa6c+yaCE SEgOqTsdsjObltCWmSN+EZn7FKvv8ew= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VSTmq71PMz4f3jcn for ; Mon, 29 Apr 2024 11:47:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C3C141A0B98 for ; Mon, 29 Apr 2024 11:47:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA3UwxgGC9m24__LA--.38879S8; Mon, 29 Apr 2024 11:47:47 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org, jack@suse.cz, tj@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/10] writeback: Factor out code of freerun to remove repeated code Date: Mon, 29 Apr 2024 11:47:34 +0800 Message-Id: <20240429034738.138609-7-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240429034738.138609-1-shikemeng@huaweicloud.com> References: <20240429034738.138609-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA3UwxgGC9m24__LA--.38879S8 X-Coremail-Antispam: 1UD129KBjvJXoWxJF1kAw1rAr4fAF1xAr48tFb_yoWrZFW3pF WxJw4Yy3yDXa4IqrZxAF9rXrW3trs7W3y3XasrCw15tr13KF12gFy2kFZ5Ar17CFyxJF15 ZayaqF97J34kKFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Queue-Id: E32F1A0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 9fr9d68oszkrgm5axsncupg7drib79q6 X-HE-Tag: 1714362471-125332 X-HE-Meta: U2FsdGVkX1/ceqfCScvuWH53X2Dr7GXRN0zbz+CIqNghjn4pFKfwK4t9wgGbofG5ZLYKyhr7udLPNUNUOt3TthsRcXTKWVR4y80LG639t8xFUDjcp9BL8mz+3rgXyuk8klCTz6+eZJMXUF5s70QUlgIf1mtIJENboJqFNfz3rWrnWClcZdU0BE6cs15sfACds3ZMr59qYPLjj3nMIBWXPc3ADtKOvdJh6g5/x/CdCfC7GzWq7ZLOg1QA828TVFW46Fh+82GwlWhJXTxUlh7IrJXM8kaMC/eHGFJSZU7nZ4zfajCcS2XaNuK4ASrO3sm/wnwoPc5j05qCl+cgLWc3zHyRFSONe3L6GzIffQzC1PiHgWK8otOJpecNRUtPPtOSB9uOjIrlym0sNnvr+EnuJQjcB/KjEMlkrXt+CFH77NkDi9Vx3DLrTBdN5wn24Yai93LKe0WnnNIqFEHuFZvSckUMyg7pSf4D/lxMQnBCM+19fJxESKsBgZ+I68hqMRMCPubXyM/IrY9WvskHMJih/q0NahEcaxWpuUsJcE/UMmtYetCDyS4bK4K1M1u3gojN436mq0MbeCWXZZFhHEtSvQckaEHucSiir3OsQfZXbL2RxAvN7cAuarM52jNqg3AI6oPgJrvsP6w5HFCpYfaFT09MY1tmgaV0dxetotpy409n0cj4TVjkVeRniEWzQ+yZh50SKTQmQR0PeiC+A7IdMog3c/8/w1FqmxTzoGuaF5RkMg45BshmvuE5D5Z3e34Zn4XwgAFjowWH1TX+sBnqP9osf0Ebms5jpU7Z5M2bDYQOvBaH8y3jFhfjZcSuKnHaKbWhn49Tod2MctxJAifHx2il+BZO9TObadCum4zs49y7uNK29gagly0uh/YcY5cjEnYisA2WMwrpbV2i4ArV2MZqocX+Tzf5+EZip+DP9Vik+4ypkDk0w8hJ84Kgn1Si7xinENYPxgu7fb8zyI/ CV2Rtn1D cCUHbpxTMkaJElEJ0fb5k/Fos2zvfYhMxuahi8+RBNYsNlnHM5+ApMCBvs/qDet+xwW/6Q84DfjebjdPaG3LXPsBTaMxxRB5l0P4fNYY5diYvBAwT35Q1KVXvjCDM318oxW7EOIcaOBUfflCJvOJk299BFhQH8lnpPO7qKXOOA9ZhZm/mOO8k2gysX2MTkp16H0s7WQF4VaGMRtiVPkwST9vgcQ== 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 code of freerun into new helper functions domain_poll_intv and domain_dirty_freerun to remove repeated code. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 89 +++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c41db87f4e98..b49ca82380a5 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -139,6 +139,7 @@ struct dirty_throttle_control { unsigned long wb_bg_thresh; unsigned long pos_ratio; + bool freerun; }; /* @@ -1709,6 +1710,49 @@ static inline void wb_dirty_limits(struct dirty_throttle_control *dtc) } } +static unsigned long domain_poll_intv(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + unsigned long dirty, thresh; + + if (strictlimit) { + dirty = dtc->wb_dirty; + thresh = dtc->wb_thresh; + } else { + dirty = dtc->dirty; + thresh = dtc->thresh; + } + + return dirty_poll_interval(dirty, thresh); +} + +/* + * Throttle it only when the background writeback cannot + * catch-up. This avoids (excessively) small writeouts + * when the wb limits are ramping up in case of !strictlimit. + * + * In strictlimit case make decision based on the wb counters + * and limits. Small writeouts when the wb limits are ramping + * up are the price we consciously pay for strictlimit-ing. + */ +static void domain_dirty_freerun(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + unsigned long dirty, thresh, bg_thresh; + + if (unlikely(strictlimit)) { + wb_dirty_limits(dtc); + dirty = dtc->wb_dirty; + thresh = dtc->wb_thresh; + bg_thresh = dtc->wb_bg_thresh; + } else { + dirty = dtc->dirty; + thresh = dtc->thresh; + bg_thresh = dtc->bg_thresh; + } + dtc->freerun = dirty <= dirty_freerun_ceiling(thresh, bg_thresh); +} + /* * 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 @@ -1741,27 +1785,12 @@ static int balance_dirty_pages(struct bdi_writeback *wb, for (;;) { unsigned long now = jiffies; - unsigned long dirty, thresh, bg_thresh; - unsigned long m_dirty = 0; /* stop bogus uninit warnings */ - unsigned long m_thresh = 0; - unsigned long m_bg_thresh = 0; nr_dirty = global_node_page_state(NR_FILE_DIRTY); domain_dirty_avail(gdtc, false); domain_dirty_limits(gdtc); - - if (unlikely(strictlimit)) { - wb_dirty_limits(gdtc); - - dirty = gdtc->wb_dirty; - thresh = gdtc->wb_thresh; - bg_thresh = gdtc->wb_bg_thresh; - } else { - dirty = gdtc->dirty; - thresh = gdtc->thresh; - bg_thresh = gdtc->bg_thresh; - } + domain_dirty_freerun(gdtc, strictlimit); if (mdtc) { /* @@ -1770,17 +1799,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb, */ domain_dirty_avail(mdtc, false); domain_dirty_limits(mdtc); - - if (unlikely(strictlimit)) { - wb_dirty_limits(mdtc); - m_dirty = mdtc->wb_dirty; - m_thresh = mdtc->wb_thresh; - m_bg_thresh = mdtc->wb_bg_thresh; - } else { - m_dirty = mdtc->dirty; - m_thresh = mdtc->thresh; - m_bg_thresh = mdtc->bg_thresh; - } + domain_dirty_freerun(mdtc, strictlimit); } /* @@ -1797,31 +1816,21 @@ static int balance_dirty_pages(struct bdi_writeback *wb, wb_start_background_writeback(wb); /* - * Throttle it only when the background writeback cannot - * catch-up. This avoids (excessively) small writeouts - * when the wb limits are ramping up in case of !strictlimit. - * - * In strictlimit case make decision based on the wb counters - * and limits. Small writeouts when the wb limits are ramping - * up are the price we consciously pay for strictlimit-ing. - * * If memcg domain is in effect, @dirty should be under * both global and memcg freerun ceilings. */ - if (dirty <= dirty_freerun_ceiling(thresh, bg_thresh) && - (!mdtc || - m_dirty <= dirty_freerun_ceiling(m_thresh, m_bg_thresh))) { + if (gdtc->freerun && (!mdtc || mdtc->freerun)) { unsigned long intv; unsigned long m_intv; free_running: - intv = dirty_poll_interval(dirty, thresh); + intv = domain_poll_intv(gdtc, strictlimit); m_intv = ULONG_MAX; current->dirty_paused_when = now; current->nr_dirtied = 0; if (mdtc) - m_intv = dirty_poll_interval(m_dirty, m_thresh); + m_intv = domain_poll_intv(mdtc, strictlimit); current->nr_dirtied_pause = min(intv, m_intv); break; }