From patchwork Thu Apr 25 13:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13643331 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 BF854C4345F for ; Thu, 25 Apr 2024 13:17:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B3B96B0082; Thu, 25 Apr 2024 09:17:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 566C26B0088; 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 2F2A76B0083; Thu, 25 Apr 2024 09:17:36 -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 E6D856B0082 for ; Thu, 25 Apr 2024 09:17:35 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5516BA11BE for ; Thu, 25 Apr 2024 13:17:35 +0000 (UTC) X-FDA: 82048106070.19.ED6D5F5 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf21.hostedemail.com (Postfix) with ESMTP id 83D581C0022 for ; Thu, 25 Apr 2024 13:17:31 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) 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=1714051053; 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=14b37KrNa7X9q1mbbLcgXNBGbcEuQbMP6LfxnICbkfo=; b=Jwu0Yqhd4YFZxpyA6mIUh56qVM97ssACasqQeOIJ61eCyoyhXAt7dN1urL0+aVenD3JlKe w+92ZFVAm27ktWOi3+ujHbzn5TyMuxIkyNHqsXOJdIuu5sy1EN9DZPAPjrU5Wylx95ZWJL lBA+BCdAKiW9Mh/XMJYCb1Av+FmMxDw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714051053; a=rsa-sha256; cv=none; b=nN4prxhwlhuo9vMpeE7xhEDytyKQvdI0chB1UusDzQwjt7GUrI7E6FMxqiKDlNQZ9HJbB1 +lR4XvRfmCPJideljVCxP5ym9knIpwpmXPXldIA+APH1q01TwQ1SopcK7OSH0bmV2Fh/NS HG9zL2squYOsleQkZ70Lb3Ss45dvwZI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) 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 4VQGbz2VSqz4f3khc for ; Thu, 25 Apr 2024 21:17:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id E7BF01A0568 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--.42283S4; 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 2/4] mm: correct calculation of wb's bg_thresh in cgroup domain Date: Thu, 25 Apr 2024 21:17:22 +0800 Message-Id: <20240425131724.36778-3-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--.42283S4 X-Coremail-Antispam: 1UD129KBjvJXoWxZFy5Zr13Wry7tF1DXw4kCrg_yoW5Gw13pF WkGr1jvr4UJF1xtrsxKa4qgryfta1rtFW7XFZxJw17tw13Gr18Kr17CFWqgFW8AF13J345 ZFs8C397Xr1Dtw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUXw A2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU2GYLDUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 83D581C0022 X-Stat-Signature: jh1x643tfdegtoyjo5uqpj838fd1xnow X-Rspam-User: X-HE-Tag: 1714051051-134215 X-HE-Meta: U2FsdGVkX18h1DC7ER55ZXUgc3vreMs3+rlTEvAO+rzb6HQInL16plawv9OJ4E2R09UUdUN/TpV3dGxn31GaLXjvOm8rBVi9LGACqGKIXg/PiNllSy37KQFsiMMzUCAmPJKFtys623/QwpUh0JEULzjgZVXfUF++rGDny5fNBrUjyWdGu/8sRCtJn7ANgp2D1Keh70ZxAa5n+wSFT1zbsWV0/h/Be0xzN11MuPDpImbWOD02dvJB/B/xATbX8AXsXJMe0J+MwqqaRaSyJs8szTfi7flZiI1drtwfFHdAzXm7nStjoptlnLOZjuhhV8OZGRxXrZOSwoo9tqxdVDp5KvQNlZ9X6uzAnl/oftzNf6L/M2IFNApNboT42AVliOsnwcnt2oSt6UwWKvZajsqvUTJtrd8Q/07YtrwbadLxFnVlY2EO6sCPP/c3spKvaKZE2K57B6Io8gkzYFUJx4IVh+3kyfAJ6iYrYCflU2YOnMqu58d5bI9YwPuOOdVm5GktI47N/NniNNAokmna2dwbluOb9rfONsHNcinmVJDQEkmBPWbQVR1yj9K/qa+ynx1fJhQB4+CG1m7vjW1S4uRRL24utrf1sU/aZ25q5dtsG/WCa54UJQpejgzu4GgaItOcbJjxq/kptV4K1UJjiwyitNjGLrrdkuQNfMmAhiSleVi+o5m/V/4B6jWJMEexUIEYWwdvM9OsM12xBrDDTgliUsyv+vhupeZjAXzWoeh9dpDJzo2V9/9JKZqEt+GmSX22AuSjrkJCl1mK2mce8XHkMZxESV+Yau91j5jgKSfzg0q7bqxPoAKwqnV+rnIE+bFAXH9tkF8roiyeB36fGPBTgtX7HRmQfFNzMO47BdRvHUiKrkAKTTlIw0Aw0KqnQVfblcHUgbVQwZAdpdjh7uZktLqgLNpzVYELB++o5VkRAXh/HBtcicJw2ymrKlonZ4cZnzKlef1BAt4= 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: The wb_calc_thresh is supposed to calculate wb's share of bg_thresh in global domain. To calculate wb's share of bg_thresh in cgroup domain, it's more reasonable to use __wb_calc_thresh in which way we calculate dirty_thresh in cgroup domain in balance_dirty_pages(). Consider following domain hierarchy: global domain (> 20G) / \ cgroup domain1(10G) cgroup domain2(10G) | | bdi wb1 wb2 Assume wb1 and wb2 has the same bandwidth. We have global domain bg_thresh > 2G, cgroup domain bg_thresh 1G. Then we have: wb's thresh in global domain = 2G * (wb bandwidth) / (system bandwidth) = 2G * 1/2 = 1G wb's thresh in cgroup domain = 1G * (wb bandwidth) / (system bandwidth) = 1G * 1/2 = 0.5G At last, wb1 and wb2 will be limited at 0.5G, the system will be limited at 1G which is less than global domain bg_thresh 2G. Test as following: /* make it easier to observe the issue */ echo 300000 > /proc/sys/vm/dirty_expire_centisecs echo 100 > /proc/sys/vm/dirty_writeback_centisecs /* run fio in wb1 */ cd /sys/fs/cgroup echo "+memory +io" > cgroup.subtree_control mkdir group1 cd group1 echo 10G > memory.high echo 10G > memory.max echo $$ > cgroup.procs mkfs.ext4 -F /dev/vdb mount /dev/vdb /bdi1/ fio -name test -filename=/bdi1/file -size=600M -ioengine=libaio -bs=4K \ -iodepth=1 -rw=write -direct=0 --time_based -runtime=600 -invalidate=0 /* run fio in wb2 with a new shell */ cd /sys/fs/cgroup mkdir group2 cd group2 echo 10G > memory.high echo 10G > memory.max echo $$ > cgroup.procs mkfs.ext4 -F /dev/vdc mount /dev/vdc /bdi2/ fio -name test -filename=/bdi2/file -size=600M -ioengine=libaio -bs=4K \ -iodepth=1 -rw=write -direct=0 --time_based -runtime=600 -invalidate=0 Before fix, the wrttien pages of wb1 and wb2 reported from toos/writeback/wb_monitor.py keep growing. After fix, rare written pages are accumulated. There is no obvious change in fio result. Fixes: 74d369443325 ("writeback: Fix performance regression in wb_over_bg_thresh()") Signed-off-by: Kemeng Shi Reviewed-by: Jan Kara --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2a3b68aae336..14893b20d38c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2137,7 +2137,7 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb) if (mdtc->dirty > mdtc->bg_thresh) return true; - thresh = wb_calc_thresh(mdtc->wb, mdtc->bg_thresh); + thresh = __wb_calc_thresh(mdtc, mdtc->bg_thresh); if (thresh < 2 * wb_stat_error()) reclaimable = wb_stat_sum(wb, WB_RECLAIMABLE); else