xref: /linux/fs/xfs/xfs_zone_info.c (revision c4dde411bc366f568dbe33366253bbfea049e8ea)
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_platform.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 %s\n",
34 		rtg_rgno(oz->oz_rtg),
35 		oz->oz_allocated, oz->oz_written,
36 		rtg_rmap(oz->oz_rtg)->i_used_blocks,
37 		xfs_write_hint_to_str(oz->oz_write_hint),
38 		oz->oz_is_gc ? "(GC)" : "");
39 }
40 
41 static void
42 xfs_show_full_zone_used_distribution(
43 	struct seq_file         *m,
44 	struct xfs_mount        *mp)
45 {
46 	struct xfs_zone_info	*zi = mp->m_zone_info;
47 	unsigned int		reclaimable = 0, full, i;
48 
49 	spin_lock(&zi->zi_used_buckets_lock);
50 	for (i = 0; i < XFS_ZONE_USED_BUCKETS; i++) {
51 		unsigned int entries = zi->zi_used_bucket_entries[i];
52 
53 		seq_printf(m, "\t  %2u..%2u%%: %u\n",
54 				i * (100 / XFS_ZONE_USED_BUCKETS),
55 				(i + 1) * (100 / XFS_ZONE_USED_BUCKETS) - 1,
56 				entries);
57 		reclaimable += entries;
58 	}
59 	spin_unlock(&zi->zi_used_buckets_lock);
60 
61 	full = mp->m_sb.sb_rgcount;
62 	full -= zi->zi_nr_open_zones;
63 	full -= zi->zi_nr_open_gc_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, "\ttotal number of zones: %u\n",
94 		mp->m_sb.sb_rgcount);
95 	seq_printf(m, "\tfree zones: %d\n", atomic_read(&zi->zi_nr_free_zones));
96 
97 	spin_lock(&zi->zi_open_zones_lock);
98 	seq_printf(m, "\tmax open zones: %u\n",
99 		mp->m_max_open_zones);
100 	seq_printf(m, "\tnr open zones: %u\n",
101 		zi->zi_nr_open_zones);
102 	seq_printf(m, "\tnr open GC zones: %u\n",
103 		zi->zi_nr_open_gc_zones);
104 	seq_puts(m, "\topen zones:\n");
105 	list_for_each_entry(oz, &zi->zi_open_zones, oz_entry)
106 		xfs_show_open_zone(m, oz);
107 	spin_unlock(&zi->zi_open_zones_lock);
108 	seq_puts(m, "\tused blocks distribution (fully written zones):\n");
109 	xfs_show_full_zone_used_distribution(m, mp);
110 }
111