From patchwork Tue May 14 12:52: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: 13664067 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 6B319C25B7D for ; Tue, 14 May 2024 12:53:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3E486B027C; Tue, 14 May 2024 08:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA2A76B0321; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64AA26B0320; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA0F36B031C for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D654C1610BB for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992790.19.CAC95F3 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf26.hostedemail.com (Postfix) with ESMTP id 4DBE1140008 for ; Tue, 14 May 2024 12:53:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=none (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) 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=9v3vuhnbf1vF4ZXypyblzT8sGgqvSrJQapse5Ol9qRI=; b=aRSfMXa6mdRVDGPqfSLsEOwl2LRBIuR4J3KPG8Cx7OrAD/vwS0quGxQ+oKAA4tF2iQYXHp BquSxq0o8IvGkyuU0vZM6keNew1q/yjVkAuY6tNeEqEdQZ1T1WhLgJzdBbxGIS+TdSgblu rsIQro+Qb6SyXBCicTM2aqpq/ZuW/Kc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=none (imf26.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691213; a=rsa-sha256; cv=none; b=zZX6TSaIty0+bJlHGtsufxOI7xLrPPzdmsvceP10vKjZxsAX3mxpZijUwrYpmYz9xp7T9Y eVHOyJnklN3wmR5dHU/P/DzMfyim+wqjrbMKffJnjgEDUrWaY4lW8hvV25B+mtW/PQ9D4B liaXap/mQYpv4ZeQbNDqljh0XhqtOCI= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9X68wtz4f3kKn for ; Tue, 14 May 2024 20:53:20 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 620CC1A0ACF for ; Tue, 14 May 2024 20:53:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDHzG7EXkNmCyyLMw--.6596S3; Tue, 14 May 2024 20:53:26 +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 1/8] writeback: factor out wb_bg_dirty_limits to remove repeated code Date: Tue, 14 May 2024 20:52:47 +0800 Message-Id: <20240514125254.142203-2-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--.6596S3 X-Coremail-Antispam: 1UD129KBjvJXoWxCw43Kr15Zr45XFWkCFyfWFg_yoW5GFWDpF ZrAw12vrW8Jr1ayrsxGFWUZr45tan3trW7Xr93CwnIyw43GryYgFyIkFZYvFyfGFW7Ja4f Zw4YvryxJw1DKrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxUzoGQUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: jf5fsj7spm7eoxs4gbtqmsy1cp6hx645 X-Rspamd-Queue-Id: 4DBE1140008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1715691211-324610 X-HE-Meta: U2FsdGVkX1/cEGNgTs/dEFwq9j8QW+etmIKHNMj323fwUgATjmt5dRQ4oNvQt5Do73r6p4807liTiXj6qgCk16N9gbs+s6QxsKT6LAR7+FGLUwqLx4pMtIio0JUodOsVsYtrBnVGkU7yEvgG833wboGYvNMLtlHD616ibUZvF6X4mNOqw1Wkq++nxoPqAWczhclEzHEIzX53RG1+L7BGhxog5iFkHZh59597NIMZlv9a8DWfiDjQYURVYdsgm+aPo5d0bKAGC7ZxY3uMARpoulqOkoPQVmdtleYJhO0SWmGJm8JM1H6/8VVxiS6TGqJ5vbveKqk0TCukDPP/x+sZ1xEMfepN6VbAXf2dWxvtlXae2oogz7zVFVRMuv1ebb88IoOi6a42ZEAvecJqTmwS4o/kfYVv+jjDDbGhnifmBiC19AIV2FXZctcRd5K0NCCrYjNQg1qW4VvGFW1/GH9unAhcufZ3U4azM03WcQzI/r8U75BV9Nca6JnDcHyHJsqS884bZv3x6kdOEqczGvIrNzMocrYh0E5PwOEz/zylJlZiYA6IGld95rC3jzOXDFxJ/mMGxLrGRi1T9SB2L72mWkkqwsBJ78TS4A0po3kowrwXYn6RgUYzT7e7/b5khyQR18m0GraFDG6+C1SmhO3WxfJV9DlzbxLgtgLl2hdbC5V5kTv0y3KLf3faUBecbBisuihnPounnblYPtzE/y3ACZEAKCOkcV9jBGC2X8O6CRBCpImymZzp3+qu2bBmW03tsfFlzWlFr/tHe1L7bNyMfAvCUssiBJte96OHJu41zIzE3syYPjC77We1hLCf5P7Yyq+sI1otFYseakC0K6Hm987j47XTth7MKK9nxuPEROtZURkc1eJz8gCoce4dibNx81OZ6wfsfMXXEzl36yLtMW6mV2HH1UVjTIWy46c9lZOP7jiMH7QBcBNtPF1emEHmjbYsvnZCGjyG/y0OHYe 1vN+AwR1 xfE5AF6JvOFOjdz98S3lITacEvOGRdqavyQ8p1Ib0QpUKR8a9+U5mpe+s8cAz6q5W95ssMheIeCDksT42eEPxOwXV9I+RiCAYp+iVgZBQn5V0Nikl/5GpZuEpyokSSQljjCF2+8HNYATKAAu4e9u95WP44TEhmM1T2H0N1OwMuzleprm5EllHK3VOospm0BOtc0aku2z/VReLX5pc4o4whnx3GLicerHiT2gcf1jlrRF/mYtY/nVlz+CbL5p0VvkPPTWcpdaEtm6pnB/synW068ac6JM941g5OBtQOUCMuPM+UfU/Q6g06Z+oDL5hR0xP9pAeZny/+HaSr6vFg+DoocM3Ig== 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: Similar to wb_dirty_limits which calculates dirty and thresh of wb, wb_bg_dirty_limits calculates background dirty and background thresh of wb. With wb_bg_dirty_limits, we could remove repeated code in wb_over_bg_thresh. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 692c0da04cbd..e1f73643aca1 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2087,6 +2087,21 @@ void balance_dirty_pages_ratelimited(struct address_space *mapping) } EXPORT_SYMBOL(balance_dirty_pages_ratelimited); +/* + * Similar to wb_dirty_limits, wb_bg_dirty_limits also calculates dirty + * and thresh, but it's for background writeback. + */ +static void wb_bg_dirty_limits(struct dirty_throttle_control *dtc) +{ + struct bdi_writeback *wb = dtc->wb; + + dtc->wb_bg_thresh = __wb_calc_thresh(dtc, dtc->bg_thresh); + if (dtc->wb_bg_thresh < 2 * wb_stat_error()) + dtc->wb_dirty = wb_stat_sum(wb, WB_RECLAIMABLE); + else + dtc->wb_dirty = wb_stat(wb, WB_RECLAIMABLE); +} + /** * wb_over_bg_thresh - does @wb need to be written back? * @wb: bdi_writeback of interest @@ -2103,8 +2118,6 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) struct dirty_throttle_control * const gdtc = &gdtc_stor; struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ? &mdtc_stor : NULL; - unsigned long reclaimable; - unsigned long thresh; /* * Similar to balance_dirty_pages() but ignores pages being written @@ -2117,13 +2130,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) if (gdtc->dirty > gdtc->bg_thresh) return true; - thresh = __wb_calc_thresh(gdtc, gdtc->bg_thresh); - if (thresh < 2 * wb_stat_error()) - reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE); - else - reclaimable = wb_stat(wb, WB_RECLAIMABLE); - - if (reclaimable > thresh) + wb_bg_dirty_limits(gdtc); + if (gdtc->wb_dirty > gdtc->wb_bg_thresh) return true; if (mdtc) { @@ -2137,13 +2145,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) if (mdtc->dirty > mdtc->bg_thresh) return true; - thresh = __wb_calc_thresh(mdtc, mdtc->bg_thresh); - if (thresh < 2 * wb_stat_error()) - reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE); - else - reclaimable = wb_stat(wb, WB_RECLAIMABLE); - - if (reclaimable > thresh) + wb_bg_dirty_limits(mdtc); + if (mdtc->wb_dirty > mdtc->wb_bg_thresh) return true; } From patchwork Tue May 14 12:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664066 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 A8EA5C04FFE for ; Tue, 14 May 2024 12:53:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8C3D6B031C; Tue, 14 May 2024 08:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87A676B031D; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 589446B027C; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EAB5F6B031D for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 70A6AA11F3 for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992790.29.64EC570 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id D7E47A0017 for ; Tue, 14 May 2024 12:53:31 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=none (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) 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=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=RVRmI0uxJQR8pfG5u1h3ZKSEwON33hQDGEsCrYD7E2g=; b=mXe0p5h8INRbEGfsZsT0glxMdRTLF2lXYtcQ7gZzZkiVgJEHrmcsH3RxLPK1QtkqQs1EU8 8WqMcUlwp2N4q/Ykt4RFJDW0loti14L1xSqsVsi5W4Ttrx94s+F6UWiG1V8cUBdB6MOvz1 dW5zVcz/2L4SIuIbp0yusokUgn5FUag= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=none (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691213; a=rsa-sha256; cv=none; b=KqU1Pe7ieVYJngPbx4aP9d3DavqgEFQnMPoe3eDLHzOBY9jS12Ag6p94tKGkJzWNbOcxW1 0nYDad/JcMIXAEHbxOaJuMMB40hrX+B8M9tN30ONOhlYvogV/4CeA16pMEVlqVSGqlCc/E t9fRAa7RAcNQkDARrn7+ZeyqsNWGEJ4= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9S3wZyz4f3n5p for ; Tue, 14 May 2024 20:53:16 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id AB5691A0ACF for ; Tue, 14 May 2024 20:53:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDHzG7EXkNmCyyLMw--.6596S4; Tue, 14 May 2024 20:53:26 +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 2/8] writeback: add general function domain_dirty_avail to calculate dirty and avail of domain Date: Tue, 14 May 2024 20:52:48 +0800 Message-Id: <20240514125254.142203-3-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--.6596S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGrW3tFyxGw45Xr47ZFW3Awb_yoWrCrW8pF 43Jws0kayUtF47Xrs3AFWq9rW3K397GrW7t34xCaySqFnFkr1UKFyI9ryvvr1xAF97Jry3 ArsIvr97Gr40kr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2_MaUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D7E47A0017 X-Stat-Signature: jayer7tf3wpppsmb6sngm5rcdbyitdjk X-HE-Tag: 1715691211-345982 X-HE-Meta: U2FsdGVkX19PQBrsaTF1zX3Xi37z4DAZJ798DNIA963s7xgnIxhPLB9JDU29/Gc0z5qb1VEVdcu3kzHveSbR0kp7oUNXZ+k2NacXjmx9+P5+JVqTLNqInMYXtbkr+4nTutu1LAR5LvDOFqdM3vFQXNxsx11v0oGqcDzCpC9her05D6goGfFmzNbqa+yc3hUUN+zIHe4/jF93bpVTcISO6s5P/3h7UQgnG2SnRc7naYJSlJD/NrE7o9Ejr6DqBJ5+qInFHNndDgNsuH4QtuL0jrNy45+dURVgZsMMqYtN2y077MFEalNUDzmxkqeiX+FrqRaMeRFiEYhL14mYdIEfV9CccwIYe0qCZymD9kAue4F88glnmLrW0jOISiYQoUl6N18CZX9lgjSdPBAjGGIJKtUPWhbI5BpCa0XwqoXKkfnJPb4l4MGktHgO0IUBTUIF8Dlk/lf3DT8hkv5MdeU4R590WiP/Z9YhW/YoIVHT5BMcwknHrRxj1SB/HYJDuNPAgeZNqbxf2pmCZv5N6XPcPIEx80CmvADopgUF1L9zb4onhjKHmnRJ22l+DAMeYMVMIIPIbNwH7g8fiKSKnQyACTP1vRs4w3IkA/RBJZ2b+oTfTsigvJqp+AcH+W2l8okqBS1eBBrv+P6OHNvg8OdoNVi7Y9C1qahAG7hNOuULfpfO9XHMZX1472wHhGOk5sqVyCiVWTmXWx/NVpGcQ8Evda3DXbI9wl149P/guOolIrNxAvNaZSOcWUMVpCuvQ7OdNaC2qUl8AmYMgqEuISGe+K80ppEpGaqRsxtQciaxRBqOIk++1ZMDdGOg+2ySRqz9aByLCltWs2NwvK2MBRzDESMJKu/AqzLOADOUEzhYBFbOgLsr27/iY199Y6hNRzaIpKs4KxJ14HZm3Xo1XHMUuWFFnds78ejmHu1NMfBwM0wfObWRs+aA4BTeqaQwEU8BBzbDZ9mYJjLQor6c8Z6 fGGgU+zH 1ZZ0SPmEoWBkVOtRau8NDQamf07BoROspZ8qzovE4jsDxGnmKK+NVGD5BnYNKZebgDUhbMdzVY/NKme9MXPWhFfN4gz7w69tI+bPGDyMmWTCqMCOF2XhtQGq/SoztAmhqaiUmDbMD34IgL/sYngwlmEJMfzOsXbDKzc9ET1rsMV/fBmYAUpoEOEPnM9k3CsdsVjQYhPyXnvHxZPFDE3pmp4PzgCSOy0nic+G7YHepCJxPwlHYoT64OtRBfaGpA4jR7IYWjgrXR1XWIEM8FyBQ9UWl8w== 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: Add general function domain_dirty_avail to calculate dirty and avail for either dirty limit or background writeback in either global domain or wb domain. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index e1f73643aca1..16a94c7df260 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -837,6 +837,34 @@ static void mdtc_calc_avail(struct dirty_throttle_control *mdtc, mdtc->avail = filepages + min(headroom, other_clean); } +static inline bool dtc_is_global(struct dirty_throttle_control *dtc) +{ + return mdtc_gdtc(dtc) == NULL; +} + +/* + * Dirty background will ignore pages being written as we're trying to + * decide whether to put more under writeback. + */ +static void domain_dirty_avail(struct dirty_throttle_control *dtc, + bool include_writeback) +{ + if (dtc_is_global(dtc)) { + dtc->avail = global_dirtyable_memory(); + dtc->dirty = global_node_page_state(NR_FILE_DIRTY); + if (include_writeback) + dtc->dirty += global_node_page_state(NR_WRITEBACK); + } else { + unsigned long filepages = 0, headroom = 0, writeback = 0; + + mem_cgroup_wb_stats(dtc->wb, &filepages, &headroom, &dtc->dirty, + &writeback); + if (include_writeback) + dtc->dirty += writeback; + mdtc_calc_avail(dtc, filepages, headroom); + } +} + /** * __wb_calc_thresh - @wb's share of dirty threshold * @dtc: dirty_throttle_context of interest @@ -899,16 +927,9 @@ unsigned long cgwb_calc_thresh(struct bdi_writeback *wb) { struct dirty_throttle_control gdtc = { GDTC_INIT_NO_WB }; struct dirty_throttle_control mdtc = { MDTC_INIT(wb, &gdtc) }; - unsigned long filepages = 0, headroom = 0, writeback = 0; - gdtc.avail = global_dirtyable_memory(); - gdtc.dirty = global_node_page_state(NR_FILE_DIRTY) + - global_node_page_state(NR_WRITEBACK); - - mem_cgroup_wb_stats(wb, &filepages, &headroom, - &mdtc.dirty, &writeback); - mdtc.dirty += writeback; - mdtc_calc_avail(&mdtc, filepages, headroom); + domain_dirty_avail(&gdtc, true); + domain_dirty_avail(&mdtc, true); domain_dirty_limits(&mdtc); return __wb_calc_thresh(&mdtc, mdtc.thresh); @@ -1719,9 +1740,8 @@ static int balance_dirty_pages(struct bdi_writeback *wb, unsigned long m_bg_thresh = 0; nr_dirty = global_node_page_state(NR_FILE_DIRTY); - gdtc->avail = global_dirtyable_memory(); - gdtc->dirty = nr_dirty + global_node_page_state(NR_WRITEBACK); + domain_dirty_avail(gdtc, true); domain_dirty_limits(gdtc); if (unlikely(strictlimit)) { @@ -1737,17 +1757,11 @@ static int balance_dirty_pages(struct bdi_writeback *wb, } if (mdtc) { - unsigned long filepages, headroom, writeback; - /* * If @wb belongs to !root memcg, repeat the same * basic calculations for the memcg domain. */ - mem_cgroup_wb_stats(wb, &filepages, &headroom, - &mdtc->dirty, &writeback); - mdtc->dirty += writeback; - mdtc_calc_avail(mdtc, filepages, headroom); - + domain_dirty_avail(mdtc, true); domain_dirty_limits(mdtc); if (unlikely(strictlimit)) { @@ -2119,14 +2133,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ? &mdtc_stor : NULL; - /* - * Similar to balance_dirty_pages() but ignores pages being written - * as we're trying to decide whether to put more under writeback. - */ - gdtc->avail = global_dirtyable_memory(); - gdtc->dirty = global_node_page_state(NR_FILE_DIRTY); + domain_dirty_avail(gdtc, false); domain_dirty_limits(gdtc); - if (gdtc->dirty > gdtc->bg_thresh) return true; @@ -2135,13 +2143,8 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) return true; if (mdtc) { - unsigned long filepages, headroom, writeback; - - mem_cgroup_wb_stats(wb, &filepages, &headroom, &mdtc->dirty, - &writeback); - mdtc_calc_avail(mdtc, filepages, headroom); + domain_dirty_avail(mdtc, false); domain_dirty_limits(mdtc); /* ditto, ignore writeback */ - if (mdtc->dirty > mdtc->bg_thresh) return true; From patchwork Tue May 14 12:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664065 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 0F4A3C04FFE for ; Tue, 14 May 2024 12:53:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 947636B031A; Tue, 14 May 2024 08:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7366D6B031C; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38D986B027E; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EBC2D6B031F for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 24219121186 for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992790.27.45E859E Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 3CFAFC0013 for ; Tue, 14 May 2024 12:53:31 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) 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=IlnR5L3D+FBjNpPSrrMEAYZVW6cLDbt2FV1F+BNadgM=; b=qB3Rsbn0hLZ86oIE8ALAqEDJow/DulHdtOWmpexbGSEmGnncqdApstTQpZt4XGxaYyL7xS Oz9LO4UcqINeBTJrHKsdMp5ey7mL9kq3YgndOhRqtPCtIhGzPKZdCNzKWso/Ca6ggJUkF1 3uDiD6QZ4AVKw0itYwt2Qt8v5MJ8fXM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691213; a=rsa-sha256; cv=none; b=ru/f4xduUKR++p6HdpAz5WTsXg9FMCGrNLTE4hM1Ut0tnKcjGQjKL7g2+3ZCbM1/0Xrle3 SUqfetWfgoUWT0C9C+fat1zvOcgo0r5fJREwKU1YxZ6x+LwU0wetEDlFYoS3wh146ydRTU 94JmaetA2y1EI83SpRplvdX0s9lH2h0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9S6BC8z4f3n5r for ; Tue, 14 May 2024 20:53:16 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 029241A0D52 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--.6596S5; Tue, 14 May 2024 20:53:26 +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 3/8] writeback: factor out domain_over_bg_thresh to remove repeated code Date: Tue, 14 May 2024 20:52:49 +0800 Message-Id: <20240514125254.142203-4-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--.6596S5 X-Coremail-Antispam: 1UD129KBjvJXoW7WrW8CrWxXFykGr4Duw43trb_yoW8tF4rpF 4fAw1a9rWUJanrXFnxCFyUur43tFZ7t3yUJ3srCwn3Aw43Cr4UGFy7ArZYvFy8AFy7Xrya vr4ava4xGF10krJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvGb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjxU2PEfUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: hk8facek6muce8f8tp7h3bepgqnera95 X-Rspamd-Queue-Id: 3CFAFC0013 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715691211-455008 X-HE-Meta: U2FsdGVkX1++ukaQyPxTN80vBF5QjLx0UAOl6OdKq+NSVAiTtbTGsu7vVRME92Gc/OZUs+kvu5qdEZEQYh6YQzYtlPKE7wE80njn2dgQJeIdqwTINfJ1/tjE6N/xb2zBkPoZymqUFKCyL0o3NvQQL57K+PMb48N+Ktf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CjFoJb+CTTEmoDCfhdPPtaW4QtBvZS9GFftMbNkMs62PXEssG7LwJAMg4NjtJeaPiUaw3C0MyU3T4bYTgVr+djdN2J0jdBK047IaHtxoMky0gQ== 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 domain_over_bg_thresh from wb_over_bg_thresh to remove repeated code. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 16a94c7df260..e7c6ad48f738 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2116,6 +2116,20 @@ static void wb_bg_dirty_limits(struct dirty_throttle_control *dtc) dtc->wb_dirty = wb_stat(wb, WB_RECLAIMABLE); } +static bool domain_over_bg_thresh(struct dirty_throttle_control *dtc) +{ + domain_dirty_avail(dtc, false); + domain_dirty_limits(dtc); + if (dtc->dirty > dtc->bg_thresh) + return true; + + wb_bg_dirty_limits(dtc); + if (dtc->wb_dirty > dtc->wb_bg_thresh) + return true; + + return false; +} + /** * wb_over_bg_thresh - does @wb need to be written back? * @wb: bdi_writeback of interest @@ -2127,31 +2141,14 @@ static void wb_bg_dirty_limits(struct dirty_throttle_control *dtc) */ bool wb_over_bg_thresh(struct bdi_writeback *wb) { - struct dirty_throttle_control gdtc_stor = { GDTC_INIT(wb) }; - struct dirty_throttle_control mdtc_stor = { MDTC_INIT(wb, &gdtc_stor) }; - struct dirty_throttle_control * const gdtc = &gdtc_stor; - struct dirty_throttle_control * const mdtc = mdtc_valid(&mdtc_stor) ? - &mdtc_stor : NULL; - - domain_dirty_avail(gdtc, false); - domain_dirty_limits(gdtc); - if (gdtc->dirty > gdtc->bg_thresh) - return true; + struct dirty_throttle_control gdtc = { GDTC_INIT(wb) }; + struct dirty_throttle_control mdtc = { MDTC_INIT(wb, &gdtc) }; - wb_bg_dirty_limits(gdtc); - if (gdtc->wb_dirty > gdtc->wb_bg_thresh) + if (domain_over_bg_thresh(&gdtc)) return true; - if (mdtc) { - domain_dirty_avail(mdtc, false); - domain_dirty_limits(mdtc); /* ditto, ignore writeback */ - if (mdtc->dirty > mdtc->bg_thresh) - return true; - - wb_bg_dirty_limits(mdtc); - if (mdtc->wb_dirty > mdtc->wb_bg_thresh) - return true; - } + if (mdtc_valid(&mdtc)) + return domain_over_bg_thresh(&mdtc); return false; } From patchwork Tue May 14 12:52:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664061 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 A7EDDC04FFE for ; Tue, 14 May 2024 12:53:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A6DD6B0318; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 056FE6B0319; Tue, 14 May 2024 08:53:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E60AF6B031A; Tue, 14 May 2024 08:53:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C86A56B0318 for ; Tue, 14 May 2024 08:53:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7E3D014069B for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992790.21.0609DB8 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 764E910001B for ; Tue, 14 May 2024 12:53:32 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=none (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) 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=ieEtLzMmMqCrvyQ9MTJSR7uAGtRW58Q2kyz2C00Y7o0=; b=aG7kan6MkCvISEf5Ctaq4MYn3zkdtNXV87Q9nr2ZinH5JpD0MRsj88ReqJmtJy9Qwod98L +CoiF1TrUtv8A/3Ir51VTF0RWvm2w6LTqat8i8uVhIU/jTi6XSF1RCEwyVUbkm9IgW6nQ1 GzWNEE5J25FclzapWljarf9sXGGFRBw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=none (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691213; a=rsa-sha256; cv=none; b=kOGpQjtj01oZ3SrRcUifVO+UnnGrhjI0qs9GTloke/Nwoyz+JHYJ0iubnLlxas3oWEOIJj Rux5mzD79SHOwWYcrMECg5UzNLzrjGdVw1qOxbKURbMwuFuHaJcVSnm4QMbH3w5sBRigUe A/eatMf2PlTZBe1yLyem3GlZM8tax7w= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9T1Cf2z4f3m78 for ; Tue, 14 May 2024 20:53:17 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 4D3FA1A0AD7 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--.6596S6; 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 4/8] writeback: Factor out code of freerun to remove repeated code Date: Tue, 14 May 2024 20:52:50 +0800 Message-Id: <20240514125254.142203-5-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--.6596S6 X-Coremail-Antispam: 1UD129KBjvJXoWxJF1kAFWDuw43KFyDZrWfAFb_yoWrur13pF WxJw4Yy3yDXa4IqrZxCF9rZrW3trsrW3y3XasrCw1Yqr13KF12gFy2yF95Ar17CFyxJF15 Za1aqF97J34kKFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI 42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWI evJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 764E910001B X-Stat-Signature: o5fp7a64s9arioj6nzf976da168ytfjc X-Rspam-User: X-HE-Tag: 1715691212-254826 X-HE-Meta: U2FsdGVkX194y+nAsQEcAVS+Npviodl4sSqFWMZ7fvfKJNAhH9AeN4VtoUhEgpZ1X9kdQCBljL8hMHxlUnsdVqx4OcY1N/GsJdXAHHVAK55yOUY3weT+UwjSe3MWXojdiMvKHu9M498++H1qc2MOjMVWZVPt/b6m9fc3W1LLq1OWMOGL0ri2TzixTwKYLsVEIGGCOUHGDNya6HeVG/P4iBoaFHgTDMJB8V2mY4sHV7SCTaRD2I+OHzDAHlKhKL2BCVWur3rJIxaKPQgpRpoo39+pYSr+VDIK9lh7Wb5iuUVjlje6dDgzR4yMkFAEbS6zrX1XKjnSLs4l91tuMXbMvbWBx/C+Pm6OqyE9ZTchli8Yv/BOs3pwIOB8Dwb+R1eHN8bxcPao7Z+rsaqMGRAvXMAvGwyHgOi2YP+KXdhoc9he+8/xKN25qlVfppUNlCPFRSLKBPVl3nB9Rsie4sc0XYVNQ2EvC4wWTYOE7X95NSolRuHUfWdTQmrMCTtoq0jZkU1QLBVLiquSwC1FaTXTISs4rheSmPBudDuekBROTidmaMObWYWmfDf7qLxax7o5Xn0j+McqgjsS/UdiLITTenAJ9Ax2hkfighsOfHTF2nCq7SjcZv6c4ppoWZ13kVw9zA3r5Yuz20tmlxSGI4TC4Ib7UiT3G43vMRgozhlvggz3PxHfLP6aRPqST5Tsy9+qSbp1Acwmbti8slJfPntrD5YdOwwyYu3mdJDm0x4eF+VKfQZwszFj9Px2MTtzi6dy9RzFqRjxS2rDER37Jdj66135LoTDsLpTaxQfj6CYEF0JsfiQV/OkCGSADaBPtlfqTab1qSGE/m6dpCTjLAYKyVHplQgyPq7eJUyAr7q7bP0oldwtJyD6DxFTIIGKPRnZo40g3NYDMrUMhGK2kL3XS+ifRA2ebFiqFJqDc8XcU0vtKP29sLQpNgQnpOCD/zl2v9SU/LhmiLJmC15hnAN uoSjn9nI V4mc+i9jVDb1717ar+UKgxfrPH4TaJl1te9zOzQiOZLbcx8bLTiqfDKeP0J/KKsWgaH62P0vJjBKeMVFv4UXvdR90umGhiHrDB3RjLcOfpxQsk0aG7/k1eUEP6at4tRmCjJF3YvLPl5EKjC6VEKbrler9sMnbRC+ynmFRN8uEQZ/4y422CXkVbv/w9mw245N4gRTCWu12HwwnFnMqH8d28U1IiMAhVFcBU3mBDUKq1WavZa/Z3+wHL8KiWA== 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 e7c6ad48f738..b7478eacd3ff 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; }; /* @@ -1702,6 +1703,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 @@ -1734,27 +1778,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, true); 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) { /* @@ -1763,17 +1792,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb, */ domain_dirty_avail(mdtc, true); 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); } /* @@ -1790,31 +1809,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; } 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 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VA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WrsJ6jnEpBTqgVwiJBEIlejFMvyvnVHkgtIN0pFXxck/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); From patchwork Tue May 14 12:52:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664063 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 07C17C04FFE for ; Tue, 14 May 2024 12:53:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B5D76B031E; Tue, 14 May 2024 08:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 318316B0320; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11D846B027E; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E78226B031A for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 07A7F14125E for ; Tue, 14 May 2024 12:53:36 +0000 (UTC) X-FDA: 82116992832.01.613E642 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf30.hostedemail.com (Postfix) with ESMTP id BA76580002 for ; Tue, 14 May 2024 12:53:32 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=none (imf30.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=WMrJbiEWpN5NH6F5AoU86xAjAgWYamOSH4B7klexMUE=; b=XWAZHzJKcdbS0PqGNNJhdXl/+hZ/gd5evv5GItrU5qJQkn3K9ZPDQomEAHAEreIOR223Ei obrKMs2vLy5iq0+6IdZCyojsCfv/vqhfFz5npTMZxLgEoX+/pZLhYeKm1aizSyJ2UAgBvA 2zjC8y061kAGgGyIPUPBmPKP3LHCt6Q= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=none (imf30.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=ICLREui3UEHb9G6OFroMaCe1t2jhCWLGwojxXGZWd7W135X0lvevAH0qJY6GJbPJcknjKb WhLL1KU1hf76lzVC6MP9MZhL/BvASB8NrMZnWwCL7aMd/nFSaW8hK4A1+aw7g0hUL839IR s8AAvDFQ2kmRWs1ybSJ3U6Rc53uoTw4= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9W27hRz4f3jcs for ; Tue, 14 May 2024 20:53:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id E368B1A0D5E 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--.6596S8; 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 6/8] writeback: factor out balance_domain_limits to remove repeated code Date: Tue, 14 May 2024 20:52:52 +0800 Message-Id: <20240514125254.142203-7-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--.6596S8 X-Coremail-Antispam: 1UD129KBjvJXoW7AFW5ZFyDKF18Jr4UAFy5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lgc8VTJ+qcppKNFySN2d oLa9MwnQ SNXd8NBIA1NU/O1U7FsIC8MyKNlc921J1GYtW5J+fYvEnDyncRFs+48tVfspOKUM8WLBY7K1Y7wD5IarEnaHXcfF1m8AL/K34r2/bx1pnWrJWP8YobGql6Cjvq4MlLYsywdKsArbOM9dhkXa/9tVvtePS5Z3O9hLF3FQ2yZf/rPr6xS0pZKJeqVu3Gf9bxSfKK6Yq8cf9jpSVz+O4JWV7CJbgQq43kOI8u8icKZX4tRlBSJWWsiPpDHyCuJsdcDkT8hiHuPE9ogWu2WBazVXSVLSYfNLRTMF9rjSX3z0zRBAbYo20WOEoi20Gci0lWYc5Tk3MCCLzArbsd1XNUoWV4JxICLtrRkMvHAE7eUL6Suje6UBrDxSIKjluIQ== 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_domain_limits to remove repeated code. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b9c8db7089ef..97ee5b32b4ef 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1746,6 +1746,14 @@ static void domain_dirty_freerun(struct dirty_throttle_control *dtc, dtc->freerun = dirty <= dirty_freerun_ceiling(thresh, bg_thresh); } +static void balance_domain_limits(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + domain_dirty_avail(dtc, true); + domain_dirty_limits(dtc); + domain_dirty_freerun(dtc, strictlimit); +} + static void wb_dirty_freerun(struct dirty_throttle_control *dtc, bool strictlimit) { @@ -1802,18 +1810,13 @@ static int balance_dirty_pages(struct bdi_writeback *wb, nr_dirty = global_node_page_state(NR_FILE_DIRTY); - domain_dirty_avail(gdtc, true); - domain_dirty_limits(gdtc); - domain_dirty_freerun(gdtc, strictlimit); - + balance_domain_limits(gdtc, strictlimit); if (mdtc) { /* * If @wb belongs to !root memcg, repeat the same * basic calculations for the memcg domain. */ - domain_dirty_avail(mdtc, true); - domain_dirty_limits(mdtc); - domain_dirty_freerun(mdtc, strictlimit); + balance_domain_limits(mdtc, strictlimit); } /* From patchwork Tue May 14 12:52:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664069 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 D4D0AC25B7B for ; Tue, 14 May 2024 12:53:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64D626B0322; Tue, 14 May 2024 08:53:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AEEC6B0323; Tue, 14 May 2024 08:53:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 428216B0324; Tue, 14 May 2024 08:53:42 -0400 (EDT) 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 198856B0322 for ; Tue, 14 May 2024 08:53:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 911DB1C1606 for ; Tue, 14 May 2024 12:53:41 +0000 (UTC) X-FDA: 82116993042.15.E178F3B Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf17.hostedemail.com (Postfix) with ESMTP id 1BC7840013 for ; Tue, 14 May 2024 12:53:37 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=none (imf17.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715691219; 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=VpwvkJTJKj9ehosxWP/E50lK1hDX8qLG01cJAFmHKes=; b=cDSc6/lKSx/4YGu79+OFgLZ9HEVdHj8uQ7uGOcCb6Wk2BhqxP+LIfpDmYzGp/tin7GLz7z wmGOd1b63QI8qdA17r1FxBCaJDmB6ydRkQdPlISuhLla45XvtYqQ0VhcOk1jYc1KSWdeTk w0dzyLP4QpXt1jxNmNlP/Jz6rSlIj7k= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=none; spf=none (imf17.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691219; a=rsa-sha256; cv=none; b=DdGgOGxV2eMbARNwW31JZ6eXwJ5vWhxtGiAqXFBMiLFbjoOrnjGlijDIcmi3xTnmQQKer3 4uObRN+lJmc0OvcWnY7y0l46GGbdLkIgMl9asLcXu/xOjO+dwbB127QTKxFc8S5V9kpAvJ lC9eri4yySfW9DuXYCRjVw9kiOJGi+s= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9Z4tf3z4f3kKy for ; Tue, 14 May 2024 20:53:22 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 38B221A017F for ; Tue, 14 May 2024 20:53:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDHzG7EXkNmCyyLMw--.6596S9; Tue, 14 May 2024 20:53:28 +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 7/8] writeback: factor out wb_dirty_exceeded to remove repeated code Date: Tue, 14 May 2024 20:52:53 +0800 Message-Id: <20240514125254.142203-8-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--.6596S9 X-Coremail-Antispam: 1UD129KBjvJXoW7AFWfZr4xKF4rJr4kJw4fZrb_yoW8KF47pF ZrJw4Ik3yUJa1SgasxJFWDur43trs7JrWxJryUWw15ta13KF12gr92qFWFvr17ArZxJF4Y vrZ5t34xGw18Kr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvEb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v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DqkGNE4Fo04D93Qi4kbzr9/GahkIUDstP5Ykj0bNEzNHc7Q1LnKPCztDCjUWWt+A/+19SW6MSjrw6aGTFtH78nTns1UGOnGVp95K6pPVLTgMc4VzHnQYEEeusJ+HyTiyELAwdg+/fdznvfPfuxgvS1UApDRUKnfctk+TcICstiAPXOqWqTPjcCS8J23tuK63mHmlPcAR07NbgaLKH88RqIBUGg8gkyWgft3uJ3OsOwU0wZz3oYE7uj9xcsFRCXKTlqIfJ7BTW2Q/XLYeblxbM06NuP45qw5Bd+0+16VXZzjVM0fj79wpGYaiw6iLn/hS7beoWLLIO4e0I2hNjyDHW7gV2u/2Y7tc2PwcPGIIM7GY4vdbB1cfXyPhP9NMXiKTB1GFP2bCWWABU4TR/d6gv++hSlMlju0HR0vWYwsWL2nTqYYlA/u+NYgdihpn EweTXKEh lwrMNYs62RzmiLoan19+5eVXosBdFvlfYK/PeLxPRfw5Fg0ZJv1K3AHCkefEwrwkon+DD9Zy9DaT5lKjRan5qD77BhFACBMvzyFEzZe7CSUFiY9d+HXAZ+79JSgK608++gJUjz/f/kyd/nYvrBkcjJcoQTLXVSgstcHMjG9mEPUYBibVE8ZzKrHFZ5Obl33XE0TOTlREH3IPv2YyQKQkx+SYEuZdDh0rkEglA 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_exceeded to remove repeated code Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- mm/page-writeback.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 97ee5b32b4ef..0f1f3e179be2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -140,6 +140,7 @@ struct dirty_throttle_control { unsigned long pos_ratio; bool freerun; + bool dirty_exceeded; }; /* @@ -1775,6 +1776,13 @@ static void wb_dirty_freerun(struct dirty_throttle_control *dtc, dirty_freerun_ceiling(dtc->wb_thresh, dtc->wb_bg_thresh); } +static inline void wb_dirty_exceeded(struct dirty_throttle_control *dtc, + bool strictlimit) +{ + dtc->dirty_exceeded = (dtc->wb_dirty > dtc->wb_thresh) && + ((dtc->dirty > dtc->thresh) || strictlimit); +} + /* * 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 @@ -1797,7 +1805,6 @@ static int balance_dirty_pages(struct bdi_writeback *wb, long max_pause; long min_pause; int nr_dirtied_pause; - bool dirty_exceeded = false; unsigned long task_ratelimit; unsigned long dirty_ratelimit; struct backing_dev_info *bdi = wb->bdi; @@ -1866,9 +1873,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb, if (gdtc->freerun) goto free_running; - dirty_exceeded = (gdtc->wb_dirty > gdtc->wb_thresh) && - ((gdtc->dirty > gdtc->thresh) || strictlimit); - + wb_dirty_exceeded(gdtc, strictlimit); wb_position_ratio(gdtc); sdtc = gdtc; @@ -1883,17 +1888,14 @@ static int balance_dirty_pages(struct bdi_writeback *wb, if (mdtc->freerun) goto free_running; - dirty_exceeded |= (mdtc->wb_dirty > mdtc->wb_thresh) && - ((mdtc->dirty > mdtc->thresh) || strictlimit); - + wb_dirty_exceeded(mdtc, strictlimit); wb_position_ratio(mdtc); if (mdtc->pos_ratio < gdtc->pos_ratio) sdtc = mdtc; } - if (dirty_exceeded != wb->dirty_exceeded) - wb->dirty_exceeded = dirty_exceeded; - + wb->dirty_exceeded = gdtc->dirty_exceeded || + (mdtc && mdtc->dirty_exceeded); if (time_is_before_jiffies(READ_ONCE(wb->bw_time_stamp) + BANDWIDTH_INTERVAL)) __wb_update_bandwidth(gdtc, mdtc, true); From patchwork Tue May 14 12:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664064 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 79CA3C04FFE for ; Tue, 14 May 2024 12:53:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 658496B027E; Tue, 14 May 2024 08:53:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 513106B031A; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2746B027C; Tue, 14 May 2024 08:53:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EAF6C6B031E for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D97BB121246 for ; Tue, 14 May 2024 12:53:35 +0000 (UTC) X-FDA: 82116992790.14.CD80184 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf04.hostedemail.com (Postfix) with ESMTP id 482A140011 for ; Tue, 14 May 2024 12:53:32 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=none (imf04.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) 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=1715691214; 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=0EhsKrW/Sp6dPIJFD2cCoXmFIaalgzDjYH4iMS4P2Uo=; b=YXZV1+5dvNe9A/qnIs62d82Y44nhnhBYE+YTdmhYnkgalO5W2Fl1Ta8PznvHxildiV1t3S 6x6m8BfoDzeY8+I6NgjmLoqCH/3drsjr5lUbvz0go8RuLcpQVZ6SyMjT7Jf/TDIm4C3+6o glZqrqAdLcYrZ4vHy3E0ocwDWhkh+v8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691214; a=rsa-sha256; cv=none; b=7l4q4DDkXnllFRAWeslQ6F5VcBu265NJRuhKKqLok6zUhMFx4WCVFSr0S3FPBWWyUtU3O4 b9VPxq3d8awlxq+hL0aMK5qyHZkNxgvUNs8rlGTc34DfySUzFjsRgbJ+sQN52Ar2mTCIt/ 2yDPfSKN3nnyD8hT8OaQ+jD7YBzczPo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=none (imf04.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9W6RDbz4f3jcq for ; Tue, 14 May 2024 20:53:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 842BF1A0AD6 for ; Tue, 14 May 2024 20:53:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDHzG7EXkNmCyyLMw--.6596S10; Tue, 14 May 2024 20:53:28 +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 8/8] writeback: factor out balance_wb_limits to remove repeated code Date: Tue, 14 May 2024 20:52:54 +0800 Message-Id: <20240514125254.142203-9-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--.6596S10 X-Coremail-Antispam: 1UD129KBjvJXoWxJryxXr4rXFW8CrW8Jr1DJrb_yoW8AFyrpF Z2kw40yr1kJF1IqanayFZF9rWaqrs3tFWfJ348Gws3tF4fKr12gFy2vry0qr17ArnrGrW5 Zr4DtF97Gw1rCFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIda VFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 482A140011 X-Rspam-User: X-Stat-Signature: u9gk4nw84xjp5a1ybhp599itkhx8nqhf X-HE-Tag: 1715691212-335918 X-HE-Meta: U2FsdGVkX1+Lgce1IjYNdymp76QJaEf3cV/ZJgtB5DDPF3PGjBuhSMHH50bknDFbsAPI+JWbL0etx1v8UEpODx6V/qvEHYJS+f1h4dSMUpCk+CcdnzFkktSTlUPzsWJr5mxPmKLBiIScd3LOkWHxsKtLkh/nTgrIbdU8ZpVmDfLsmaCwSEGElW8zalD+ICWWmFY1NtTdaNR35P2uT/TyQhbvklzf4IEOd88rV93z+G8BVIIRsqTtuHrz5+ErSRBbDGqE22jQAUOPB/DJi7JVAhG/i1mrQaXo8ETBsifRQXBVwpLaJXFnpCW1W834pXki8JfM1o6lbSE3WfkJxLlnc8owM6aCate53vq8BdEQr4v0CCRovh9J6tfsm15HCvma52sqa4a74pEO/KgrVz87JEgmxbar3ExipsZjDFn+UtnKQbd1cDBSkX5I6z30D4ceEaQ6a6KHCwFF3v14PaJHTXTFiwJeXoPS0d/cF/9jHriYxycfSPl+8mVWh7IeYrKgxDzs4UdeyPA+piq9dQqp5bO791aQWEBkpcRojMQkoCnEerwph9jUa8yFjLKXJ8N7CNImjG5SEOHD6nTzar1jDBPQ9A8g+nQAzxs0fB/ubbGfU8nllteRZclkyiGrjCnsn0OuuACcXCAYiGli7IfkhuLUo0NbksV2zA9UXWyXSOB3gXqYdk9p/Jtv3caemuLEdo60TGToZV8Z3091pVAVWouUH0e6AAt6xz7CqDFr4g09qQwiortorfohnzCt4jin/sgb0uKeTMHpMV6FV0IvFIGslM75NhYok+lvLn5rRjd62lSAEGyUzndDJ9GUsCHnLSSqq5biJh1BU24dD/RonQ6yNwOyuLpHbCK9iaCEBYQotXQfu2LpboxKaUpjHQk3R2+kjBWAZUp+lNDnrrOhE80JXUaWBjeoFjykEwqusxDb2TysmFHW9m98cV4xwkjBcC/ZQlpTJiWmdGDdKsY zORF6BpB 3UKYBkDw9Rihr5QLBMJ9IZ9hJeJE5XZE8+dYJX6IJ08MZnQDAgLaKHqpYZHR7t2f38gNcxPbbdlV4ycS0J5gZ3nATKh/wUgurQvqZsd920XCEpO0r2VRcbBQrd8fJLZNfbD7qSjui9wRz5oUp5toaSxXbcDb+QLcCwJrnA9r/kzjSRh7fV4YdqZfnPLdr7lcIpa1EpyxZB1UyLcUA/tjDL4qvLTFqrT39cFMeKBl/V9FOpdxTxk6Mhl+zwzxv95eUSDGrLiq1NJqc3rrZra0HJZ2WRA== 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0f1f3e179be2..d1d385373c5b 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1783,6 +1783,17 @@ static inline void wb_dirty_exceeded(struct dirty_throttle_control *dtc, ((dtc->dirty > dtc->thresh) || strictlimit); } +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 +1880,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 +1892,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; }