^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) struct xstats xfsstats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static int counter_val(struct xfsstats __percpu *stats, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) int val = 0, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) val += *(((__u32 *)per_cpu_ptr(stats, cpu) + idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) uint64_t xs_xstrat_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) uint64_t xs_write_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) uint64_t xs_read_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) uint64_t defer_relog = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static const struct xstats_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) char *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) } xstats[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) { "extent_alloc", xfsstats_offset(xs_abt_lookup) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { "abt", xfsstats_offset(xs_blk_mapr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) { "blk_map", xfsstats_offset(xs_bmbt_lookup) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { "bmbt", xfsstats_offset(xs_dir_lookup) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) { "dir", xfsstats_offset(xs_trans_sync) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { "trans", xfsstats_offset(xs_ig_attempts) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { "ig", xfsstats_offset(xs_log_writes) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { "log", xfsstats_offset(xs_try_logspace)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { "push_ail", xfsstats_offset(xs_xstrat_quick)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { "xstrat", xfsstats_offset(xs_write_calls) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { "rw", xfsstats_offset(xs_attr_get) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { "attr", xfsstats_offset(xs_iflush_count)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) { "icluster", xfsstats_offset(vn_active) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { "vnodes", xfsstats_offset(xb_get) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { "buf", xfsstats_offset(xs_abtb_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { "abtb2", xfsstats_offset(xs_abtc_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) { "abtc2", xfsstats_offset(xs_bmbt_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) { "bmbt2", xfsstats_offset(xs_ibt_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) { "ibt2", xfsstats_offset(xs_fibt_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) { "fibt2", xfsstats_offset(xs_rmap_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) { "rmapbt", xfsstats_offset(xs_refcbt_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) { "refcntbt", xfsstats_offset(xs_qm_dqreclaims)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* we print both series of quota information together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) { "qm", xfsstats_offset(xs_xstrat_bytes)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Loop over all stats groups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) for (i = j = 0; i < ARRAY_SIZE(xstats); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) len += scnprintf(buf + len, PATH_MAX - len, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) xstats[i].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* inner loop does each group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) for (; j < xstats[i].endpoint; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) len += scnprintf(buf + len, PATH_MAX - len, " %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) counter_val(stats, j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) len += scnprintf(buf + len, PATH_MAX - len, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* extra precision counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) xs_xstrat_bytes += per_cpu_ptr(stats, i)->s.xs_xstrat_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) xs_write_bytes += per_cpu_ptr(stats, i)->s.xs_write_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) xs_read_bytes += per_cpu_ptr(stats, i)->s.xs_read_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) defer_relog += per_cpu_ptr(stats, i)->s.defer_relog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) len += scnprintf(buf + len, PATH_MAX-len, "xpc %Lu %Lu %Lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) xs_xstrat_bytes, xs_write_bytes, xs_read_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) len += scnprintf(buf + len, PATH_MAX-len, "defer_relog %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) defer_relog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) len += scnprintf(buf + len, PATH_MAX-len, "debug %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #if defined(DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void xfs_stats_clearall(struct xfsstats __percpu *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) uint32_t vn_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) xfs_notice(NULL, "Clearing xfsstats");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) for_each_possible_cpu(c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* save vn_active, it's a universal truth! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) vn_active = per_cpu_ptr(stats, c)->s.vn_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) per_cpu_ptr(stats, c)->s.vn_active = vn_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* legacy quota interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #ifdef CONFIG_XFS_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define XFSSTAT_START_XQMSTAT xfsstats_offset(xs_qm_dqreclaims)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define XFSSTAT_END_XQMSTAT xfsstats_offset(xs_qm_dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int xqm_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* maximum; incore; ratio free to inuse; freelist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) seq_printf(m, "%d\t%d\t%d\t%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* legacy quota stats interface no 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int xqmstat_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) seq_printf(m, "qm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #endif /* CONFIG_XFS_QUOTA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) xfs_init_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!proc_mkdir("fs/xfs", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!proc_symlink("fs/xfs/stat", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) "/sys/fs/xfs/stats/stats"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #ifdef CONFIG_XFS_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!proc_create_single("fs/xfs/xqmstat", 0, NULL, xqmstat_proc_show))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!proc_create_single("fs/xfs/xqm", 0, NULL, xqm_proc_show))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) remove_proc_subtree("fs/xfs", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) xfs_cleanup_procfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) remove_proc_subtree("fs/xfs", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #endif /* CONFIG_PROC_FS */