1 Index: linux-4.4/fs/ext4/mballoc.c
2 ===================================================================
3 --- linux-4.4.orig/fs/ext4/mballoc.c
4 +++ linux-4.4/fs/ext4/mballoc.c
5 @@ -2483,6 +2483,77 @@ static struct kmem_cache *get_groupinfo_
9 +#define EXT4_MB_MAX_INPUT_STRING_SIZE 32
11 +static ssize_t ext4_mb_last_group_write(struct file *file,
12 + const char __user *buf,
13 + size_t cnt, loff_t *pos)
15 + char dummy[EXT4_MB_MAX_INPUT_STRING_SIZE + 1];
16 + struct super_block *sb = PDE_DATA(file_inode(file));
17 + struct ext4_sb_info *sbi = EXT4_SB(sb);
21 + if (cnt > EXT4_MB_MAX_INPUT_STRING_SIZE)
23 + if (copy_from_user(dummy, buf, cnt))
26 + val = simple_strtoul(dummy, &end, 0);
29 + if (val >= ext4_get_groups_count(sb))
31 + spin_lock(&sbi->s_md_lock);
32 + sbi->s_mb_last_group = val;
33 + sbi->s_mb_last_start = 0;
34 + spin_unlock(&sbi->s_md_lock);
38 +static int ext4_mb_seq_last_group_seq_show(struct seq_file *m, void *v)
40 + struct ext4_sb_info *sbi = EXT4_SB(m->private);
42 + seq_printf(m , "%ld\n", sbi->s_mb_last_group);
46 +static int ext4_mb_seq_last_group_open(struct inode *inode, struct file *file)
48 + return single_open(file, ext4_mb_seq_last_group_seq_show, PDE_DATA(inode));
51 +const struct file_operations ext4_seq_mb_last_group_fops = {
52 + .owner = THIS_MODULE,
53 + .open = ext4_mb_seq_last_group_open,
55 + .llseek = seq_lseek,
56 + .release = seq_release,
57 + .write = ext4_mb_last_group_write,
60 +static int ext4_mb_seq_last_start_seq_show(struct seq_file *m, void *v)
62 + struct ext4_sb_info *sbi = EXT4_SB(m->private);
64 + seq_printf(m , "%ld\n", sbi->s_mb_last_start);
68 +static int ext4_mb_seq_last_start_open(struct inode *inode, struct file *file)
70 + return single_open(file, ext4_mb_seq_last_start_seq_show, PDE_DATA(inode));
72 +const struct file_operations ext4_seq_mb_last_start_fops = {
73 + .owner = THIS_MODULE,
74 + .open = ext4_mb_seq_last_start_open,
76 + .llseek = seq_lseek,
77 + .release = seq_release,
81 * Allocate the top-level s_group_info array for the specified number
83 Index: linux-4.4/fs/ext4/ext4.h
84 ===================================================================
85 --- linux-4.4.orig/fs/ext4/ext4.h
86 +++ linux-4.4/fs/ext4/ext4.h
87 @@ -2595,6 +2595,8 @@ extern void ext4_end_bitmap_read(struct
89 extern const struct file_operations ext4_seq_prealloc_table_fops;
90 extern const struct file_operations ext4_seq_mb_groups_fops;
91 +extern const struct file_operations ext4_seq_mb_last_group_fops;
92 +extern const struct file_operations ext4_seq_mb_last_start_fops;
93 extern long ext4_mb_stats;
94 extern long ext4_mb_max_to_scan;
95 extern int ext4_mb_init(struct super_block *);
96 Index: linux-4.4/fs/ext4/sysfs.c
97 ===================================================================
98 --- linux-4.4.orig/fs/ext4/sysfs.c
99 +++ linux-4.4/fs/ext4/sysfs.c
100 @@ -396,6 +396,8 @@ static struct ext4_proc_files {
101 PROC_FILE_LIST(es_shrinker_info),
102 PROC_FILE_LIST(mb_groups),
103 PROC_FILE_LIST(prealloc_table),
104 + PROC_FILE_LIST(mb_last_group),
105 + PROC_FILE_LIST(mb_last_start),