From patchwork Tue Jan 23 18:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13527202 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 BE7A4C47258 for ; Tue, 23 Jan 2024 10:36:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B2C86B0080; Tue, 23 Jan 2024 05:36:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 314D06B0095; Tue, 23 Jan 2024 05:36:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5DDC6B0092; Tue, 23 Jan 2024 05:36:02 -0500 (EST) 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 C232B6B008A for ; Tue, 23 Jan 2024 05:36:02 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 86B0D1407E6 for ; Tue, 23 Jan 2024 10:36:02 +0000 (UTC) X-FDA: 81710220564.07.28C7726 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf25.hostedemail.com (Postfix) with ESMTP id 89D1CA000B for ; Tue, 23 Jan 2024 10:35:56 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706006160; a=rsa-sha256; cv=none; b=G+WYUqB0UEVk8eGh8212uD5r4geiBQkAaJ35/Ad+mCzwdmaZfrSz5Df+ghGfU7u5Kb9FG2 Su9xKkh89ZEeqBcsPl28P9Ty+7zcLQ01rr4zHdZjLSdDeTT4+KS7XCjqsOXGsCPMR+guNB 0Jr/zbuDV6cNQd+9QhfVZo3m18E51Ng= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706006160; 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=OAaqomji99g2cRoUEAO6uaDJ6TGdmIFEqLlbI9qqcjA=; b=amyXSf0PJh3CDU9xNNXiRpTV4c/YQi+SoE4PJ1Ouk44Jz3txEWnJnKAwdS9ynFs91OzH8s v1TmSGj8BIXgYn6VpPHY0yzdtR1XdpQ7OshXZScGVRT8eUIUia/Lu+J6UVzvX+apy5AnsL EUr1jwrqsZXCcbIOnlhLMKDmGDDRv5Q= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TK3QT11hJz4f3lW1 for ; Tue, 23 Jan 2024 18:35:45 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6B30D1A0172 for ; Tue, 23 Jan 2024 18:35:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgA3Bg+Flq9ly6DjBg--.30161S3; Tue, 23 Jan 2024 18:35:51 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org Cc: tj@kernel.org, hcochran@kernelspring.com, mszeredi@redhat.com, axboe@kernel.dk, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm: enable __wb_calc_thresh to calculate dirty background threshold Date: Wed, 24 Jan 2024 02:33:28 +0800 Message-Id: <20240123183332.876854-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240123183332.876854-1-shikemeng@huaweicloud.com> References: <20240123183332.876854-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgA3Bg+Flq9ly6DjBg--.30161S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZw4rZrWfJr45Gw1rWrWkCrg_yoWrGF47pF W3Xw17CF4UJrZ7ZrsxAFyruFWavws7JFW2q3s7Jw15tw1akryUKr12kF4vyFy5AF93JFy3 AFWYqr97XF1qyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUsWrWDUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 89D1CA000B X-Stat-Signature: a7g1wb6d4xke9mhz6qe7pfsisbxskbjn X-Rspam-User: X-HE-Tag: 1706006156-516708 X-HE-Meta: U2FsdGVkX199yrWuBx0FkI5tx+9GdAefE8BU9IP7gW8TNxQzpVZY1favVv6Xb+QqNKE0il4m48MQP8/a4F7+sRWDN01tNTedOVG3OaovjjBfmBFcECgIuXk4zuVyDW5W4EJapy9zT98LVz0/H2FG3HHDhB7RGaNxE8zpqRK7PGnH7NFLvr3fsW9tcftnNorFXzQrnUmgQpt5tBl+T7sA2bnojhLYFC3yRuTIun2gr5yxI/0DC1HVItuCaAdIDP70irZ+YfuUTTwsPQ7+McR3MTM3sPETHlCCQb/kdQ3eHPgNTj9ZmBxDVTZrjgRevqIaHNshYXWQnGFjYxAZjXy7R18Tg0+82blOX6oujElg5rEPUol3447vv9SnkhqHN9Lx5AMyObxZGGlhM0odlbBvgYZx9s83uZxlz6LTdBahsw3IkxSux+cETlceA+41aoa3wRfyW9DsvXzxCyFSlh4ZaJfNwt/fwbWrV2cQPJzJtZmpJnGvd5chxQcPLOmndTeMIpC5Se3XriNWN+cm4enDvrCstHTXCTnT0gCBNHNCUtusr7rctnsB+n9aopLIb0vz47SlxMs8KOWIwqOYlMW2JauPToL/4Yy95Qk3ozHLIDO+E8UHFlDOoPQ3P2HxVsXfQd3ikta+4lwngUfv0ZWwPYfTI0ml74qCKYUI7LagbffvJRpRiLNCLGkhaw7DCe8VbazIzB4WQdYLHaO7FdCOE7WzhllFjnueXNkgffpvEgK4C1S2K/M+7te+qFT3hr/zO4/ZHGweR0XcUCMSzErexuiO25HEPWrCd8nuMJjk4+4Y6s7trQCGeCxA+SaDDQ68zT8Djxdbk8u2F8/P4Sts/hteAxIcYX5knRxjCBkqAdSQt7GZ9OUF0xrGklUerCnFtqNGampuZZJD1szpNwBEl3nLRM/DlI/laD7liRV7Ilb9vxNKxhzSgUEwZPySKT0bc+JzjE6wy5jRdgelRAe 9XpsD1K+ XguYDKm/wCFgDwI04D99Snq6m/+NoU7pVrBxRoDDem2LApJOsQ8vtrhWJUbzFFFinG9ImXVczxIlZEiuEXWkp4xoKD3/VhIcOayinT+6cbOLpqUng4SpbYR9FjRYGUw1xdSuFbLEEppaOUH9WwbcHanjC0cKdUkbXKYVUWrVA4IqvUjaBTqrQiBh06gASTVMPNwuecG0h+RGqkYz+ez9SCbtM0CIv7QlcRo8uLxHOYqKoxu3Z6DXqbck5s4ghH5UgGxUFUZ4yHM00Bh5qlI6Vc8pRnICwfCu85RsRtA8xrbYo2r4= 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: Originally, __wb_calc_thresh always calculate wb's share of dirty throttling threshold. By getting thresh of wb_domain from caller, __wb_calc_thresh could be used for both dirty throttling and dirty background threshold. This is a preparation to correct threshold calculation of wb in cgroup. Signed-off-by: Kemeng Shi --- mm/page-writeback.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index cd4e4ae77c40..9268859722c4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -838,13 +838,15 @@ static void mdtc_calc_avail(struct dirty_throttle_control *mdtc, } /** - * __wb_calc_thresh - @wb's share of dirty throttling threshold + * __wb_calc_thresh - @wb's share of dirty threshold * @dtc: dirty_throttle_context of interest + * @thresh: dirty throttling or dirty background threshold of wb_domain in @dtc * - * Note that balance_dirty_pages() will only seriously take it as a hard limit - * when sleeping max_pause per page is not enough to keep the dirty pages under - * control. For example, when the device is completely stalled due to some error - * conditions, or when there are 1000 dd tasks writing to a slow 10MB/s USB key. + * Note that balance_dirty_pages() will only seriously take dirty throttling + * threshold as a hard limit when sleeping max_pause per page is not enough + * to keep the dirty pages under control. For example, when the device is + * completely stalled due to some error conditions, or when there are 1000 + * dd tasks writing to a slow 10MB/s USB key. * In the other normal situations, it acts more gently by throttling the tasks * more (rather than completely block them) when the wb dirty pages go high. * @@ -855,19 +857,20 @@ static void mdtc_calc_avail(struct dirty_throttle_control *mdtc, * The wb's share of dirty limit will be adapting to its throughput and * bounded by the bdi->min_ratio and/or bdi->max_ratio parameters, if set. * - * Return: @wb's dirty limit in pages. The term "dirty" in the context of - * dirty balancing includes all PG_dirty and PG_writeback pages. + * Return: @wb's dirty limit in pages. For dirty throttling limit, the term + * "dirty" in the context of dirty balancing includes all PG_dirty and + * PG_writeback pages. */ -static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc) +static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc, + unsigned long thresh) { struct wb_domain *dom = dtc_dom(dtc); - unsigned long thresh = dtc->thresh; u64 wb_thresh; unsigned long numerator, denominator; unsigned long wb_min_ratio, wb_max_ratio; /* - * Calculate this BDI's share of the thresh ratio. + * Calculate this wb's share of the thresh ratio. */ fprop_fraction_percpu(&dom->completions, dtc->wb_completions, &numerator, &denominator); @@ -887,9 +890,9 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc) unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh) { - struct dirty_throttle_control gdtc = { GDTC_INIT(wb), - .thresh = thresh }; - return __wb_calc_thresh(&gdtc); + struct dirty_throttle_control gdtc = { GDTC_INIT(wb) }; + + return __wb_calc_thresh(&gdtc, thresh); } /* @@ -1636,7 +1639,7 @@ static inline void wb_dirty_limits(struct dirty_throttle_control *dtc) * wb_position_ratio() will let the dirtier task progress * at some rate <= (write_bw / 2) for bringing down wb_dirty. */ - dtc->wb_thresh = __wb_calc_thresh(dtc); + dtc->wb_thresh = __wb_calc_thresh(dtc, dtc->thresh); dtc->wb_bg_thresh = dtc->thresh ? div_u64((u64)dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0;