From patchwork Thu Apr 25 13:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13643333 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 B3389C4345F for ; Thu, 25 Apr 2024 13:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBDA56B0083; Thu, 25 Apr 2024 09:17:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E465C6B008C; Thu, 25 Apr 2024 09:17:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B30146B0089; Thu, 25 Apr 2024 09:17:36 -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 9116C6B0088 for ; Thu, 25 Apr 2024 09:17:36 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 342B781218 for ; Thu, 25 Apr 2024 13:17:36 +0000 (UTC) X-FDA: 82048106112.10.F47B0C0 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 62E2BC001D for ; Thu, 25 Apr 2024 13:17:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1714051054; 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=mfcKiU+ZYDyLKaeFzsTSyvHtn5e+BEoR7aL/xw2NvuU=; b=0iRBGpI4tRKT4a/XCeypN6Tns6A1eOcZyRk6hST4DSPa1iAhsOtsUEFeJGmxTzo0a4ZStx EEUEr8OxIVUg//vAYz0zYl6rMZp6Sgvh7R+OUXR8kY1V3nKvOD2yphaNVSb0z7+cCaS+pa t6rAYpVrBoa9YLw1bHq9YhwIJd2u21I= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1714051054; a=rsa-sha256; cv=none; b=2lLz2dyXsakwnYkFCSkwJSf4QGVCk3EroGer1c98IwdRs5Wjno4FLhxdoyvaROIM8U8Q8k zUijTd50iQ9HxftFZsXZ5oLQ13yeosb1wVFFGkgEolP13+6q9dzjBvXr0WczB1TixNTK2E 8wiBjPnlwYRqWEnovEX1Zn9p+BsNHKQ= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VQGbx1lfHz4f3n6Y for ; Thu, 25 Apr 2024 21:17:17 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 7EFFA1A0EAB for ; Thu, 25 Apr 2024 21:17:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP3 (Coremail) with SMTP id _Ch0CgA3+J_kVypmFDcOKw--.42283S3; Thu, 25 Apr 2024 21:17:26 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org Cc: tj@kernel.org, jack@suse.cz, hcochran@kernelspring.com, axboe@kernel.dk, mszeredi@redhat.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] mm: enable __wb_calc_thresh to calculate dirty background threshold Date: Thu, 25 Apr 2024 21:17:21 +0800 Message-Id: <20240425131724.36778-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240425131724.36778-1-shikemeng@huaweicloud.com> References: <20240425131724.36778-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgA3+J_kVypmFDcOKw--.42283S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZw4rZF1rJryUtr1UCr1kAFb_yoWrAr4fpF W3Xw17CF4UJrZ7ZrsxAFyruFWavws7JrW2qa97Gw1rtwnIkryUKF12kF4vyFy5AF93JFy3 AFWYqryxXF1qyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUzl1vUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 62E2BC001D X-Stat-Signature: oo795k63uz6eq4okcrr6xhty57e6awe7 X-HE-Tag: 1714051050-732170 X-HE-Meta: U2FsdGVkX19/qCjLZhAjY/pIFvjIqF/IKuNknRTjWWe/llafba/arMvTu3c2KT6XThS5EKILv9QZUySWaaeO1eVP+EKP6kqor6YZJFwM7j+f9rDHUAag7hAnHchz0EiOChYOQ4IwvjjfhaApISy5upSvn1GyY99IbG52Wa/GJWK+WlkkN/lzA+pDOYfCfABd5KT12UAgHtAUR6jB7N3ITcwjTr1Fiu6iuRnd9Ye5Sqi4VUMqyf4XhTSIk2zdVfOqCxql8wElbxsCQxkYLaO6j0+AnjW4GOO2NaV/9zzWGy3kTli5h1tyC4YN9isYLJaTFXs7bZRZ4fs9cA09hqRu8Xo0FReIPY6jXmlj7iOjSDoFhiyDCu1dGuLgsvJ8RiTLATeAQpUDXxUNvGtvoJJZABhflBNiXudn7OTHmJEM0oPyH2fSyuH4AwZc4WuPf7040UQr8nLu5PnvjVINJVdV8s0z9ciUOYLyjF6GbcEuMZ0dJXEsu69ILfWc31JtX5Owl6OcRHXZjA0oFHE/yL8gB+QZ4IfWtYdfStK8dCoGZ5+mIQ9TET//YesZ7L1LstrwAAUbGHNY+TOI2avl4kFKjo0IMNA3e4sPs5fdgm8rsUoIRUlfIrbzp+7kxuuPjinBzTz8qGSGf1gnCp41bHTOAZAToFXSYNf6PGYTlXX7hi2al3UmGnHHJty/wa7v7CPfKt4BZXUwZdxbUqonfY1IYcMYqKLeFptqp1ClJUceRwyaaJTeTvyaQ22IC8Hti+x2vsORlrxddW+rMS58bunDZ47nmq7wrVUEVA957qzKTzFJNqTRvkj4Ln4oxnNU1UeMoQR3qAEseiZMGx/3AGt9O5vrOdX3HxZgJcXqOdLa3SNV2YwHzQ0uweRD7Ljois1lupr5/zH/uG+qF7arWbvHMZXNJlmorZ1SXc0B+8gIDaHj7bhKeGH0X3rVRlV5KNPjCl7xyAVkWnLU3i4OaGi J/0lSb1W 8rG3duoehtrRPWyfpkjZeg/F4t/+7GRU6ugjXBg89i/nPoSmGI2gD8sCED6pxqXMfBLDRnORdD7ZiCvCyiJuj2n7x6VVzFA8Z1TFQ5o6rEo8pqMUHEGP5lxl3t6zPioYs8qM3xUAxT90iKfmxrC6CIqwkIUfpsu0kz37Rrz7Q2N56/WO3pfAkI/3s4/qZNytFdjWU9WdIEbvKOWH8EI4LIuZ1+W94OBPEGR/6sTQmNVL0PHs11L3ZTNvq39DbTNQjThoHak9ZdRiS60E= 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 Reviewed-by: Jan Kara --- mm/page-writeback.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index db5769cb12fd..2a3b68aae336 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); } unsigned long cgwb_calc_thresh(struct bdi_writeback *wb) @@ -908,7 +911,7 @@ unsigned long cgwb_calc_thresh(struct bdi_writeback *wb) mdtc_calc_avail(&mdtc, filepages, headroom); domain_dirty_limits(&mdtc); - return __wb_calc_thresh(&mdtc); + return __wb_calc_thresh(&mdtc, mdtc.thresh); } /* @@ -1655,7 +1658,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 ? div64_u64(dtc->wb_thresh * dtc->bg_thresh, dtc->thresh) : 0;