From patchwork Mon Apr 29 03:47:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13646253 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 EBD7DC4345F for ; Mon, 29 Apr 2024 03:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C4626B008A; Sun, 28 Apr 2024 23:47:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13A5E6B0095; 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 C82B56B0089; Sun, 28 Apr 2024 23:47:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2DC376B008A for ; Sun, 28 Apr 2024 23:47:55 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CD28C1604EE for ; Mon, 29 Apr 2024 03:47:54 +0000 (UTC) X-FDA: 82061185668.14.102F3B8 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf14.hostedemail.com (Postfix) with ESMTP id 70636100008 for ; Mon, 29 Apr 2024 03:47:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 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=4hJMqp0kdzD927iRN9tU+qg9NNfQR5aBN07pmpBydD8=; b=hLo9bfv3Kv6zUjBc5S2FgLdpxWkQs0OmodxMaCYRCMtaGpXdW5p6TjX3AqvH4fAk621FC5 hEW8hnixk3xy9Y7Rzg3w0qzlA/9zhJ0Wcec+Krm+zDaqLmoO0JuSeiXjg2XultuNwnz5iz /3oCJpdfRvnnSltFk4KY4j8XDqCGr/A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714362473; a=rsa-sha256; cv=none; b=DxZEe3A9cHLH8RtXwSCwspwsLFg7Mu2NKwK17R56oekQia+6uRESgLLONjFNvi0ZAxcyN6 2Cilnyd/WKaBY1ID/0c1cPfHpl6ruvFR1wVMfn7bFz5XiV4L5hjLUFuNeoE2z7FB5Ftcxz R/eSe4I87QQfbE4Lodg9yL1qPNOS2FE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VSTmp4xWLz4f3nJk for ; Mon, 29 Apr 2024 11:47:38 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1E5F51A0568 for ; Mon, 29 Apr 2024 11:47:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA3UwxgGC9m24__LA--.38879S9; Mon, 29 Apr 2024 11:47:48 +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 07/10] writeback: factor out wb_dirty_freerun to remove more repeated freerun code Date: Mon, 29 Apr 2024 11:47:35 +0800 Message-Id: <20240429034738.138609-8-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--.38879S9 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1xWrWUuryUXF45GrW7Arb_yoW5GFy5pF WSyw43Cr4DJr1IqrsIyF9FvFWftrsavrWfC34Uuwnxtw1Sgr1Igry7tryrZF42kFy7Jrs0 vFs0vF97G34UJFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvf C2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Stat-Signature: g13oddq5nbse9t94zr14cdgozf5it6rs X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 70636100008 X-HE-Tag: 1714362472-254747 X-HE-Meta: U2FsdGVkX1/bLacc7iLFthQmT8pFB/wyAc/5wbWNwNJR8r1nO1m6wwSVnWa/TmTrVs1k7F+IgZx30UJvkvMhyijoovlGcHjlJ42lne+CUg0uKn21y/D81HEI3wDzy4dEPHcD+0Uswi6X6j3twemAEY3aYBwsvs57AXI0MHkOyj4BicEhFSfZixE20h/Wu6Q7zo+afctZehqZUTNdvclqdzM6zgSKbHKEqRzHFhu7qz2QuOsIwTNQMeIKEy12P7mKKry+OlTlX4a+ruRkvIaqnFMJYhf9EZpMMesOLXM1tP/mxH6F6G3VwltT3gPRxxGC0aQTqM6vBWFRFtJUmbdHTZbm6u3FuWBdzGonf194lUmmTjGsdi6e+GZKrOaU+vRnVxVyQurbYJ/uu9dIYaLs73B8tAdGO2xImCwu3h5cjwVQUN3N3NLcF2CzYneLMpsEH1rwicXqzcA4WvkjCxibtChT8Dn/9aVRmDWK0PsniA8QswZfG2fgEbl018pLudu9OVMNAa/5UJUvQpZBSE/jiqyQbvNgIJhp6VbZwrl6uYMVmh16sIFbkpJvWrE/ziFX4OV2J8H9zztQK80CYjOl1mhbMdhPxRbNDzIas//Ntc4JqmxyuwZnMB9MV/qKlONzlLO5M/yej0P1P++vxz2OcI8RsrSxEAVIdiNU+5z4McnvExX8WW56IDI52vtFp9wvG6C5ZF/gmcLUBknR+r8Xf3LheUrTbliRVM2gDnAw6nmLNMZHqYM9e3ByS83/FnEsvaJaiP6P1YIgq06+XdS4sc78dCir5v+nUKKb2X0aEJIxgxNz6C35TRTM1hDag8cCkDYKPKZGDbzMz3SPaBsa9SoO0E8RejaS7Qr0tTnKG8NDfWZB6/aVrkEo8ec+EqaBoLuCLRMKJU/4sjtR6lUpEIrNxkEv2kGfCIIYHugRIqlEepHwM/t6xXgZz3QeWVsp7WXygKEtU6c23ZUjREh KTIlNB57 0fhu0uL/kFbhNFmCxzMfRMZI7l3HUNFeNNyESnuwQWQXLlBeceCRM01FQwFlPWgn3lN6pCVBEYvnnGLbdz8GRo9dxB1xNb3nL+NWGq4GQwYgtt+RPUEJVtGul/aqrlL+663IThvlpORuZdVYxgwbU4mEr9LdzIE6Nhz08IwDYPm8u+aECqeXUI/mw4c6XgAmFWMZVArxFN9md52Ra7q/gyRLfaK3GZdq6LswbsNAWy+bJuGZcg7pCmLOW8y7KSy4p79jFDPNSPLZxfUU= 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 wb_dirty_freerun to remove more repeated freerun code. Signed-off-by: Kemeng Shi --- mm/page-writeback.c | 55 +++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b49ca82380a5..e38beb680742 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1753,6 +1753,27 @@ static void domain_dirty_freerun(struct dirty_throttle_control *dtc, dtc->freerun = dirty <= dirty_freerun_ceiling(thresh, bg_thresh); } +static void wb_dirty_freerun(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + dtc->freerun = false; + + /* was already handled in domain_dirty_freerun */ + if (strictlimit) + return; + + wb_dirty_limits(dtc); + /* + * LOCAL_THROTTLE tasks must not be throttled when below the per-wb + * freerun ceiling. + */ + if (!(current->flags & PF_LOCAL_THROTTLE)) + return; + + dtc->freerun = dtc->wb_dirty < + dirty_freerun_ceiling(dtc->wb_thresh, dtc->wb_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 @@ -1845,19 +1866,9 @@ static int balance_dirty_pages(struct bdi_writeback *wb, * Calculate global domain's pos_ratio and select the * global dtc by default. */ - if (!strictlimit) { - wb_dirty_limits(gdtc); - - if ((current->flags & PF_LOCAL_THROTTLE) && - gdtc->wb_dirty < - dirty_freerun_ceiling(gdtc->wb_thresh, - gdtc->wb_bg_thresh)) - /* - * LOCAL_THROTTLE tasks must not be throttled - * when below the per-wb freerun ceiling. - */ - goto free_running; - } + wb_dirty_freerun(gdtc, strictlimit); + if (gdtc->freerun) + goto free_running; dirty_exceeded = (gdtc->wb_dirty > gdtc->wb_thresh) && ((gdtc->dirty > gdtc->thresh) || strictlimit); @@ -1872,20 +1883,10 @@ static int balance_dirty_pages(struct bdi_writeback *wb, * both global and memcg domains. Choose the one * w/ lower pos_ratio. */ - if (!strictlimit) { - wb_dirty_limits(mdtc); - - if ((current->flags & PF_LOCAL_THROTTLE) && - mdtc->wb_dirty < - dirty_freerun_ceiling(mdtc->wb_thresh, - mdtc->wb_bg_thresh)) - /* - * LOCAL_THROTTLE tasks must not be - * throttled when below the per-wb - * freerun ceiling. - */ - goto free_running; - } + wb_dirty_freerun(mdtc, strictlimit); + if (mdtc->freerun) + goto free_running; + dirty_exceeded |= (mdtc->wb_dirty > mdtc->wb_thresh) && ((mdtc->dirty > mdtc->thresh) || strictlimit);