From nobody Sat Nov 23 04:48:48 2024 Received: from out30-76.freemail.mail.aliyun.com (out30-76.freemail.mail.aliyun.com [115.124.30.76]) (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 ACF142AD21; Thu, 14 Nov 2024 03:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.76 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731555941; cv=none; b=jvFGr3bcwYEctUVycwBu8oZRmY+W4OrFw0V1h8gzctCdywoHIjc4IG1sJ1v+6bMG5ZyFDSGfoydCeYw28srvZFgndJJjW5FvD2gqC7D50w+EIZhnYFGA5rZVnpwyM5Fhwx7cfVbgbDhXeXK0+ioLn9m+3VfibplimMPCYjaOKug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731555941; c=relaxed/simple; bh=IdhrXyPf19VOojC9bGeoFlzKJXolp5iyT/19HGcP/m0=; h=Date:From:To:Cc:Message-ID:Subject:MIME-Version:Content-Type; b=Px4FG5WmaFONu+T1FmnrWnMcUjSyHozowX89ookPWijYBhwOzYEOKpu7dGZbXQuzcyacqFTBe15zYTNp35VStIH6El3SjwKmNU70zhlYJIYAl93T9Rk2CqOGHmbEizANKzoW+F//jsPIrzU7aELiYXe+AX/oA9uAXqYpkzTKPLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aliyun.com; spf=pass smtp.mailfrom=aliyun.com; dkim=pass (1024-bit key) header.d=aliyun.com header.i=@aliyun.com header.b=TdVAcplK; arc=none smtp.client-ip=115.124.30.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=aliyun.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aliyun.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=aliyun.com header.i=@aliyun.com header.b="TdVAcplK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aliyun.com; s=s1024; t=1731555935; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type; bh=IdhrXyPf19VOojC9bGeoFlzKJXolp5iyT/19HGcP/m0=; b=TdVAcplKGxLxbZ4c3udHiUnxOmtYXxZor9xjIq9v1QJV6XyGHB7U00OXKyRWrzcazZhRgcsmavL1ePQJhGQ++8d1nG0tlKlYd7CJVkRepGVLQFfk+F62OIG8AnP+sC0ptldqYo5FRnED2DvbVy16uXQQwjirUrFA1HJGp13APv0= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07431718|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.045937-0.00108146-0.952982;FP=17767681518276724467|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033023153071;MF=shisiyuan@aliyun.com;NM=1;PH=DW;RN=4;RT=4;SR=0;TI=W4_0.2.3_21460848_1731555797897_o7001c61p; Received: from WS-web (shisiyuan@aliyun.com[W4_0.2.3_21460848_1731555797897_o7001c61p] cluster:ay36) at Thu, 14 Nov 2024 11:45:35 +0800 Date: Thu, 14 Nov 2024 11:45:35 +0800 From: "shisiyuan" To: "tytso" , "adilger.kernel" Cc: "linux-ext4" , "linux-kernel" Reply-To: "shisiyuan" Message-ID: <88ccc36e-f511-4d35-9738-1c2ee6dab17c.shisiyuan@aliyun.com> Subject: =?UTF-8?B?W1BBVENIXSBleHQ0OiBhZGQgdW50cmltbWVkIGdyb3VwIGNvdW50IHN5c2ZzIGludGVyZmFj?= =?UTF-8?B?ZQ==?= X-Mailer: [Alimail-Mailagent][W4_0.2.3][null][Chrome] Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 x-aliyun-im-through: {"version":"v1.0"} x-aliyun-mail-creator: W4_0.2.3_null_M3LTW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEzMC4wLjAuMCBTYWZhcmkvNTM3LjM2vN Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is used for userspace to decide whether system should perform trimming at a proper time. Signed-off-by: shisiyuan --- fs/ext4/mballoc.c | 2 +- fs/ext4/mballoc.h | 3 +++ fs/ext4/sysfs.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9fc4b6177129..0b8c49b7535e 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1727,7 +1727,7 @@ ext4_mb_load_buddy_gfp(struct super_block *sb, ext4_g= roup_t group, return ret; } -static int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, +int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, struct ext4_buddy *e4b) { return ext4_mb_load_buddy_gfp(sb, group, e4b, GFP_NOFS); diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h index f8280de3e882..9544abdcf7e4 100644 --- a/fs/ext4/mballoc.h +++ b/fs/ext4/mballoc.h @@ -246,6 +246,9 @@ static inline loff_t pa_logical_end(struct ext4_sb_info= *sbi, return (loff_t)pa->pa_lstart + EXT4_C2B(sbi, pa->pa_len); } +int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, + struct ext4_buddy *e4b); + typedef int (*ext4_mballoc_query_range_fn)( struct super_block *sb, ext4_group_t agno, diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index ddb54608ca2e..ecfd79505a79 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -17,6 +17,7 @@ #include "ext4.h" #include "ext4_jbd2.h" +#include "mballoc.h" typedef enum { attr_noop, @@ -40,6 +41,7 @@ typedef enum { attr_pointer_string, attr_pointer_atomic, attr_journal_task, + attr_untrimmed_groups, } attr_id_t; typedef enum { @@ -138,6 +140,29 @@ static ssize_t journal_task_show(struct ext4_sb_info *= sbi, char *buf) task_pid_vnr(sbi->s_journal->j_task)); } +static ssize_t untrimmed_groups_show(struct ext4_sb_info *sbi, char *buf) +{ + struct super_block *sb =3D sbi->s_sb; + ext4_group_t ngroups, i; + struct ext4_buddy e4b; + int ret =3D 0, untrimmed =3D 0; + + ngroups =3D ext4_get_groups_count(sb); + for (i =3D 0; i < ngroups; i++) { + ret =3D ext4_mb_load_buddy(sb, i, &e4b); + if (ret) { + ext4_warning(sb, "Error %d loading buddy informati= on for %u", + ret, i); + return snprintf(buf, PAGE_SIZE, "load error\n"); + } + if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info)) + untrimmed++; + } + + return snprintf(buf, PAGE_SIZE, "%d/%d\n", + untrimmed, ngroups); +} + #define EXT4_ATTR(_name,_mode,_id) \ static struct ext4_attr ext4_attr_##_name =3D { = \ .attr =3D {.name =3D __stringify(_name), .mode =3D _mode }, = \ @@ -251,6 +276,7 @@ EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_fu= nc, 32); EXT4_ATTR(first_error_time, 0444, first_error_time); EXT4_ATTR(last_error_time, 0444, last_error_time); EXT4_ATTR(journal_task, 0444, journal_task); +EXT4_ATTR(untrimmed_groups, 0444, untrimmed_groups); EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); @@ -299,6 +325,7 @@ static struct attribute *ext4_attrs[] =3D { ATTR_LIST(first_error_time), ATTR_LIST(last_error_time), ATTR_LIST(journal_task), + ATTR_LIST(untrimmed_groups), #ifdef CONFIG_EXT4_DEBUG ATTR_LIST(simulate_fail), #endif @@ -439,6 +466,8 @@ static ssize_t ext4_attr_show(struct kobject *kobj, return print_tstamp(buf, sbi->s_es, s_last_error_time); case attr_journal_task: return journal_task_show(sbi, buf); + case attr_untrimmed_groups: + return untrimmed_groups_show(sbi, buf); default: return ext4_generic_attr_show(a, sbi, buf); } --=20 2.34.1