From patchwork Mon Apr 22 16:05:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13637732 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 BF67AC04FF6 for ; Mon, 22 Apr 2024 07:10:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 103636B009E; Mon, 22 Apr 2024 03:10:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F33B96B00A0; Mon, 22 Apr 2024 03:10:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFA406B009E; Mon, 22 Apr 2024 03:10:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9DD766B009D for ; Mon, 22 Apr 2024 03:10:22 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 54C2A1A0AC8 for ; Mon, 22 Apr 2024 07:10:22 +0000 (UTC) X-FDA: 82036294284.15.D898577 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id 270DA100007 for ; Mon, 22 Apr 2024 07:10:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713769820; 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:in-reply-to:references:references; bh=+CfwWr6c0peMCx7OD2HGSsGpRnFxzf4wkYBoyN5xUX4=; b=lWY5dhow6pG/tuPxxg2kVUbX3wt9SFsgBCN281RmWvGTOIrs2Ya4oIsJ0U9y15KbwWu1Jw 6l9kJ2D7u9AwlGa0ofDAZFhIL37zSTLALRbr22S/SHRcobZWr5ye/sFxB5/Toc8kJo62e+ a6OknzwBluyO+eVUU9P9k3bNAAKPN20= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf05.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713769820; a=rsa-sha256; cv=none; b=0c7gPCBr0VdmnoQ2Y6djmRJ9PfL9FXnSB6NCnXFYQaML5WC2enmJdjXaJybcn8POsE6Nbh CAlCKdv1OO6prnCAjIHZVdUJxkbY3Pzp9h2WA3hWWqHS7avPcIPcXUwep7gqI8yDVHVcrz enuBLq6Y8rmawOp4MNr9cNQU5QdVhPM= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VNGbc6vNsz4f3m7J for ; Mon, 22 Apr 2024 15:10:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 1855D1A148B for ; Mon, 22 Apr 2024 15:10:14 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP2 (Coremail) with SMTP id Syh0CgAHdwpTDSZmt5eIKw--.7343S3; Mon, 22 Apr 2024 15:10:13 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, willy@infradead.org, jack@suse.cz, bfoster@redhat.com, tj@kernel.org Cc: dsterba@suse.com, mjguzik@gmail.com, dhowells@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [ATCH v3 1/4] writeback: collect stats of all wb of bdi in bdi_debug_stats_show Date: Tue, 23 Apr 2024 00:05:36 +0800 Message-Id: <20240422160539.3340-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240422160539.3340-1-shikemeng@huaweicloud.com> References: <20240422160539.3340-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgAHdwpTDSZmt5eIKw--.7343S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Jr4kKF15Jw13GF4rGF13twb_yoW7ArWxpF W3Gw1fJrWxZFyagasxZFWDXrW5tw40q342qF92k3y5G3WDAFy3KFyxua4jyr1UGrZ7AFy5 Jan5ArykC3yUKF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPab4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r 43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF 7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxV WUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU 3Xo2DUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 270DA100007 X-Stat-Signature: khy9943p1xabssqdbxk98w811jbxi4o5 X-HE-Tag: 1713769818-54077 X-HE-Meta: U2FsdGVkX18pGvDS24abXcziXnQuNM1A+2gYQMCD6x38GPyD8/RWi3xRKaIJWiKBjAmmFBnBtiAg+pL8tAyjOV0FD5qAYYsbfFz4fvtsUBSCsynimZ4D2iHdGnkAfEV2X+DixYHoLOcvXkQx4oIB/mKUmJl0j9VHCkHHxlANVwiWac6li3fyjjU39JsL39hERXL8FI//NEEobw/+hWjSFnFK9kaD2xuzoDzpiv0ps6uBKYcVsfMcoEfS2mU39Pkn5Pbh0SOSD0QGRNb39QQb///BgvdRdUqyDrJWWwgmIOfNMJhlvqiNIwG+c5DlBbyqm1vFrzZl0KHw7lXAFttRK8A2/H7W15yM+zEoV/SO0BxtGUzmn5mH8p+3bzV2o2gYKzyii2hO292DAQ4/I9zUARx0eqoKmMbnpidAMDzg6o2+q//dbD7FzhFQGjXtX90RQ3F/s+60QxUimC0tsictQdbHfrCCKXwNAEy9zrTaG37TEYfd1cbfgZbPRor74fIZoWrQMN8MlPQ/yJ5i97UUkhLHt7K+Qa1u84gX4kEMM8QVmk3jn20mBBgLH7a8E9mhk8OakfCXIhYhNcXZGbHU7HO1NpECgWBkvbo9Aokt7NNVoCpIc86GzF46Wd9lJd06Ad6rODvMrEj4qnSLBxlO6vaDehG1K912X/dPQJsdMJcpQ+PKh77TmU0xhV25IuJiYc8k9cNvLRT9ISoT4ilRYeNyKKzWM0cCIZ/dABMwab7eH7Zot/vSNc+QBTJrfwlYgALO/5qEmBg/1gEJ2YoJdLOiiyTEoGAdML2QhSF1Mmmn3KOO4oe0VqSIJ3xezJmYZk7QlDQ8yLgo8IN8HBi+19A+ZjAUwFUm6Am+IrGMu6GF4GQXr9KWGqKK+e9Il1dozxlmtA6frPSg/ExfOgCMK3naHkkOzm7AOgEYmNogBfcI3HRbazlaBEwi3OfeJj5zLf/NNM4/G8CQ+YsHkKq dOrYH4Ak I60TEwVAB6b4c7ogcCbgG2FGIIeGo5yk0JOEjbLladbS5DvfnKzgSCEmmsOh5tMejv1DPM7SmSOOfZ1jjSp69F05YolUZDOS/AWdlgh0ZFzVpie3tH7OliYYEdjeKotbKaSlNl5VXhIyZ3JxBZ3xa7Dx3eUJ3i309oJixcwsJvIRR5m9AVepBl1MbKWoQS3ZRpnSte+Z5s2I4sTJeskotPVUksl4kD3yz1ZISIDAPgpYaDH2YpgFRfrVBuFZrIG3fg/nlR8CDZ1pbCB09ogelcg+oPDh9nYqDDOep9T7GguY69h4= 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: /sys/kernel/debug/bdi/xxx/stats is supposed to show writeback information of whole bdi, but only writeback information of bdi in root cgroup is collected. So writeback information in non-root cgroup are missing now. To be more specific, considering following case: /* create writeback cgroup */ cd /sys/fs/cgroup echo "+memory +io" > cgroup.subtree_control mkdir group1 cd group1 echo $$ > cgroup.procs /* do writeback in cgroup */ fio -name test -filename=/dev/vdb ... /* get writeback info of bdi */ cat /sys/kernel/debug/bdi/xxx/stats The cat result unexpectedly implies that there is no writeback on target bdi. Fix this by collecting stats of all wb in bdi instead of only wb in root cgroup. Following domain hierarchy is tested: global domain (320G) / \ cgroup domain1(10G) cgroup domain2(10G) | | bdi wb1 wb2 /* all writeback info of bdi is successfully collected */ cat stats BdiWriteback: 4704 kB BdiReclaimable: 1294496 kB BdiDirtyThresh: 204208088 kB DirtyThresh: 195259944 kB BackgroundThresh: 32503588 kB BdiDirtied: 48519296 kB BdiWritten: 47225696 kB BdiWriteBandwidth: 1173892 kBps b_dirty: 1 b_io: 0 b_more_io: 1 b_dirty_time: 0 bdi_list: 1 state: 1 Signed-off-by: Kemeng Shi --- mm/backing-dev.c | 96 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 5fa3666356f9..089146feb830 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -39,6 +39,19 @@ struct workqueue_struct *bdi_wq; #include #include +struct wb_stats { + unsigned long nr_dirty; + unsigned long nr_io; + unsigned long nr_more_io; + unsigned long nr_dirty_time; + unsigned long nr_writeback; + unsigned long nr_reclaimable; + unsigned long nr_dirtied; + unsigned long nr_written; + unsigned long dirty_thresh; + unsigned long wb_thresh; +}; + static struct dentry *bdi_debug_root; static void bdi_debug_init(void) @@ -46,31 +59,68 @@ static void bdi_debug_init(void) bdi_debug_root = debugfs_create_dir("bdi", NULL); } -static int bdi_debug_stats_show(struct seq_file *m, void *v) +static void collect_wb_stats(struct wb_stats *stats, + struct bdi_writeback *wb) { - struct backing_dev_info *bdi = m->private; - struct bdi_writeback *wb = &bdi->wb; - unsigned long background_thresh; - unsigned long dirty_thresh; - unsigned long wb_thresh; - unsigned long nr_dirty, nr_io, nr_more_io, nr_dirty_time; struct inode *inode; - nr_dirty = nr_io = nr_more_io = nr_dirty_time = 0; spin_lock(&wb->list_lock); list_for_each_entry(inode, &wb->b_dirty, i_io_list) - nr_dirty++; + stats->nr_dirty++; list_for_each_entry(inode, &wb->b_io, i_io_list) - nr_io++; + stats->nr_io++; list_for_each_entry(inode, &wb->b_more_io, i_io_list) - nr_more_io++; + stats->nr_more_io++; list_for_each_entry(inode, &wb->b_dirty_time, i_io_list) if (inode->i_state & I_DIRTY_TIME) - nr_dirty_time++; + stats->nr_dirty_time++; spin_unlock(&wb->list_lock); + stats->nr_writeback += wb_stat(wb, WB_WRITEBACK); + stats->nr_reclaimable += wb_stat(wb, WB_RECLAIMABLE); + 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); +} + +#ifdef CONFIG_CGROUP_WRITEBACK +static void bdi_collect_stats(struct backing_dev_info *bdi, + struct wb_stats *stats) +{ + struct bdi_writeback *wb; + + rcu_read_lock(); + list_for_each_entry_rcu(wb, &bdi->wb_list, bdi_node) { + if (!wb_tryget(wb)) + continue; + + 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); +} +#endif + +static int bdi_debug_stats_show(struct seq_file *m, void *v) +{ + struct backing_dev_info *bdi = m->private; + unsigned long background_thresh; + unsigned long dirty_thresh; + struct wb_stats stats; + unsigned long tot_bw; + global_dirty_limits(&background_thresh, &dirty_thresh); - wb_thresh = wb_calc_thresh(wb, dirty_thresh); + + memset(&stats, 0, sizeof(stats)); + stats.dirty_thresh = dirty_thresh; + bdi_collect_stats(bdi, &stats); + tot_bw = atomic_long_read(&bdi->tot_write_bandwidth); seq_printf(m, "BdiWriteback: %10lu kB\n" @@ -87,18 +137,18 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v) "b_dirty_time: %10lu\n" "bdi_list: %10u\n" "state: %10lx\n", - (unsigned long) K(wb_stat(wb, WB_WRITEBACK)), - (unsigned long) K(wb_stat(wb, WB_RECLAIMABLE)), - K(wb_thresh), + K(stats.nr_writeback), + K(stats.nr_reclaimable), + K(stats.wb_thresh), K(dirty_thresh), K(background_thresh), - (unsigned long) K(wb_stat(wb, WB_DIRTIED)), - (unsigned long) K(wb_stat(wb, WB_WRITTEN)), - (unsigned long) K(wb->write_bandwidth), - nr_dirty, - nr_io, - nr_more_io, - nr_dirty_time, + K(stats.nr_dirtied), + K(stats.nr_written), + K(tot_bw), + stats.nr_dirty, + stats.nr_io, + stats.nr_more_io, + stats.nr_dirty_time, !list_empty(&bdi->bdi_list), bdi->wb.state); return 0;