Skip to content

Commit 5443041

Browse files
yhrChristoph Hellwig
authored andcommitted
xfs: export zone stats in /proc/*/mountstats
Add the per-zone life time hint and the used block distribution for fully written zones, grouping reclaimable zones in fixed-percentage buckets spanning 0..9%, 10..19% and full zones as 100% used as well as a few statistics about the zone allocator and open and reclaimable zones in /proc/*/mountstats. This gives good insight into data fragmentation and data placement success rate. Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com> Co-developed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
1 parent 099bf44 commit 5443041

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

fs/xfs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ xfs-$(CONFIG_XFS_QUOTA) += xfs_dquot.o \
140140
xfs-$(CONFIG_XFS_RT) += xfs_rtalloc.o \
141141
xfs_zone_alloc.o \
142142
xfs_zone_gc.o \
143+
xfs_zone_info.o \
143144
xfs_zone_space_resv.o
144145

145146
xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o

fs/xfs/xfs_super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,10 @@ xfs_fs_show_stats(
12631263
struct seq_file *m,
12641264
struct dentry *root)
12651265
{
1266+
struct xfs_mount *mp = XFS_M(root->d_sb);
1267+
1268+
if (xfs_has_zoned(mp) && IS_ENABLED(CONFIG_XFS_RT))
1269+
xfs_zoned_show_stats(m, mp);
12661270
return 0;
12671271
}
12681272

fs/xfs/xfs_zone_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void xfs_mark_rtg_boundary(struct iomap_ioend *ioend);
4444

4545
uint64_t xfs_zoned_default_resblks(struct xfs_mount *mp,
4646
enum xfs_free_counter ctr);
47+
void xfs_zoned_show_stats(struct seq_file *m, struct xfs_mount *mp);
4748

4849
#ifdef CONFIG_XFS_RT
4950
int xfs_mount_zones(struct xfs_mount *mp);

fs/xfs/xfs_zone_info.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2023-2025 Christoph Hellwig.
4+
* Copyright (c) 2024-2025, Western Digital Corporation or its affiliates.
5+
*/
6+
#include "xfs.h"
7+
#include "xfs_shared.h"
8+
#include "xfs_format.h"
9+
#include "xfs_trans_resv.h"
10+
#include "xfs_mount.h"
11+
#include "xfs_inode.h"
12+
#include "xfs_rtgroup.h"
13+
#include "xfs_zone_alloc.h"
14+
#include "xfs_zone_priv.h"
15+
16+
static const char xfs_write_hint_shorthand[6][16] = {
17+
"NOT_SET", "NONE", "SHORT", "MEDIUM", "LONG", "EXTREME"};
18+
19+
static inline const char *
20+
xfs_write_hint_to_str(
21+
uint8_t write_hint)
22+
{
23+
if (write_hint > WRITE_LIFE_EXTREME)
24+
return "UNKNOWN";
25+
return xfs_write_hint_shorthand[write_hint];
26+
}
27+
28+
static void
29+
xfs_show_open_zone(
30+
struct seq_file *m,
31+
struct xfs_open_zone *oz)
32+
{
33+
seq_printf(m, "\t zone %d, wp %u, written %u, used %u, hint %s\n",
34+
rtg_rgno(oz->oz_rtg),
35+
oz->oz_write_pointer, oz->oz_written,
36+
rtg_rmap(oz->oz_rtg)->i_used_blocks,
37+
xfs_write_hint_to_str(oz->oz_write_hint));
38+
}
39+
40+
static void
41+
xfs_show_full_zone_used_distribution(
42+
struct seq_file *m,
43+
struct xfs_mount *mp)
44+
{
45+
struct xfs_zone_info *zi = mp->m_zone_info;
46+
unsigned int reclaimable = 0, full, i;
47+
48+
spin_lock(&zi->zi_used_buckets_lock);
49+
for (i = 0; i < XFS_ZONE_USED_BUCKETS; i++) {
50+
unsigned int entries = zi->zi_used_bucket_entries[i];
51+
52+
seq_printf(m, "\t %2u..%2u%%: %u\n",
53+
i * (100 / XFS_ZONE_USED_BUCKETS),
54+
(i + 1) * (100 / XFS_ZONE_USED_BUCKETS) - 1,
55+
entries);
56+
reclaimable += entries;
57+
}
58+
spin_unlock(&zi->zi_used_buckets_lock);
59+
60+
full = mp->m_sb.sb_rgcount;
61+
if (zi->zi_open_gc_zone)
62+
full--;
63+
full -= zi->zi_nr_open_zones;
64+
full -= atomic_read(&zi->zi_nr_free_zones);
65+
full -= reclaimable;
66+
67+
seq_printf(m, "\t 100%%: %u\n", full);
68+
}
69+
70+
void
71+
xfs_zoned_show_stats(
72+
struct seq_file *m,
73+
struct xfs_mount *mp)
74+
{
75+
struct xfs_zone_info *zi = mp->m_zone_info;
76+
struct xfs_open_zone *oz;
77+
78+
seq_puts(m, "\n");
79+
80+
seq_printf(m, "\tuser free RT blocks: %lld\n",
81+
xfs_sum_freecounter(mp, XC_FREE_RTEXTENTS));
82+
seq_printf(m, "\treserved free RT blocks: %lld\n",
83+
mp->m_free[XC_FREE_RTEXTENTS].res_avail);
84+
seq_printf(m, "\tuser available RT blocks: %lld\n",
85+
xfs_sum_freecounter(mp, XC_FREE_RTAVAILABLE));
86+
seq_printf(m, "\treserved available RT blocks: %lld\n",
87+
mp->m_free[XC_FREE_RTAVAILABLE].res_avail);
88+
seq_printf(m, "\tRT reservations required: %d\n",
89+
!list_empty_careful(&zi->zi_reclaim_reservations));
90+
seq_printf(m, "\tRT GC required: %d\n",
91+
xfs_zoned_need_gc(mp));
92+
93+
seq_printf(m, "\tfree zones: %d\n", atomic_read(&zi->zi_nr_free_zones));
94+
seq_puts(m, "\topen zones:\n");
95+
spin_lock(&zi->zi_open_zones_lock);
96+
list_for_each_entry(oz, &zi->zi_open_zones, oz_entry)
97+
xfs_show_open_zone(m, oz);
98+
if (zi->zi_open_gc_zone) {
99+
seq_puts(m, "\topen gc zone:\n");
100+
xfs_show_open_zone(m, zi->zi_open_gc_zone);
101+
}
102+
spin_unlock(&zi->zi_open_zones_lock);
103+
seq_puts(m, "\tused blocks distribution (fully written zones):\n");
104+
xfs_show_full_zone_used_distribution(m, mp);
105+
}

0 commit comments

Comments
 (0)