From patchwork Tue May 14 12:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664062 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 DA029C25B75 for ; Tue, 14 May 2024 12:53:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 933FB6B0319; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E26C6B031A; Tue, 14 May 2024 08:53:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75C356B031B; Tue, 14 May 2024 08:53:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 59C116B0319 for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 04479C11E9 for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992832.03.B8FA27A Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf09.hostedemail.com (Postfix) with ESMTP id 0B44E140023 for ; Tue, 14 May 2024 12:53:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=none (imf09.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715691213; 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=LwL0MieRU3KjkSP+PLynuT7NSCMM/lDVxlVC2gSNWbM=; b=muiTd8tAOqagOTndudlT2Zypf4wAiT9gXlMyuI5qP9yPam5M4vUTb0GXbntH+FsxpVF+kd sTnm6b+dx6Ighf4sh7TUHVRoJEbDuCyqs9jSB+6PMpnp+ZNginb3Z+2n5Vdn98P12QzOdI yZs4GVZBjnl+UcxHGN3CMD3tJF+Qi74= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=none (imf09.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691213; a=rsa-sha256; cv=none; b=PS+tt4+7zVDq3KGVcGPD017nksxPVIvvyLO9E4mxSgX8uJzACA61Y2grmI2KZcUPVfU/0f y5Qe/ASFdGwFvX8jrqL4Q7pZuDPnhXr7+ZfAVhNDb3a+y0o/Mytwy+URHrSvMR7c4oNKFc t6Bs2H4Y+w3ecHP4LL/PCTUxY+2b03Q= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9W00P8z4f3jJ1 for ; Tue, 14 May 2024 20:53:18 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 9B5F21A0182 for ; Tue, 14 May 2024 20:53:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDHzG7EXkNmCyyLMw--.6596S7; Tue, 14 May 2024 20:53:27 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org, tj@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/8] writeback: factor out wb_dirty_freerun to remove more repeated freerun code Date: Tue, 14 May 2024 20:52:51 +0800 Message-Id: <20240514125254.142203-6-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240514125254.142203-1-shikemeng@huaweicloud.com> References: <20240514125254.142203-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHzG7EXkNmCyyLMw--.6596S7 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1fXr18ZrWUKrW7Wr15urg_yoW5GFy5pF WfAw4akr4DJr1IqrsxAF9FvFWftrsavrWfC34Uuwn3tw1fKr1Igry2yryrZFW2yFy7Jrs0 vFs0vF97G34UtFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYr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S3APp/b5yeH1yMdVcH1GUj2/0ra+sxTD1apSDLiyswHHq+6ScdOY2KA7S4Np4ydZhF8dJkv+5sP1F6FhA5uSTd0o8Kxfos6WrsJ6jnEpBTqgVwiJBEIlejFMvyvnVHkgtIN0pFXxck/Ie2tJ5U+81R6LAO22l/RvRToHQRhOVJIuSaPYARHCJfvTMCW0yotr0HfGEc/STKMnZXKMOBDjjqyHWY8wtLGP2noLIirkJqTTrElZ79EArabmUHQEZWzcFAwa7rIhKdfC6W6uS4tSrs1Z5DZc5 deq4/m9a atHAmlji3x+OXOUM4SKkqwwzrxRdrNiSV9AEOQjZFTZIGe8VLp5pW1LBj8LqkwSZMMDT18auo4wmNR463nILOdVOcoRi74ePOhsso9LlmAoMTKJun0cZXltlz+b5L01v1sHKhX9Jt62MY26oIF4rZdqFCLTPmKu7kSUySr2wwhinUEaPMhosvBi/eRoXolVtV7pAWbtbV/PcmTO/l5WVQSHRZEvMfUNUHV4wxa0lFXxIwUonDw0v+zh2zDrLJeb33+TQdk7PGv5Ho6b29lk6M+p1DPg== 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 Acked-by: Tejun Heo --- 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 b7478eacd3ff..b9c8db7089ef 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1746,6 +1746,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 @@ -1838,19 +1859,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); @@ -1865,20 +1876,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);