From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (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 BD8182877F4 for ; Tue, 14 Oct 2025 12:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760443871; cv=none; b=MWl6fS22IPPGTnnzEqcuLJx9e/bmWKG6Bq8dAVZha+QsliGcy8rNkgcx+snkvNqNjWlVQRnmUEag+gM1/Uk7EFUSxB/8mJ1I+FRpZOLs0GiAEqUFtxQhNVTla6nFQELA2M8nC7HdpAGfvGGLy0e5//cWaHLx39HENhb5vqiDJj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760443871; c=relaxed/simple; bh=ApCzPWuqEIv8w5oR0HLgtv4+D/wwTnZTqBn4R3B/HRU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=TqJrUaLvSy4mhQ2rJ08St9vpCyHuIEKk69RNWJiMMn9WNNLrGLRN6CJS5nB9pRLEZflLhI+a7yDGvDxttF/Jfut1ZEPu/UEEu78HMK3HcaiKkf0hv8opnpAGvijGIeRE8QTAlIPyLeAFURA8ipPHaJTOL2mvk+cjT9tzpXCxilU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=b3MP2PPQ; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="b3MP2PPQ" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251014121059epoutp027eae57729ff4138b2f835a1c1e3b672a~uWlzWFcsF2398023980epoutp02b for ; Tue, 14 Oct 2025 12:10:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251014121059epoutp027eae57729ff4138b2f835a1c1e3b672a~uWlzWFcsF2398023980epoutp02b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1760443859; bh=gsFsMIu+qmP5Pk/U6/E+nZJ61/APVl3sjNSY2NmttmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b3MP2PPQADA0hrQOZsvNMk5IqyvoGROiAsnT/N0hTNdssHWHiaozpoXzdpcNl/4nY aK//QNWUQ2GADLe9sOhTiSothJkAzC/Y6IHX6jQBZo5oxpejhWhMkIHsNmMlyxWPl7 hV5ajXmyC+3hwqX4nk9gxZZfX2spne9pdDHx46dM= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251014121058epcas5p4efc8532b88fe6f0919db6df3984eaab5~uWlyadOAm1326113261epcas5p4x; Tue, 14 Oct 2025 12:10:58 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.90]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cmCjY1B5gz6B9m6; Tue, 14 Oct 2025 12:10:57 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20251014121056epcas5p1cd2a7fde9f54633b5a331f4553f88735~uWlw9E8x81946619466epcas5p12; Tue, 14 Oct 2025 12:10:56 +0000 (GMT) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251014121048epsmtip19b929dbb834131481e70a8aeb346f9bb~uWlpts_jW1309013090epsmtip1H; Tue, 14 Oct 2025 12:10:48 +0000 (GMT) From: Kundan Kumar To: jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, miklos@szeredi.hu, agruenba@redhat.com, trondmy@kernel.org, anna@kernel.org, akpm@linux-foundation.org, willy@infradead.org, mcgrof@kernel.org, clm@meta.com, david@fromorbit.com, amir73il@gmail.com, axboe@kernel.dk, hch@lst.de, ritesh.list@gmail.com, djwong@kernel.org, dave@stgolabs.net, wangyufei@vivo.com Cc: linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev, linux-nfs@vger.kernel.org, linux-mm@kvack.org, gost.dev@samsung.com, kundan.kumar@samsung.com, anuj20.g@samsung.com, vishak.g@samsung.com, joshi.k@samsung.com Subject: [PATCH v2 08/16] writeback: add support to collect stats for all writeback ctxs Date: Tue, 14 Oct 2025 17:38:37 +0530 Message-Id: <20251014120845.2361-9-kundan.kumar@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251014120845.2361-1-kundan.kumar@samsung.com> Precedence: bulk X-Mailing-List: gfs2@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMS-MailID: 20251014121056epcas5p1cd2a7fde9f54633b5a331f4553f88735 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20251014121056epcas5p1cd2a7fde9f54633b5a331f4553f88735 References: <20251014120845.2361-1-kundan.kumar@samsung.com> Modified stats collection to collect stats for all the writeback contexts within a bdi. Signed-off-by: Kundan Kumar Signed-off-by: Anuj Gupta --- mm/backing-dev.c | 72 ++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 754f2f6c6d7c..0a772d984ecf 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -50,6 +50,7 @@ struct wb_stats { unsigned long nr_written; unsigned long dirty_thresh; unsigned long wb_thresh; + unsigned long state; }; static struct dentry *bdi_debug_root; @@ -81,6 +82,7 @@ static void collect_wb_stats(struct wb_stats *stats, stats->nr_dirtied += wb_stat(wb, WB_DIRTIED); stats->nr_written += wb_stat(wb, WB_WRITTEN); stats->wb_thresh += wb_calc_thresh(wb, stats->dirty_thresh); + stats->state |= wb->state; } #ifdef CONFIG_CGROUP_WRITEBACK @@ -89,22 +91,27 @@ static void bdi_collect_stats(struct backing_dev_info *bdi, struct wb_stats *stats) { struct bdi_writeback *wb; + struct bdi_writeback_ctx *bdi_wb_ctx; rcu_read_lock(); - list_for_each_entry_rcu(wb, &bdi->wb_ctx[0]->wb_list, bdi_node) { - if (!wb_tryget(wb)) - continue; + for_each_bdi_wb_ctx(bdi, bdi_wb_ctx) + list_for_each_entry_rcu(wb, &bdi_wb_ctx->wb_list, bdi_node) { + if (!wb_tryget(wb)) + continue; - collect_wb_stats(stats, wb); - wb_put(wb); - } + collect_wb_stats(stats, wb); + wb_put(wb); + } rcu_read_unlock(); } #else static void bdi_collect_stats(struct backing_dev_info *bdi, struct wb_stats *stats) { - collect_wb_stats(stats, &bdi->wb_ctx[0]->wb); + struct bdi_writeback_ctx *bdi_wb_ctx; + + for_each_bdi_wb_ctx(bdi, bdi_wb_ctx) + collect_wb_stats(stats, &bdi_wb_ctx->wb); } #endif @@ -150,7 +157,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v) stats.nr_io, stats.nr_more_io, stats.nr_dirty_time, - !list_empty(&bdi->bdi_list), bdi->wb_ctx[0]->wb.state); + !list_empty(&bdi->bdi_list), stats.state); return 0; } @@ -195,35 +202,40 @@ static int cgwb_debug_stats_show(struct seq_file *m, void *v) { struct backing_dev_info *bdi = m->private; struct bdi_writeback *wb; + struct bdi_writeback_ctx *bdi_wb_ctx; unsigned long background_thresh; unsigned long dirty_thresh; + struct wb_stats stats; global_dirty_limits(&background_thresh, &dirty_thresh); + stats.dirty_thresh = dirty_thresh; rcu_read_lock(); - list_for_each_entry_rcu(wb, &bdi->wb_ctx[0]->wb_list, bdi_node) { - struct wb_stats stats = { .dirty_thresh = dirty_thresh }; - - if (!wb_tryget(wb)) - continue; - - collect_wb_stats(&stats, wb); - - /* - * Calculate thresh of wb in writeback cgroup which is min of - * thresh in global domain and thresh in cgroup domain. Drop - * rcu lock because cgwb_calc_thresh may sleep in - * cgroup_rstat_flush. 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(); + for_each_bdi_wb_ctx(bdi, bdi_wb_ctx) { + list_for_each_entry_rcu(wb, &bdi_wb_ctx->wb_list, bdi_node) { + if (!wb_tryget(wb)) + continue; + + collect_wb_stats(&stats, wb); + + /* + * Calculate thresh of wb in writeback cgroup which is + * min of thresh in global domain and thresh in cgroup + * domain. Drop rcu lock because cgwb_calc_thresh may + * sleep in cgroup_rstat_flush. 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); } - - wb_stats_show(m, wb, &stats); - - wb_put(wb); } rcu_read_unlock(); -- 2.25.1