{"id":2225998,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2225998/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260422015026.7170-3-liubaolin12138@163.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/1.2/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260422015026.7170-3-liubaolin12138@163.com>","list_archive_url":null,"date":"2026-04-22T01:50:25","name":"[v3,v3,2/2] ext4: allow clearing mballoc stats through mb_stats","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"250b445500b60c49b7fa9ee36bdac8249aecab2f","submitter":{"id":89479,"url":"http://patchwork.ozlabs.org/api/1.2/people/89479/?format=json","name":"liubaolin","email":"liubaolin12138@163.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20260422015026.7170-3-liubaolin12138@163.com/mbox/","series":[{"id":500909,"url":"http://patchwork.ozlabs.org/api/1.2/series/500909/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=500909","date":"2026-04-22T01:50:23","name":"add blocks_allocated to mb_stats and clear mb_stats","version":3,"mbox":"http://patchwork.ozlabs.org/series/500909/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225998/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225998/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <SRS0=uCPE=CV=vger.kernel.org=linux-ext4+bounces-15963-patchwork-incoming=ozlabs.org@ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ext4@vger.kernel.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","patchwork-incoming@ozlabs.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256\n header.s=s110527 header.b=VqiApriF;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org\n (client-ip=150.107.74.76; helo=mail.ozlabs.org;\n envelope-from=srs0=ucpe=cv=vger.kernel.org=linux-ext4+bounces-15963-patchwork-incoming=ozlabs.org@ozlabs.org;\n receiver=patchwork.ozlabs.org)","gandalf.ozlabs.org;\n arc=pass smtp.remote-ip=172.234.253.10 arc.chain=subspace.kernel.org","gandalf.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=163.com","gandalf.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256\n header.s=s110527 header.b=VqiApriF;\n\tdkim-atps=neutral","gandalf.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15963-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=\"VqiApriF\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=220.197.31.5","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=163.com"],"Received":["from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0j2l5Wztz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:54:39 +1000 (AEST)","from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3])\n\tby gandalf.ozlabs.org (Postfix) with ESMTP id 4g0j2l53lNz4wJX\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 11:54:39 +1000 (AEST)","by gandalf.ozlabs.org (Postfix)\n\tid 4g0j2l50Cjz4wJ2; Wed, 22 Apr 2026 11:54:39 +1000 (AEST)","from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby gandalf.ozlabs.org (Postfix) with ESMTPS id 4g0j2h273sz4wJX\n\tfor <patchwork-incoming@ozlabs.org>; Wed, 22 Apr 2026 11:54:36 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 5E83A305288B\n\tfor <patchwork-incoming@ozlabs.org>; Wed, 22 Apr 2026 01:52:53 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id E42802D2483;\n\tWed, 22 Apr 2026 01:52:52 +0000 (UTC)","from m16.mail.163.com (m16.mail.163.com [220.197.31.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id A850D3090C4;\n\tWed, 22 Apr 2026 01:52:50 +0000 (UTC)","from liubaolin-VMware-Virtual-Platform.localdomain (unknown [])\n\tby gzga-smtp-mtada-g1-0 (Coremail) with SMTP id\n _____wA3Hx+uKehpOCzjAw--.387S4;\n\tWed, 22 Apr 2026 09:52:01 +0800 (CST)"],"ARC-Seal":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1776822879; cv=pass;\n\tb=a04VJ3QnCh/A5GOLXS/AQncvUBiTWCV7B4y0NFQeqjASKolgWkLwKDemwXPnQv9J7vR2CxazLSwRYsw5j/OkEggApNy1+e+uSir426yOmGpKx3gOvBLmoSWJ58vijnGbYPeozJ9+Qv9G617mMKpFrksEoidbhwqDW7OOVea1bgaqzZZr+3ciGB4SFqOcyoQ5EDixvl3LY64TAdMGt4a48uHkfOv35hDwLpWnjacQ6wNO4WG3BF6a1CM0ko2RHlb4oLSlqAWfpWdw3gwjGoP0OIf87JyKkMJjWzP7vyVSNnGkdXdQ/o8UH991my0sfkdTIOeXkp9oPwvDMRl45ZQ0aw==","i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776822772; cv=none;\n b=Q9WZq81AN3VhgbigSa2r9t5wxa96Eg2UtXT7NWELWGBbLH5t2deBQrrerKqss7fHc7c8azctUA9qetLco132UeUXf2rii+W5uI4wzrlsCaqqOtd8OaYfGYkhw1LG4uqNpWyBZHkoyyn0Sfs8YDUe16+wqYYeZQcXwu7dcHLj5f8="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=ozlabs.org; s=201707;\n\tt=1776822879; c=relaxed/relaxed;\n\tbh=dEZ9FIUPUF+T6ETjcmLX+Rkx/mVcnjQZFx9WuuF6ilM=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=PXNunh6IIpmeGcTxaDb9x7Qwpo5DzJmfgax3fkhDlcJKuTb/lr82mOQMPxl5Gf2xkPSZktXMXZWFAyCES9vZZQpnXcPEGOPTOdRATRQNjnCzEQUng3m0UvMa0wGyjI8Z4eAAq5zihYTefZ+MMG9iYoCS6++ROsB3Ik1Qyb4IezRJmYQt7+FSW2xySxeTR7Tsd3XnmSRs+fJWPnsnNhRQn4+oWMlHd6Im6Lx2JquSyLSpiHLA3UwWLqOakkVbyOVgRTMD2zUNeZfCUGs1qLWPbZxo/eih1p9VO33mFTkYOIKqh1h5zt1URjj1F0J+MATyuxadfmS9mdT1S7K32AnZjw==","i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776822772; c=relaxed/simple;\n\tbh=d3/dSb8VCsfS1PnI0yLe8lTP/fXOz2nNcgCYfTB7PVE=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=i2Ug/kg4rwMHhGnFE0xXQs1oNZmKNnj9ME40rjFvEzg9w26J/7GM2yPQai9EAi1wvGzjb3YM8Wj3HzXUNsSTSjLQU7HkeSyrHYqMcY4Xwgx8YxTkVNzNuyy/O5cLsAQqyND8b5NIblTZon6iwXILX+R6Cz17ussAm2t5GdKnv0A="],"ARC-Authentication-Results":["i=2; gandalf.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=163.com; dkim=pass (1024-bit key;\n unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256\n header.s=s110527 header.b=VqiApriF; dkim-atps=neutral;\n spf=pass (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-ext4+bounces-15963-patchwork-incoming=ozlabs.org@vger.kernel.org;\n receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org","i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com;\n spf=pass smtp.mailfrom=163.com;\n dkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=VqiApriF; arc=none smtp.client-ip=220.197.31.5"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;\n\ts=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=dE\n\tZ9FIUPUF+T6ETjcmLX+Rkx/mVcnjQZFx9WuuF6ilM=; b=VqiApriFvRN4Z6E9no\n\t7/+64z/mVsdsVapf9Ggzdz2vRtv3fAx+fhgHvdYgouQBq398YHi0asb6eX3Ah8Ar\n\tRovw21Cz7AiuPIyUc7rNq4hsD/B4sr2IoQvesU32H1oh21lrEuM8a1O534MLTGXI\n\tWGmCfvLfFgz8K6M47zBO/4mig=","From":"Baolin Liu <liubaolin12138@163.com>","To":"tytso@mit.edu,\n\tadilger.kernel@dilger.ca,\n\tojaswin@linux.ibm.com,\n\tritesh.list@gmail.com,\n\tyi.zhang@huawei.com","Cc":"linux-ext4@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\twangguanyu@vivo.com,\n\tliubaolin12138@163.com,\n\tBaolin Liu <liubaolin@kylinos.cn>,\n\tAndreas Dilger <adilger@dilger.ca>","Subject":"[PATCH v3 v3 2/2] ext4: allow clearing mballoc stats through mb_stats","Date":"Wed, 22 Apr 2026 09:50:25 +0800","Message-ID":"<20260422015026.7170-3-liubaolin12138@163.com>","X-Mailer":"git-send-email 2.51.0","In-Reply-To":"<20260422015026.7170-1-liubaolin12138@163.com>","References":"<20260422015026.7170-1-liubaolin12138@163.com>","Precedence":"bulk","X-Mailing-List":"linux-ext4@vger.kernel.org","List-Id":"<linux-ext4.vger.kernel.org>","List-Subscribe":"<mailto:linux-ext4+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ext4+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-CM-TRANSID":"_____wA3Hx+uKehpOCzjAw--.387S4","X-Coremail-Antispam":"1Uf129KBjvJXoW3JrW8GFyxCr45CF1fGrW3Jrb_yoW7tFyUpF\n\ts8ZFyxGr18Wa47uws7Gr4xZw1Yy3W8Cw1UKryIv34rur9Iqr9YyF1rtryjyFyYgrWUAayk\n\tXF429ryUGr42ka7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_73kDUUUUU=","X-CM-SenderInfo":"xolxutxrol0iasrtmqqrwthudrp/xtbCwgEP2WnoKcE7yQAA3O","X-Spam-Status":"No, score=-1.2 required=5.0 tests=ARC_SIGNED,ARC_VALID,\n\tDKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS,\n\tFREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,\n\tMAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY\n\tautolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org"},"content":"From: Baolin Liu <liubaolin@kylinos.cn>\n\nMake /proc/fs/ext4/<dev>/mb_stats writable and clear the runtime\nmballoc statistics when 0 is written.\nUpdate the related documentation accordingly.\n\nReviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>\nReviewed-by: Andreas Dilger <adilger@dilger.ca>\nReviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>\nReviewed-by: Zhang Yi <yi.zhang@huawei.com>\nSigned-off-by: Baolin Liu <liubaolin@kylinos.cn>\n---\n Documentation/admin-guide/ext4.rst |  5 ++++\n Documentation/filesystems/proc.rst |  3 +++\n fs/ext4/ext4.h                     |  1 +\n fs/ext4/mballoc.c                  | 29 ++++++++++++++++++++++\n fs/ext4/sysfs.c                    | 40 ++++++++++++++++++++++++++++--\n 5 files changed, 76 insertions(+), 2 deletions(-)","diff":"diff --git a/Documentation/admin-guide/ext4.rst b/Documentation/admin-guide/ext4.rst\nindex ac0c709ea9e7..fb3887cd5e44 100644\n--- a/Documentation/admin-guide/ext4.rst\n+++ b/Documentation/admin-guide/ext4.rst\n@@ -436,6 +436,11 @@ Files in /proc/fs/ext4/<devname>\n   mb_groups\n         details of multiblock allocator buddy cache of free blocks\n \n+  mb_stats\n+        reports runtime statistics from the multiblock allocator\n+        (mballoc). Writing 0 to this file clears the current\n+        statistics.\n+\n /sys entries\n ============\n \ndiff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst\nindex b0c0d1b45b99..7ce02573a3d9 100644\n--- a/Documentation/filesystems/proc.rst\n+++ b/Documentation/filesystems/proc.rst\n@@ -1634,6 +1634,9 @@ directory are shown in Table 1-12, below.\n  ==============  ==========================================================\n  File            Content\n  mb_groups       details of multiblock allocator buddy cache of free blocks\n+ mb_stats        reports runtime statistics from the multiblock allocator\n+                 (mballoc). Writing 0 to this file clears the current\n+                 statistics.\n  ==============  ==========================================================\n \n 1.9 /proc/consoles\ndiff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h\nindex 293f698b7042..3223e73612ae 100644\n--- a/fs/ext4/ext4.h\n+++ b/fs/ext4/ext4.h\n@@ -2994,6 +2994,7 @@ int ext4_fc_record_regions(struct super_block *sb, int ino,\n extern const struct seq_operations ext4_mb_seq_groups_ops;\n extern const struct seq_operations ext4_mb_seq_structs_summary_ops;\n extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset);\n+extern void ext4_mb_stats_clear(struct ext4_sb_info *sbi);\n extern int ext4_mb_init(struct super_block *);\n extern void ext4_mb_release(struct super_block *);\n extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,\ndiff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c\nindex 1e13ef62cb9d..79ddfa935813 100644\n--- a/fs/ext4/mballoc.c\n+++ b/fs/ext4/mballoc.c\n@@ -4723,6 +4723,35 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)\n \t\ttrace_ext4_mballoc_prealloc(ac);\n }\n \n+void ext4_mb_stats_clear(struct ext4_sb_info *sbi)\n+{\n+\tint i;\n+\n+\tatomic_set(&sbi->s_bal_reqs, 0);\n+\tatomic_set(&sbi->s_bal_success, 0);\n+\tatomic_set(&sbi->s_bal_allocated, 0);\n+\tatomic_set(&sbi->s_bal_groups_scanned, 0);\n+\n+\tfor (i = 0; i < EXT4_MB_NUM_CRS; i++) {\n+\t\tatomic64_set(&sbi->s_bal_cX_hits[i], 0);\n+\t\tatomic64_set(&sbi->s_bal_cX_groups_considered[i], 0);\n+\t\tatomic_set(&sbi->s_bal_cX_ex_scanned[i], 0);\n+\t\tatomic64_set(&sbi->s_bal_cX_failed[i], 0);\n+\t}\n+\n+\tatomic_set(&sbi->s_bal_ex_scanned, 0);\n+\tatomic_set(&sbi->s_bal_goals, 0);\n+\tatomic_set(&sbi->s_bal_stream_goals, 0);\n+\tatomic_set(&sbi->s_bal_len_goals, 0);\n+\tatomic_set(&sbi->s_bal_2orders, 0);\n+\tatomic_set(&sbi->s_bal_breaks, 0);\n+\tatomic_set(&sbi->s_mb_lost_chunks, 0);\n+\tatomic_set(&sbi->s_mb_buddies_generated, 0);\n+\tatomic64_set(&sbi->s_mb_generation_time, 0);\n+\tatomic_set(&sbi->s_mb_preallocated, 0);\n+\tatomic_set(&sbi->s_mb_discarded, 0);\n+}\n+\n /*\n  * Called on failure; free up any blocks from the inode PA for this\n  * context.  We don't need this for MB_GROUP_PA because we only change\ndiff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c\nindex b87d7bdab06a..e90885d470ab 100644\n--- a/fs/ext4/sysfs.c\n+++ b/fs/ext4/sysfs.c\n@@ -52,6 +52,42 @@ typedef enum {\n static const char proc_dirname[] = \"fs/ext4\";\n static struct proc_dir_entry *ext4_proc_root;\n \n+static int ext4_mb_stats_open(struct inode *inode, struct file *file)\n+{\n+\treturn single_open(file, ext4_seq_mb_stats_show, pde_data(inode));\n+}\n+\n+static ssize_t ext4_mb_stats_write(struct file *file, const char __user *buf,\n+\t\t\t\t\t   size_t count, loff_t *ppos)\n+{\n+\tstruct super_block *sb = pde_data(file_inode(file));\n+\tchar kbuf[2];\n+\n+\tif (count == 0 || count > sizeof(kbuf))\n+\t\treturn -EINVAL;\n+\n+\tif (copy_from_user(kbuf, buf, count))\n+\t\treturn -EFAULT;\n+\n+\tif (count == 2) {\n+\t\tif (kbuf[0] != '0' || kbuf[1] != '\\n')\n+\t\t\treturn -EINVAL;\n+\t} else if (kbuf[0] != '0') {\n+\t\treturn -EINVAL;\n+\t}\n+\n+\text4_mb_stats_clear(EXT4_SB(sb));\n+\treturn count;\n+}\n+\n+static const struct proc_ops ext4_mb_stats_proc_ops = {\n+\t.proc_open\t= ext4_mb_stats_open,\n+\t.proc_read\t= seq_read,\n+\t.proc_lseek\t= seq_lseek,\n+\t.proc_release\t= single_release,\n+\t.proc_write\t= ext4_mb_stats_write,\n+};\n+\n struct ext4_attr {\n \tstruct attribute attr;\n \tshort attr_id;\n@@ -630,8 +666,8 @@ int ext4_register_sysfs(struct super_block *sb)\n \t\t\t\t\text4_fc_info_show, sb);\n \t\tproc_create_seq_data(\"mb_groups\", S_IRUGO, sbi->s_proc,\n \t\t\t\t&ext4_mb_seq_groups_ops, sb);\n-\t\tproc_create_single_data(\"mb_stats\", 0444, sbi->s_proc,\n-\t\t\t\text4_seq_mb_stats_show, sb);\n+\t\tproc_create_data(\"mb_stats\", 0644, sbi->s_proc,\n+\t\t\t\t &ext4_mb_stats_proc_ops, sb);\n \t\tproc_create_seq_data(\"mb_structs_summary\", 0444, sbi->s_proc,\n \t\t\t\t&ext4_mb_seq_structs_summary_ops, sb);\n \t}\n","prefixes":["v3","v3","2/2"]}