From patchwork Tue May 14 12:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13664068 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 36EE7C04FFE for ; Tue, 14 May 2024 12:53:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 353366B031D; Tue, 14 May 2024 08:53:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB5BA6B0322; 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 90A196B027C; 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 E95E66B031B for ; Tue, 14 May 2024 08:53:36 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7E2B1141276 for ; Tue, 14 May 2024 12:53:36 +0000 (UTC) X-FDA: 82116992832.19.BF612DA Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf07.hostedemail.com (Postfix) with ESMTP id 89B2740007 for ; Tue, 14 May 2024 12:53:33 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=none (imf07.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=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:references; bh=Ek+i2cWZY2PyWmUdLEbKR8x4fHRa9QTyKOgOriMn11k=; b=Hwtf7vlU7Kxtq5E/q29A09oqDAzie09+d5vc4Gn5JQGRNYOF90ceiHSnnX4uiwzKaYu4+7 OTrpFRPTZ0/uotk6r+F6tOhdIHe8klySILwNreR3s0cowwXxB3XiCEvLaFFIarc3xBbRIA n/ENTYkKGHeN2ZGV1nUstJGKUteoB6s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715691215; a=rsa-sha256; cv=none; b=VoxGdLNMqUx8177e9DQ6ij4DvLxA3kv1IyObzHGlIv+twE9XBgbxUICe9dMvMCTbOwUl4w ZXONiD0l7klwz060m5I63MVCYTkk8fBam5Y0b+J29+ZBTBXa5gY2poha72SDVxoYCQLtl6 mM9mFVDsZp1MZBGlKf2UZJ+1im2yVCw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=none; spf=none (imf07.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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vdx9X3wR3z4f3kKj 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 163591A016E 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--.6596S2; Tue, 14 May 2024 20:53:25 +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 0/8] Add helper functions to remove repeated code and improve readability of cgroup writeback Date: Tue, 14 May 2024 20:52:46 +0800 Message-Id: <20240514125254.142203-1-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDHzG7EXkNmCyyLMw--.6596S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tr1DuF48Gw1ktry3Jr4ktFb_yoW8ur4DpF Z3Kr1aqr4UJFnxAr9xCay29rySyrZ3JF15t3sxuw4avF4akr12ga42vFyFkFW7AFy3GryY vF4qy34xGF1qkaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgKb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Y z7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zV AF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4l IxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s 0DMIIF0xvEx4A2jsIE14v26r4j6F4UMII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cvbBgVeSTGEhx3Mv+zhRB81hROXrhnyY1Tl6g62W3/YHJG2gF6IdWeI+e3EZSP7oLaKG4ZJrYSB++yVcpa1nLYDKaApwKZC+z74DoXMarxQbmbhN0bwYuICCA9d6tjvUA+3zFgoLjhTGBGxW bI0zuCum xrbaGWXqWwEV1EQwuX7N/wWv3QMrEZEBJBKuWJmz+s0w8FYXqTfvdjw3e8itT71/r7Q0Jakk5JGAW6e8s1K7L01ywTOpG1DdLvmbV3vmdd8dBw0QamPhaLep+dA== 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: v1->v2: -add dtc_is_global() helper -rename "bool bg" to "include_writeback" -fold patches using domain_dirty_avail -reflow comment to 80col -Fix potential NULL deref of mdtc->dirty_exceeded This series add a lot of helpers to remove repeated code between domain and wb; dirty limit and dirty background; global domain and wb domain. The helpers also improve readability. More details can be found on respective patches. Thanks. A simple domain hierarchy is tested: global domain (> 20G) | cgroup domain1(10G) | wb1 | fio Test steps: /* make it easy to observe */ echo 300000 > /proc/sys/vm/dirty_expire_centisecs echo 3000 > /proc/sys/vm/dirty_writeback_centisecs /* create cgroup domain */ 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/ /* run fio to generate dirty pages */ fio -name test -filename=/bdi1/file -size=xxx -ioengine=libaio -bs=4K \ -iodepth=1 -rw=write -direct=0 --time_based -runtime=600 -invalidate=0 When fio size is 1G, the wb is in freerun state and dirty pages are only written back when dirty inode is expired after 30 seconds. When fio size is 2G, the dirty pages keep being written back and bandwidth of fio is limited. Kemeng Shi (8): writeback: factor out wb_bg_dirty_limits to remove repeated code writeback: add general function domain_dirty_avail to calculate dirty and avail of domain writeback: factor out domain_over_bg_thresh to remove repeated code writeback: Factor out code of freerun to remove repeated code writeback: factor out wb_dirty_freerun to remove more repeated freerun code writeback: factor out balance_domain_limits to remove repeated code writeback: factor out wb_dirty_exceeded to remove repeated code writeback: factor out balance_wb_limits to remove repeated code mm/page-writeback.c | 315 ++++++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 146 deletions(-)