1 Index: linux-stage/fs/ext4/super.c
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/super.c
4 +++ linux-stage/fs/ext4/super.c
5 @@ -690,7 +690,12 @@ static void ext4_put_super(struct super_
7 for (i = 0; i < sbi->s_gdb_count; i++)
8 brelse(sbi->s_group_desc[i]);
9 - kfree(sbi->s_group_desc);
11 + if (is_vmalloc_addr(sbi->s_group_desc))
12 + vfree(sbi->s_group_desc);
14 + kfree(sbi->s_group_desc);
16 if (is_vmalloc_addr(sbi->s_flex_groups))
17 vfree(sbi->s_flex_groups);
19 @@ -2938,12 +2943,13 @@ static int ext4_fill_super(struct super_
20 unsigned long offset = 0;
21 unsigned long journal_devnum = 0;
22 unsigned long def_mount_opts;
24 + struct inode *root = NULL;
29 unsigned int db_count;
32 int needs_recovery, has_huge_files;
34 @@ -3286,11 +3292,18 @@ static int ext4_fill_super(struct super_
35 (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
36 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
37 EXT4_DESC_PER_BLOCK(sb);
38 - sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
40 + size = (size_t)db_count * sizeof(struct buffer_head *);
41 + sbi->s_group_desc = kzalloc(size, GFP_KERNEL);
42 if (sbi->s_group_desc == NULL) {
43 - ext4_msg(sb, KERN_ERR, "not enough memory");
45 + sbi->s_group_desc = vmalloc(size);
46 + if (sbi->s_group_desc != NULL) {
47 + memset(sbi->s_group_desc, 0, size);
49 + ext4_msg(sb, KERN_ERR, "no memory for %u groups (%u)\n",
50 + sbi->s_groups_count, (unsigned int)size);
57 @@ -3505,12 +3518,10 @@ no_journal:
59 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
60 ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
64 sb->s_root = d_alloc_root(root);
67 ext4_msg(sb, KERN_ERR, "get root dentry failed");
70 @@ -3562,6 +3573,7 @@ no_journal:
72 ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)",
78 @@ -3616,6 +3628,8 @@ failed_mount4a:
84 ext4_msg(sb, KERN_ERR, "mount failed");
85 destroy_workqueue(EXT4_SB(sb)->dio_unwritten_wq);
87 @@ -3639,7 +3653,11 @@ failed_mount3:
89 for (i = 0; i < db_count; i++)
90 brelse(sbi->s_group_desc[i]);
91 - kfree(sbi->s_group_desc);
93 + if (is_vmalloc_addr(sbi->s_group_desc))
94 + vfree(sbi->s_group_desc);
96 + kfree(sbi->s_group_desc);
99 remove_proc_entry(sb->s_id, ext4_proc_root);
100 Index: linux-stage/fs/ext4/mballoc.c
101 ===================================================================
102 --- linux-stage.orig/fs/ext4/mballoc.c
103 +++ linux-stage/fs/ext4/mballoc.c
107 #include <linux/debugfs.h>
108 +#include <linux/vmalloc.h>
109 #include <trace/events/ext4.h>
112 @@ -2408,24 +2409,37 @@ static int ext4_mb_init_backend(struct s
113 while (array_size < sizeof(*sbi->s_group_info) *
114 num_meta_group_infos_max)
115 array_size = array_size << 1;
116 - /* An 8TB filesystem with 64-bit pointers requires a 4096 byte
117 - * kmalloc. A 128kb malloc should suffice for a 256TB filesystem.
118 - * So a two level scheme suffices for now. */
119 - sbi->s_group_info = kmalloc(array_size, GFP_KERNEL);
120 + /* A 16TB filesystem with 64-bit pointers requires an 8192 byte
121 + * kmalloc(). Filesystems larger than 2^32 blocks (16TB normally)
122 + * have group descriptors at least twice as large (64 bytes or
123 + * more vs. 32 bytes for traditional ext3 filesystems), so a 128TB
124 + * filesystem needs a 128kB allocation, which may need vmalloc(). */
125 + sbi->s_group_info = kzalloc(array_size, GFP_KERNEL);
126 if (sbi->s_group_info == NULL) {
127 - printk(KERN_ERR "EXT4-fs: can't allocate buddy meta group\n");
129 + sbi->s_group_info = vmalloc(array_size);
130 + if (sbi->s_group_info != NULL) {
131 + memset(sbi->s_group_info, 0, array_size);
133 + ext4_msg(sb, KERN_ERR, "no memory for groupinfo (%u)\n",
138 sbi->s_buddy_cache = new_inode(sb);
139 if (sbi->s_buddy_cache == NULL) {
140 - printk(KERN_ERR "EXT4-fs: can't get new inode\n");
141 + ext4_msg(sb, KERN_ERR, "can't get new inode\n");
144 + /* To avoid potentially colliding with an valid on-disk inode number,
145 + * use EXT4_BAD_INO for the buddy cache inode number. This inode is
146 + * not in the inode hash, so it should never be found by iget(), but
147 + * this will avoid confusion if it ever shows up during debugging. */
148 + sbi->s_buddy_cache->i_ino = EXT4_BAD_INO;
149 EXT4_I(sbi->s_buddy_cache)->i_disksize = 0;
150 for (i = 0; i < ngroups; i++) {
151 desc = ext4_get_group_desc(sb, i, NULL);
154 + ext4_msg(sb, KERN_ERR,
155 "EXT4-fs: can't read descriptor %u\n", i);
158 @@ -2443,7 +2457,10 @@ err_freebuddy:
159 kfree(sbi->s_group_info[i]);
160 iput(sbi->s_buddy_cache);
162 - kfree(sbi->s_group_info);
163 + if (is_vmalloc_addr(sbi->s_group_info))
164 + vfree(sbi->s_group_info);
166 + kfree(sbi->s_group_info);
170 @@ -2627,7 +2644,10 @@ int ext4_mb_release(struct super_block *
171 EXT4_DESC_PER_BLOCK_BITS(sb);
172 for (i = 0; i < num_meta_group_infos; i++)
173 kfree(sbi->s_group_info[i]);
174 - kfree(sbi->s_group_info);
175 + if (is_vmalloc_addr(sbi->s_group_info))
176 + vfree(sbi->s_group_info);
178 + kfree(sbi->s_group_info);
180 kfree(sbi->s_mb_prealloc_table);
181 kfree(sbi->s_mb_offsets);