Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1122460lqa; Sun, 28 Apr 2024 20:49:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4vPGnxAS0TmYL1SX7Kz+I+8lD4VzgQhgNhlyLpOiaZDyRijswV6rsgUcckabL5pxgqs6xmwWxmSBR4IEp/VwlUjWUqli+Tr//IOxIYA== X-Google-Smtp-Source: AGHT+IEpwIEnRfys/StN595+sT3G5/AyKxeKoVPp1vtqNOSbCMK9OJAqpEeTSlu7Ba229U2jXAHp X-Received: by 2002:a05:6a20:e609:b0:1af:3715:80c8 with SMTP id my9-20020a056a20e60900b001af371580c8mr6538558pzb.46.1714362560861; Sun, 28 Apr 2024 20:49:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714362560; cv=pass; d=google.com; s=arc-20160816; b=OmdIw6CuJuSv0QWq1X0EFY7dlxvO9OVExttHhwI0JEZlOAoKaXGe9IIqqIJg5Q6Uqb YqS0rgyooYD31461kx3Fyb8MD+SYp6bbrchSAbWCOWtFJJtseuxnIlY8tNaeiX0yxaTF d2KZM2xM6Qym67JstSX/1Ef3mCC+7c9GQzdcq46h8BQzlzuIkmJ0vg4qMRvdOgsuqpo/ J2QUYOaW/WTrLD0K2Wb3cPTwvA2Rgcjq59BPBjaTV0oXuDdpsL4E2VakeAqHpY3GbDnz AAeZ/HRN3iRHgBrFXWnGtWehiOf1LEzynUxgF1mbzznnKMXvQ3IrqFkkPfmiCU0BmBri rROw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=rO5LDF5AfoSXhOyoW81F+0NQZkj1byH1zp8ZmzAyq0c=; fh=JvXjDH40Qny8SV6dd2VRD5pFxo0ZkXWBhEYiilPYRjw=; b=kQYOczPmr0RcIFKGe8Bkcsb/G0HqngcSk60uGLsK6FV1DmguWLmU1H+/w7My3ObNzA K7BqG0p8LZ0Aq8YB2RO9E+Ui7jINIMkO9o/o5bcM4x97kTlpqhcVp7ykHo3hUP3djR6Q O6379blGSNd5aboyS7YaGbrl+qW5A+QU5GcYdIt/hgNGoD4Tiyz1QW1isFuyT1cWDnDp +ItmXvFw5aMURPsAUBHNF7pDGAYVCl4iqMTxYmje0T27M57DuzR1NHAiHmCC3fsIxc25 21/veFEgoRUSuJzy7LLYnAz5zFHrimy2IM1jB4P2YXyL3zoOEFARKOLn2ScxqR+x/Iyx he+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-161709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161709-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k18-20020a170902c41200b001e2ad8cd0d9si17000429plk.504.2024.04.28.20.49.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 20:49:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-161709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161709-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0B7B4B21B98 for ; Mon, 29 Apr 2024 03:48:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24BBA12E74; Mon, 29 Apr 2024 03:47:57 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C52351118D; Mon, 29 Apr 2024 03:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714362476; cv=none; b=PeoTZrpXqU4k0Hxb2shhNjjcErdjbn59Yt7EZ/wJbeD3iWhDqMxDmzO+H2viAphWZkzKX//bAWdCQDO2eSLwBVViQrEike7O0En18smKLp1IqB8xjwxEt1WwydoTYxB7N5CMLzs/th4eYsx01yPlFYOPfKlxFSPPXDyWRBNvog4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714362476; c=relaxed/simple; bh=s+npPNcWKMeZEYom4cv+3hbdgohXqkg2iyExANnuyDo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZcLuXAzacza98H1a5TH+PZxszNtVVYcvRv1da64kXHhMbTpUk3bxjsyj06Y5nQTFJHhkKxnd/FzePwHriSDcbxdF5UABhZy1ivVMhD5UGDmR5GLZtcgETyXr5fYwm4RQCHLsN+J3gMZ8nQvQf/DMoVGiYNiMQrJK973Jzeuqz6M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VSTmr6CdBz4f3jkS; Mon, 29 Apr 2024 11:47:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id DB60D1A0568; Mon, 29 Apr 2024 11:47:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP1 (Coremail) with SMTP id cCh0CgA3UwxgGC9m24__LA--.38879S2; Mon, 29 Apr 2024 11:47:45 +0800 (CST) From: Kemeng Shi To: willy@infradead.org, akpm@linux-foundation.org, jack@suse.cz, tj@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 00/10] Add helper functions to remove repeated code and Date: Mon, 29 Apr 2024 11:47:28 +0800 Message-Id: <20240429034738.138609-1-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgA3UwxgGC9m24__LA--.38879S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Zw18WF1rGF4kJF47AF1rCrg_yoW8tFW7pF Z3Kr1aqr1UJ3W3Ar9xCay29ryS9397AF45t3sxXw4SvF43Cry2gFy2vFyFkay2yFy3Gry5 ZFs8t34xGr1qkaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgKb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCj c4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4 CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1x MIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJV Cq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBI daVFxhVjvjDU0xZFpf9x07UWE__UUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ 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 1.5G, the wb is in freerun state and dirty pages is written back when dirty inode is expired after 30 seconds. When fio size is 2G, the dirty pages keep being written back. When fio size is 3G, the dirty pages keep being written back and bandwidth of fio is reduce to 0 occasionally. It's more easy to observe the dirty limitation by set /proc/sys/vm/dirty_ratio to a higher value, and set /proc/sys/vm/dirty_ratio back to 20 when 3G pages are dirtied. Kemeng Shi (10): 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 use [global/wb]_domain_dirty_avail helper in cgwb_calc_thresh writeback: call domain_dirty_avail in balance_dirty_pages 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 | 324 ++++++++++++++++++++++++-------------------- 1 file changed, 176 insertions(+), 148 deletions(-) -- 2.30.0