From patchwork Wed Mar 20 11:02:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13597197 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 906D7C54E71 for ; Wed, 20 Mar 2024 02:06:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 347956B007B; Tue, 19 Mar 2024 22:06:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2CBD16B008A; Tue, 19 Mar 2024 22:06:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F26966B007B; Tue, 19 Mar 2024 22:06:13 -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 690B66B0085 for ; Tue, 19 Mar 2024 22:06:13 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 187351A0B25 for ; Wed, 20 Mar 2024 02:06:13 +0000 (UTC) X-FDA: 81915777426.29.FE2B390 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf15.hostedemail.com (Postfix) with ESMTP id 6A646A0008 for ; Wed, 20 Mar 2024 02:06:09 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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=1710900371; 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=mmFS04ZJdeH/lK7kKWd3FZA/Psfh9tii6fCdDgfIrgA=; b=16Cs0jEo+7LPBpUDppWfgQqEm5KoUqsO+2c2vkUdQyUqnhb07GRKsBiNl7ygzGKkGxgY5c aifaJQCt8lU/z9pQ0anP6zNHvoIubPENW+hQrOYIpzitQAEj4oN4WikKP+g5QxnnmZDLB5 S2odz3XOfyIDtjesW3+ljl9tx5IcBYM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf15.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=1710900371; a=rsa-sha256; cv=none; b=NuWGIUDgzomVp4IJRi+0ofawtGOTZTHNL+56yEFG+2VNOAP76eQfq7AfmAm7Zv09oa3qZZ 9PE0Ch6cf7W30t5V3oxYOevb/HLi4/Ox4DtRssmJFx7x5vTK04JCOFGVDhyvHb3xCS9l7t FKsUM1Tnsl33w5SHhmh8WEV6RkOgJOU= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TzsQ15B9rz4f3kKb for ; Wed, 20 Mar 2024 10:06:01 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 958D51A0199 for ; Wed, 20 Mar 2024 10:06:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP3 (Coremail) with SMTP id _Ch0CgAHFZ2KRPplVj2CHQ--.18626S4; Wed, 20 Mar 2024 10:06:05 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, tj@kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, bfoster@redhat.com, jack@suse.cz, dsterba@suse.com, mjguzik@gmail.com, dhowells@redhat.com, peterz@infradead.org Subject: [PATCH 2/6] writeback: support retrieving per group debug writeback stats of bdi Date: Wed, 20 Mar 2024 19:02:18 +0800 Message-Id: <20240320110222.6564-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240320110222.6564-1-shikemeng@huaweicloud.com> References: <20240320110222.6564-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAHFZ2KRPplVj2CHQ--.18626S4 X-Coremail-Antispam: 1UD129KBjvJXoWxur1rCr4xKFWUtFWrAFWfGrg_yoWruw4kpF sxGw1rJrWUZr17WFZxAFZrXry3Jw4FqrW2qF97ZayrKFnrKF1aqFyxury0yr1UJrWfAFya vws0kry8urW8KrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPab4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxV A2Y2ka0xkIwI1l42xK82IY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UIFTlF8CDldg458k2wVFwdX4ZBFcEn8yXqvFErlVgkMyXGw7pPk0j/fs+yL9qZ63KUBg3/oANoMAtvmJXC/LBHQaiCQSWEkHqLSopmVPpoeCOCZEqWm3mYGsQrO9W4fkPfsjZDH5rqdu7AMPq4vNi2VB6bqt0bBmEb2AD3GnvaAwQ4VPfyiixHT21WD9/KBOkzaY1C6oPPlowf105mUeTS1cWR77IWgV1Zki4qXFHATLxOxWgwYmAE+7MqNK+6dLr2tfgRTPW09r+PtVDpp63e0AARzXGnfwGVy9InJhqLv/uTjuTjtFNoHuLV+fCZ9dJWtDnyHOnOKe4swvs0QgAYhfppnTPSM5NrjuF+HqUdJs7Kx3l2MUOKrYqQ2EP9SXN 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: Add /sys/kernel/debug/bdi/xxx/wb_stats to show per group writeback stats of bdi. Signed-off-by: Kemeng Shi --- include/linux/writeback.h | 1 + mm/backing-dev.c | 66 +++++++++++++++++++++++++++++++++++++++ mm/page-writeback.c | 19 +++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 9845cb62e40b..bb1ce1123b52 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -355,6 +355,7 @@ int dirtytime_interval_handler(struct ctl_table *table, int write, void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty); unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh); +unsigned long wb_calc_cg_thresh(struct bdi_writeback *wb); void wb_update_bandwidth(struct bdi_writeback *wb); diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 788702b6c5dd..bfc4079dc7fe 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -95,12 +95,77 @@ static void bdi_collect_stats(struct backing_dev_info *bdi, collect_wb_stats(stats, wb); mutex_unlock(&bdi->cgwb_release_mutex); } +static void wb_stats_show(struct seq_file *m, struct bdi_writeback *wb, + struct wb_stats *stats) +{ + + seq_printf(m, + "WbCgIno: %10lu\n" + "WbWriteback: %10lu kB\n" + "WbReclaimable: %10lu kB\n" + "WbDirtyThresh: %10lu kB\n" + "WbDirtied: %10lu kB\n" + "WbWritten: %10lu kB\n" + "WbWriteBandwidth: %10lu kBps\n" + "b_dirty: %10lu\n" + "b_io: %10lu\n" + "b_more_io: %10lu\n" + "b_dirty_time: %10lu\n" + "state: %10lx\n", + cgroup_ino(wb->memcg_css->cgroup), + K(stats->nr_writeback), + K(stats->nr_reclaimable), + K(stats->wb_thresh), + K(stats->nr_dirtied), + K(stats->nr_written), + K(wb->avg_write_bandwidth), + stats->nr_dirty, + stats->nr_io, + stats->nr_more_io, + stats->nr_dirty_time, + wb->state); +} + +static int cgwb_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 bdi_writeback *wb; + struct wb_stats stats; + + global_dirty_limits(&background_thresh, &dirty_thresh); + + mutex_lock(&bdi->cgwb_release_mutex); + list_for_each_entry(wb, &bdi->wb_list, bdi_node) { + memset(&stats, 0, sizeof(stats)); + stats.dirty_thresh = dirty_thresh; + collect_wb_stats(&stats, wb); + + if (mem_cgroup_wb_domain(wb) != NULL) + stats.wb_thresh = min(stats.wb_thresh, wb_calc_cg_thresh(wb)); + + wb_stats_show(m, wb, &stats); + } + mutex_unlock(&bdi->cgwb_release_mutex); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(cgwb_debug_stats); + +static void cgwb_debug_register(struct backing_dev_info *bdi) +{ + debugfs_create_file("wb_stats", 0444, bdi->debug_dir, bdi, + &cgwb_debug_stats_fops); +} #else static void bdi_collect_stats(struct backing_dev_info *bdi, struct wb_stats *stats) { collect_wb_stats(stats, &bdi->wb); } + +static inline void cgwb_debug_register(struct backing_dev_info *bdi) { } #endif static int bdi_debug_stats_show(struct seq_file *m, void *v) @@ -158,6 +223,7 @@ static void bdi_debug_register(struct backing_dev_info *bdi, const char *name) debugfs_create_file("stats", 0444, bdi->debug_dir, bdi, &bdi_debug_stats_fops); + cgwb_debug_register(bdi); } static void bdi_debug_unregister(struct backing_dev_info *bdi) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0e20467367fe..ba1b6b5ae5d6 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -893,6 +893,25 @@ unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh) return __wb_calc_thresh(&gdtc, thresh); } +unsigned long wb_calc_cg_thresh(struct bdi_writeback *wb) +{ + struct dirty_throttle_control gdtc = { GDTC_INIT_NO_WB }; + struct dirty_throttle_control mdtc = { MDTC_INIT(wb, &gdtc) }; + unsigned long filepages, headroom, writeback; + + gdtc.avail = global_dirtyable_memory(); + gdtc.dirty = global_node_page_state(NR_FILE_DIRTY) + + global_node_page_state(NR_WRITEBACK); + + mem_cgroup_wb_stats(wb, &filepages, &headroom, + &mdtc.dirty, &writeback); + mdtc.dirty += writeback; + mdtc_calc_avail(&mdtc, filepages, headroom); + domain_dirty_limits(&mdtc); + + return __wb_calc_thresh(&mdtc, mdtc.thresh); +} + /* * setpoint - dirty 3 * f(dirty) := 1.0 + (----------------)