Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp667487lqe; Sat, 6 Apr 2024 20:14:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9e9pmOdDlV6XsW1wl5F2fNjW28BkhQCPTOyCqyC/Phx7bf7St97uzsqYLuPOQbeubeSXh4ChXh2TMA2sB/CKrcaYYv90sHlrZF+84ig== X-Google-Smtp-Source: AGHT+IHO5u3T1y7B6AMLNL6tfCI+DYqn3/QBi5bb+g8K6Q95GIHBfA5772m/2Z6AV9eayyf36JwU X-Received: by 2002:a05:6a21:7888:b0:1a5:6e14:369 with SMTP id bf8-20020a056a21788800b001a56e140369mr6831670pzc.6.1712459642203; Sat, 06 Apr 2024 20:14:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712459642; cv=pass; d=google.com; s=arc-20160816; b=jSXMYI1OLUvoUHfMoOeRBQir4rm99oflDNnyllSu1WQfCCYkSlx8ql3d1YHErk+4AM 8gE/rh0JbMpYAbJjccz2wtBhmpoyAdLiJaK++XMB8MoOpqDGRsHRu5k348zqQK6xstoA 3ioL60b+KiY8fbor3ZyiRSsBQLgttaoI49hNTmX23j/SshvxnMqWqFtVEOJvcEUxGgHN hwcXCp6nWal34YynHaNto7DoMctE2W0GD6l9UOPuLRC3LGWwlC0ZV67ULi2gv++LF1r6 osk8/cUuEBPtsRKlDu2eV7U8kVhToGIfjkmD5GjtljsZSsnUzFgZFigLXMNG86d7r303 osPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=JNOAAdXcqa69QXt8pnHQv05QpznFEg3kuYNfz+UmDVU=; fh=IH1s1Ytpa52ukUPR7hoiC0QZGOdbVI9Fwa0qaH1u6NM=; b=i4RCD8L2ukOTqQFxzY+ZEatM+jNCX/s9bJ1DIFxEpH/VhiAs2WVRXUQu146pW+H7Ip 9OprDvLVrvcrX8MHnyLm3kskA2UoVmXOqzdDGDxgdSGl0phv20gXC2sgcG/F093rqiIi C4Wv0Iph4SRubEYCyzEgXCtvU7Xva8hycW0QUDHiqcxg7bYhw7+eMHhpyJ1hXJRkn6pH s/932oaYqJri5jGozzTzlATm+Vveo5IMNoMhZaiEEc3X+lY57WwYQKPrkogaG5h5NhGN FBWENnTaY7SQheCyo6Nviip0d1hnhnSg649bLHdVLDATz5J2rdH1ZIwmGMB1t5xEcNqz TIKw==; 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-134144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134144-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u2-20020a170902b28200b001e27aaa8bedsi3848622plr.628.2024.04.06.20.14.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 20:14:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-134144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134144-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 29A222827A9 for ; Sun, 7 Apr 2024 03:13:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03A2A111AA; Sun, 7 Apr 2024 03:13:50 +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 6AD6F10A0A; Sun, 7 Apr 2024 03:13:46 +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=1712459629; cv=none; b=NYoMrM+WiFNgNPq8sMAUOPbxopKIQSKODY8v8jK0UbPe2zXUguUdIocdLllZnO+oMEXIMZrs9DQ0xDTDRG3C2vTMOrbb3yS9A+U5mFIBZDBURwLaNbhfP2JcBzo8hvC3c26T3eoUwoRCh2xZ0ghv7kH3I5i/GEeRFtxpfvC39gU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712459629; c=relaxed/simple; bh=yJe8X8J68cHa2gvIMU5bJdS9Gcj3O1sw/lxHUWoIo+g=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=OepkQlXiNTT9iz+G/olJYF7BkgBGhJsef9vIFXKCofjYuz5QttdF7ltBauoUtRhWn5t3PrhIaJfVuQepXyWDAHD2KFL3vI7OzCnNSpRpKtJSGgMCDDAc8Uu/hYRj+w/sO5mLZXzAiEMpINMuVU0Q5ViaHxZ+eYAnv/2fWvkiu54= 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 4VBy3f3Gxbz4f3lgF; Sun, 7 Apr 2024 11:13:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id F07051A0568; Sun, 7 Apr 2024 11:13:42 +0800 (CST) Received: from [10.174.178.129] (unknown [10.174.178.129]) by APP1 (Coremail) with SMTP id cCh0CgAnRQ5lDxJmd0M4JQ--.28098S2; Sun, 07 Apr 2024 11:13:42 +0800 (CST) Subject: Re: [PATCH v2 3/6] writeback: support retrieving per group debug writeback stats of bdi To: Jan Kara , Brian Foster Cc: akpm@linux-foundation.org, willy@infradead.org, tj@kernel.org, dsterba@suse.com, mjguzik@gmail.com, dhowells@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org References: <20240327155751.3536-1-shikemeng@huaweicloud.com> <20240327155751.3536-4-shikemeng@huaweicloud.com> <20240404090753.q3iugmqeeqig64db@quack3> From: Kemeng Shi Message-ID: <6bf2280d-bce1-c1c5-3b25-8cfc7e1fa81d@huaweicloud.com> Date: Sun, 7 Apr 2024 11:13:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240404090753.q3iugmqeeqig64db@quack3> Content-Type: text/plain; charset=gbk Content-Transfer-Encoding: 7bit X-CM-TRANSID:cCh0CgAnRQ5lDxJmd0M4JQ--.28098S2 X-Coremail-Antispam: 1UD129KBjvJXoWxKw1xCF48ZF1rKw4Duw43trb_yoW7AryUp3 Wqg3W7Kr4DXw1IkwnFv34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foster wrote: >> On Wed, Apr 03, 2024 at 04:49:42PM +0800, Kemeng Shi wrote: >>> on 3/29/2024 9:10 PM, Brian Foster wrote: >>>> On Wed, Mar 27, 2024 at 11:57:48PM +0800, Kemeng Shi wrote: >>>>> + collect_wb_stats(&stats, wb); >>>>> + >>>> >>>> Also, similar question as before on whether you'd want to check >>>> WB_registered or something here.. >>> Still prefer to keep full debug info and user could filter out on >>> demand. >> >> Ok. I was more wondering if that was needed for correctness. If not, >> then that seems fair enough to me. >> >>>>> + if (mem_cgroup_wb_domain(wb) == NULL) { >>>>> + wb_stats_show(m, wb, &stats); >>>>> + continue; >>>>> + } >>>> >>>> Can you explain what this logic is about? Is the cgwb_calc_thresh() >>>> thing not needed in this case? A comment might help for those less >>>> familiar with the implementation details. >>> If mem_cgroup_wb_domain(wb) is NULL, then it's bdi->wb, otherwise, >>> it's wb in cgroup. For bdi->wb, there is no need to do wb_tryget >>> and cgwb_calc_thresh. Will add some comment in next version. >>>> >>>> BTW, I'm also wondering if something like the following is correct >>>> and/or roughly equivalent: >>>> >>>> list_for_each_*(wb, ...) { >>>> struct wb_stats stats = ...; >>>> >>>> if (!wb_tryget(wb)) >>>> continue; >>>> >>>> collect_wb_stats(&stats, wb); >>>> >>>> /* >>>> * Extra wb_thresh magic. Drop rcu lock because ... . We >>>> * can do so here because we have a ref. >>>> */ >>>> if (mem_cgroup_wb_domain(wb)) { >>>> rcu_read_unlock(); >>>> stats.wb_thresh = min(stats.wb_thresh, cgwb_calc_thresh(wb)); >>>> rcu_read_lock(); >>>> } >>>> >>>> wb_stats_show(m, wb, &stats) >>>> wb_put(wb); >>>> } >>> It's correct as wb_tryget to bdi->wb has no harm. I have considered >>> to do it in this way, I change my mind to do it in new way for >>> two reason: >>> 1. Put code handling wb in cgroup more tight which could be easier >>> to maintain. >>> 2. Rmove extra wb_tryget/wb_put for wb in bdi. >>> Would this make sense to you? >> >> Ok, well assuming it is correct the above logic is a bit more simple and >> readable to me. I think you'd just need to fill in the comment around >> the wb_thresh thing rather than i.e. having to explain we don't need to >> ref bdi->wb even though it doesn't seem to matter. >> >> I kind of feel the same on the wb_stats file thing below just because it >> seems more consistent and available if wb_stats eventually grows more >> wb-specific data. >> >> That said, this is subjective and not hugely important so I don't insist >> on either point. Maybe wait a bit and see if Jan or Tejun or somebody >> has any thoughts..? If nobody else expresses explicit preference then >> I'm good with it either way. > > No strong opinion from me really. > >>>>> +static void cgwb_debug_register(struct backing_dev_info *bdi) >>>>> +{ >>>>> + debugfs_create_file("wb_stats", 0444, bdi->debug_dir, bdi, >>>>> + &cgwb_debug_stats_fops); >>>>> +} >>>>> + >>>>> static void bdi_collect_stats(struct backing_dev_info *bdi, >>>>> struct wb_stats *stats) >>>>> { >>>>> @@ -117,6 +202,8 @@ static void bdi_collect_stats(struct backing_dev_info *bdi, >>>>> { >>>>> collect_wb_stats(stats, &bdi->wb); >>>>> } >>>>> + >>>>> +static inline void cgwb_debug_register(struct backing_dev_info *bdi) { } >>>> >>>> Could we just create the wb_stats file regardless of whether cgwb is >>>> enabled? Obviously theres only one wb in the !CGWB case and it's >>>> somewhat duplicative with the bdi stats file, but that seems harmless if >>>> the same code can be reused..? Maybe there's also a small argument for >>>> dropping the state info from the bdi stats file and moving it to >>>> wb_stats.In backing-dev.c, there are a lot "#ifdef CGWB .. #else .. #endif" to >>> avoid unneed extra cost when CGWB is not enabled. >>> I think it's better to avoid extra cost from wb_stats when CGWB is not >>> enabled. For now, we only save cpu cost to create and destroy wb_stats >>> and save memory cost to record debugfs file, we could save more in >>> future when wb_stats records more debug info. > > Well, there's the other side that you don't have to think whether the > kernel has CGWB enabled or not when asking a customer to gather the > writeback debug info - you can always ask for wb_stats. Also if you move > the wb->state to wb_stats only it will become inaccessible with CGWB > disabled. So I agree with Brian that it is better to provide wb_stats also > with CGWB disabled (and we can just implement wb_stats for !CGWB case with > the same function as bdi_stats). > > That being said all production kernels I have seen do have CGWB enabled so > I don't care that much about this... It's acceptable to me if the extra cost is tolerable. > >>> Move state info from bdi stats to wb_stats make senses to me. The only >>> concern would be compatibility problem. I will add a new patch to this >>> to make this more noticeable and easier to revert. > > Yeah, I don't think we care much about debugfs compatibility but I think > removing state from bdi_stats is not worth the inconsistency between > wb_stats and bdi_stats in the !CGWB case. OK, I will simply keep wb_stats even CGWB is not enabled while keep state in both bdi_stats and wb_stats if Braian doesn't against in recent dasy. Kemeng > > Honza >