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