Skip to content

Commit f68f406

Browse files
harshadjstytso
authored andcommitted
ext4: add proc files to monitor new structures
This patch adds a new file "mb_structs_summary" which allows us to see the summary of the new allocator structures added in this series. Here's the sample output of file: optimize_scan: 1 max_free_order_lists: list_order_0_groups: 0 list_order_1_groups: 0 list_order_2_groups: 0 list_order_3_groups: 0 list_order_4_groups: 0 list_order_5_groups: 0 list_order_6_groups: 0 list_order_7_groups: 0 list_order_8_groups: 0 list_order_9_groups: 0 list_order_10_groups: 0 list_order_11_groups: 0 list_order_12_groups: 0 list_order_13_groups: 40 fragment_size_tree: tree_min: 16384 tree_max: 32768 tree_nodes: 40 Signed-off-by: Harshad Shirwadkar <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 196e402 commit f68f406

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

fs/ext4/ext4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,7 @@ int __init ext4_fc_init_dentry_cache(void);
28722872

28732873
/* mballoc.c */
28742874
extern const struct seq_operations ext4_mb_seq_groups_ops;
2875+
extern const struct seq_operations ext4_mb_seq_structs_summary_ops;
28752876
extern long ext4_mb_stats;
28762877
extern long ext4_mb_max_to_scan;
28772878
extern int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset);

fs/ext4/mballoc.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,92 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
29632963
return 0;
29642964
}
29652965

2966+
static void *ext4_mb_seq_structs_summary_start(struct seq_file *seq, loff_t *pos)
2967+
{
2968+
struct super_block *sb = PDE_DATA(file_inode(seq->file));
2969+
unsigned long position;
2970+
2971+
read_lock(&EXT4_SB(sb)->s_mb_rb_lock);
2972+
2973+
if (*pos < 0 || *pos >= MB_NUM_ORDERS(sb) + 1)
2974+
return NULL;
2975+
position = *pos + 1;
2976+
return (void *) ((unsigned long) position);
2977+
}
2978+
2979+
static void *ext4_mb_seq_structs_summary_next(struct seq_file *seq, void *v, loff_t *pos)
2980+
{
2981+
struct super_block *sb = PDE_DATA(file_inode(seq->file));
2982+
unsigned long position;
2983+
2984+
++*pos;
2985+
if (*pos < 0 || *pos >= MB_NUM_ORDERS(sb) + 1)
2986+
return NULL;
2987+
position = *pos + 1;
2988+
return (void *) ((unsigned long) position);
2989+
}
2990+
2991+
static int ext4_mb_seq_structs_summary_show(struct seq_file *seq, void *v)
2992+
{
2993+
struct super_block *sb = PDE_DATA(file_inode(seq->file));
2994+
struct ext4_sb_info *sbi = EXT4_SB(sb);
2995+
unsigned long position = ((unsigned long) v);
2996+
struct ext4_group_info *grp;
2997+
struct rb_node *n;
2998+
unsigned int count, min, max;
2999+
3000+
position--;
3001+
if (position >= MB_NUM_ORDERS(sb)) {
3002+
seq_puts(seq, "fragment_size_tree:\n");
3003+
n = rb_first(&sbi->s_mb_avg_fragment_size_root);
3004+
if (!n) {
3005+
seq_puts(seq, "\ttree_min: 0\n\ttree_max: 0\n\ttree_nodes: 0\n");
3006+
return 0;
3007+
}
3008+
grp = rb_entry(n, struct ext4_group_info, bb_avg_fragment_size_rb);
3009+
min = grp->bb_fragments ? grp->bb_free / grp->bb_fragments : 0;
3010+
count = 1;
3011+
while (rb_next(n)) {
3012+
count++;
3013+
n = rb_next(n);
3014+
}
3015+
grp = rb_entry(n, struct ext4_group_info, bb_avg_fragment_size_rb);
3016+
max = grp->bb_fragments ? grp->bb_free / grp->bb_fragments : 0;
3017+
3018+
seq_printf(seq, "\ttree_min: %u\n\ttree_max: %u\n\ttree_nodes: %u\n",
3019+
min, max, count);
3020+
return 0;
3021+
}
3022+
3023+
if (position == 0) {
3024+
seq_printf(seq, "optimize_scan: %d\n",
3025+
test_opt2(sb, MB_OPTIMIZE_SCAN) ? 1 : 0);
3026+
seq_puts(seq, "max_free_order_lists:\n");
3027+
}
3028+
count = 0;
3029+
list_for_each_entry(grp, &sbi->s_mb_largest_free_orders[position],
3030+
bb_largest_free_order_node)
3031+
count++;
3032+
seq_printf(seq, "\tlist_order_%u_groups: %u\n",
3033+
(unsigned int)position, count);
3034+
3035+
return 0;
3036+
}
3037+
3038+
static void ext4_mb_seq_structs_summary_stop(struct seq_file *seq, void *v)
3039+
{
3040+
struct super_block *sb = PDE_DATA(file_inode(seq->file));
3041+
3042+
read_unlock(&EXT4_SB(sb)->s_mb_rb_lock);
3043+
}
3044+
3045+
const struct seq_operations ext4_mb_seq_structs_summary_ops = {
3046+
.start = ext4_mb_seq_structs_summary_start,
3047+
.next = ext4_mb_seq_structs_summary_next,
3048+
.stop = ext4_mb_seq_structs_summary_stop,
3049+
.show = ext4_mb_seq_structs_summary_show,
3050+
};
3051+
29663052
static struct kmem_cache *get_groupinfo_cache(int blocksize_bits)
29673053
{
29683054
int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE;

fs/ext4/sysfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ int ext4_register_sysfs(struct super_block *sb)
534534
&ext4_mb_seq_groups_ops, sb);
535535
proc_create_single_data("mb_stats", 0444, sbi->s_proc,
536536
ext4_seq_mb_stats_show, sb);
537+
proc_create_seq_data("mb_structs_summary", 0444, sbi->s_proc,
538+
&ext4_mb_seq_structs_summary_ops, sb);
537539
}
538540
return 0;
539541
}

0 commit comments

Comments
 (0)