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; }