From mboxrd@z Thu Jan 1 00:00:00 1970 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 ECD69C4345F for ; Fri, 3 May 2024 09:31:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DCB16B0089; Fri, 3 May 2024 05:31:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58D356B008C; Fri, 3 May 2024 05:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42D676B0092; Fri, 3 May 2024 05:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 294D96B0089 for ; Fri, 3 May 2024 05:31:05 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CAB25A0FFC for ; Fri, 3 May 2024 09:31:04 +0000 (UTC) X-FDA: 82076565648.14.2CE570E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf11.hostedemail.com (Postfix) with ESMTP id 673644000F for ; Fri, 3 May 2024 09:31:02 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cbzLyPgo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=XgIjjsSu; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cbzLyPgo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=XgIjjsSu; spf=pass (imf11.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714728662; a=rsa-sha256; cv=none; b=yclYg7zJmrEhIhEZ4V+G2imi/5Oix7C6UkxdW7FTfjD3xF22G5qNA+68ymtUYZEOjJDF07 7W4PGs9ggBpc3UhmjgahjVlg47LzJK7sgQfpzP8tD0ebNew32pTHfU8+JHBfQvvbfidTm+ SjKLHJlX4UpMHwRAJMZT1ufCY8yPIhs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cbzLyPgo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=XgIjjsSu; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cbzLyPgo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=XgIjjsSu; spf=pass (imf11.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714728662; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dJxohtrBKRpaNpkwWLIS75cauTsED9rnDxgq1rWa2Lk=; b=OiljnvaRdGl16wSbCfwSpQ27EeboEjHAFuoA70zHNO6lruxLxPWqgHBqSkvU6OW7r4WCDc iBFYfdB0Jm/F6t/AZx+2pXeEl8CBBI8Ij6rRHvvmQp1jnNu3PRPU5Q2G+k0wa0iDORYi/w KDNi0owYoPl/bS66MRKu+5amR05qsjE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AC78E22398; Fri, 3 May 2024 09:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1714728660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dJxohtrBKRpaNpkwWLIS75cauTsED9rnDxgq1rWa2Lk=; b=cbzLyPgotGC1W52Cn5O3pysHF04zQu6T3npjdTiGxIFx/VNjIVy1/ZfE9PUzWRV2Xsz6yF B8l4g+iyjZ27ntIR1TzeO2UWub+XWSdFEI7dbi/j1yrsxVGG2AYcoHxwMfd0exeCfHFFMl H7PPrNQfdZo+qHVct8CYYkDlQkTRct4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1714728660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dJxohtrBKRpaNpkwWLIS75cauTsED9rnDxgq1rWa2Lk=; b=XgIjjsSuyVQISQJwsdTcl1u28ed6TKdUp+FFcAMmIDc2SlN6gGIGDP7CPzQMVAdevr/VYn Yjv0Wom/CuLUB7Cg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1714728660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dJxohtrBKRpaNpkwWLIS75cauTsED9rnDxgq1rWa2Lk=; b=cbzLyPgotGC1W52Cn5O3pysHF04zQu6T3npjdTiGxIFx/VNjIVy1/ZfE9PUzWRV2Xsz6yF B8l4g+iyjZ27ntIR1TzeO2UWub+XWSdFEI7dbi/j1yrsxVGG2AYcoHxwMfd0exeCfHFFMl H7PPrNQfdZo+qHVct8CYYkDlQkTRct4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1714728660; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dJxohtrBKRpaNpkwWLIS75cauTsED9rnDxgq1rWa2Lk=; b=XgIjjsSuyVQISQJwsdTcl1u28ed6TKdUp+FFcAMmIDc2SlN6gGIGDP7CPzQMVAdevr/VYn Yjv0Wom/CuLUB7Cg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9C5E0139CB; Fri, 3 May 2024 09:31:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id Y+LrJdSuNGaDMgAAD6G6ig (envelope-from ); Fri, 03 May 2024 09:31:00 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 41951A0A12; Fri, 3 May 2024 11:30:56 +0200 (CEST) Date: Fri, 3 May 2024 11:30:56 +0200 From: Jan Kara To: Kemeng Shi Cc: willy@infradead.org, akpm@linux-foundation.org, 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: Re: [PATCH v2 2/4] mm: correct calculation of wb's bg_thresh in cgroup domain Message-ID: <20240503093056.6povgn2shvqzpedj@quack3> References: <20240425131724.36778-1-shikemeng@huaweicloud.com> <20240425131724.36778-3-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240425131724.36778-3-shikemeng@huaweicloud.com> X-Stat-Signature: abjdnyouso6k7ois7g3dpg7zeubnd3xz X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 673644000F X-HE-Tag: 1714728662-812543 X-HE-Meta: U2Fs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YvoL2jKqBmtUvnFb15Ya+6BTDEt2Bhm2+XIVu/7G3oYVyJXvrk2+3mWEP01Mj86oxciZuVYm9pRcHp33l1492C/vdUKT4AGa9mkMARpfTsoMK8GYa7uOaiR6RS6mQhas19n96uhIJYXPijE1jRYFuLF2oABQ4Vv0N7v2bu7XMGHr9LLm9HOPAHqNjTBEpTpz7ZQshroETR+W/J2Z1UdsdOo6GwibFhYqmGeYTnW5t5qAjjkjHH6Q9184MyF51tk3lvBPBq2sHzDq4yVpW0lnygJ1gh9+u75P/y4Ol2Qt6lurIV72RTXOr 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: On Thu 25-04-24 21:17:22, Kemeng Shi wrote: > 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. This was a bit hard to understand for me so I'd rephrase it as: wb_calc_thresh() is calculating wb's share of bg_thresh in the global domain. However in case of cgroup writeback this is not the right thing to do. Consider the following domain hierarchy: global domain (> 20G) / \ cgroup1 (10G) cgroup2 (10G) | | bdi wb1 wb2 and assume wb1 and wb2 have the same bandwidth and the background threshold is set at 10%. The bg_thresh of cgroup1 and cgroup2 is going to be 1G. Now because wb_calc_thresh(mdtc->wb, mdtc->bg_thresh) calculates per-wb threshold in the global domain as (wb bandwidth) / (domain bandwidth) it returns bg_thresh for wb1 as 0.5G although it has nobody to compete against in cgroup1. Fix the problem by calculating wb's share of bg_thresh in the cgroup domain. > 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 Besides the changelog rephrasing the change looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > 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 > -- > 2.30.0 > -- Jan Kara SUSE Labs, CR