1 Index: linux-2.6.27.21-0.1/fs/ext4/mballoc.c
2 ===================================================================
3 --- linux-2.6.27.21-0.1.orig/fs/ext4/mballoc.c
4 +++ linux-2.6.27.21-0.1/fs/ext4/mballoc.c
6 static struct kmem_cache *ext4_pspace_cachep;
7 static struct kmem_cache *ext4_ac_cachep;
8 static struct kmem_cache *ext4_free_ext_cachep;
9 -static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
10 +static int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
12 static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
14 @@ -672,7 +672,7 @@ static void ext4_mb_mark_free_simple(str
17 static noinline_for_stack
18 -void ext4_mb_generate_buddy(struct super_block *sb,
19 +int ext4_mb_generate_buddy(struct super_block *sb,
20 void *buddy, void *bitmap, ext4_group_t group)
22 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
23 @@ -704,14 +704,13 @@ static void ext4_mb_generate_buddy(struc
24 grp->bb_fragments = fragments;
26 if (free != grp->bb_free) {
27 - ext4_grp_locked_error(sb, group, __func__,
28 - "EXT4-fs: group %u: %u blocks in bitmap, %u in gd",
29 - group, free, grp->bb_free);
31 - * If we intent to continue, we consider group descritor
32 - * corrupt and update bb_free using bitmap value
34 - grp->bb_free = free;
35 + struct ext4_group_desc *gdp;
36 + gdp = ext4_get_group_desc (sb, group, NULL);
37 + ext4_grp_locked_error(sb, group, __func__,
38 + "group %u: %u blocks in bitmap, %u in bb, "
39 + "%u in gd\n", group, free, grp->bb_free,
40 + ext4_free_blks_count(sb, gdp));
44 clear_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state));
45 @@ -721,6 +720,8 @@ static void ext4_mb_generate_buddy(struc
46 EXT4_SB(sb)->s_mb_buddies_generated++;
47 EXT4_SB(sb)->s_mb_generation_time += period;
48 spin_unlock(&EXT4_SB(sb)->s_bal_lock);
53 /* The buddy information is attached the buddy cache inode
54 @@ -850,7 +851,7 @@ static int ext4_mb_init_cache(struct pag
55 first_block = page->index * blocks_per_page;
57 memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
58 - for (i = 0; i < blocks_per_page; i++) {
59 + for (i = 0; i < blocks_per_page && err == 0; i++) {
61 struct ext4_group_info *grinfo;
63 @@ -884,7 +885,7 @@ static int ext4_mb_init_cache(struct pag
64 * incore got set to the group block bitmap below
66 ext4_lock_group(sb, group);
67 - ext4_mb_generate_buddy(sb, data, incore, group);
68 + err = ext4_mb_generate_buddy(sb, data, incore, group);
69 ext4_unlock_group(sb, group);
72 @@ -898,7 +899,7 @@ static int ext4_mb_init_cache(struct pag
73 memcpy(data, bitmap, blocksize);
75 /* mark all preallocated blks used in in-core bitmap */
76 - ext4_mb_generate_from_pa(sb, data, group);
77 + err = ext4_mb_generate_from_pa(sb, data, group);
78 ext4_mb_generate_from_freelist(sb, data, group);
79 ext4_unlock_group(sb, group);
81 @@ -908,6 +909,7 @@ static int ext4_mb_init_cache(struct pag
85 + if (likely(err == 0))
86 SetPageUptodate(page);
89 @@ -2345,9 +2350,11 @@ static void *ext4_mb_seq_groups_next(str
90 static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
92 struct super_block *sb = seq->private;
93 + struct ext4_group_desc *gdp;
94 ext4_group_t group = (ext4_group_t) ((unsigned long) v);
98 struct ext4_buddy e4b;
100 struct ext4_group_info info;
101 @@ -2356,10 +2363,10 @@ static int ext4_mb_seq_groups_show(struc
105 - seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
106 + seq_printf(seq, "#%-5s: %-5s %-5s %-5s %-5s %-5s"
107 "[ %-5s %-5s %-5s %-5s %-5s %-5s %-5s "
108 "%-5s %-5s %-5s %-5s %-5s %-5s %-5s ]\n",
109 - "group", "free", "frags", "first",
110 + "group", "free", "frags", "first", "first", "pa",
111 "2^0", "2^1", "2^2", "2^3", "2^4", "2^5", "2^6",
112 "2^7", "2^8", "2^9", "2^10", "2^11", "2^12", "2^13");
114 @@ -2371,12 +2378,18 @@ static int ext4_mb_seq_groups_show(struc
115 seq_printf(seq, "#%-5u: I/O error\n", group);
119 + gdp = ext4_get_group_desc(sb, group, NULL);
121 + free = ext4_free_blks_count(sb, gdp);
123 ext4_lock_group(sb, group);
124 memcpy(&sg, ext4_get_group_info(sb, group), i);
125 ext4_unlock_group(sb, group);
126 ext4_mb_unload_buddy(&e4b);
128 - seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
129 + seq_printf(seq, "#%-5u: %-5u %-5u %-5u %-5u [", group,
130 + sg.info.bb_free, free,
131 sg.info.bb_fragments, sg.info.bb_first_free);
132 for (i = 0; i <= 13; i++)
133 seq_printf(seq, " %-5u", i <= sb->s_blocksize_bits + 1 ?
134 @@ -3695,23 +3709,68 @@ static void ext4_mb_generate_from_freeli
138 + * check free blocks in bitmap match free block in group descriptor
139 + * do this before taking preallocated blocks into account to be able
140 + * to detect on-disk corruptions. The group lock should be hold by the
143 +int ext4_mb_check_ondisk_bitmap(struct super_block *sb, void *bitmap,
144 + struct ext4_group_desc *gdp, int group)
146 + unsigned short max = EXT4_BLOCKS_PER_GROUP(sb);
147 + unsigned short i, first, free = 0;
149 + i = mb_find_next_zero_bit(bitmap, max, 0);
153 + i = mb_find_next_bit(bitmap, max, i);
158 + i = mb_find_next_zero_bit(bitmap, max, i);
161 + if (free != ext4_free_blks_count(sb, gdp)) {
162 + ext4_error(sb, __FUNCTION__, "on-disk bitmap for group %d"
163 + "corrupted: %u blocks free in bitmap, %u - in gd\n",
164 + group, free, ext4_free_blks_count(sb, gdp));
171 * the function goes through all preallocation in this group and marks them
172 * used in in-core bitmap. buddy must be generated from this bitmap
173 * Need to be called with ext4 group lock held
175 static noinline_for_stack
176 -void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
177 +int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
180 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
181 struct ext4_prealloc_space *pa;
182 + struct ext4_group_desc *gdp;
183 struct list_head *cur;
184 ext4_group_t groupnr;
186 int preallocated = 0;
192 + gdp = ext4_get_group_desc (sb, group, NULL);
196 + /* before applying preallocations, check bitmap consistency */
197 + err = ext4_mb_check_ondisk_bitmap(sb, bitmap, gdp, group);
201 /* all form of preallocation discards first load group,
202 * so the only competing code is preallocation use.
203 * we don't need any locking here
204 @@ -3720,8 +3778,10 @@ static void ext4_mb_generate_from_pa(str
207 spin_unlock(&pa->pa_lock);
208 - if (unlikely(len == 0))
209 + if (unlikely(len == 0)) {
213 BUG_ON(groupnr != group);
214 mb_set_bits(bitmap, start, len);
216 @@ -3729,6 +3789,7 @@ static void ext4_mb_generate_from_pa(str
219 mb_debug(1, "prellocated %u for group %u\n", preallocated, group);
223 static void ext4_mb_pa_callback(struct rcu_head *head)
224 @@ -3978,6 +4039,7 @@ ext4_mb_release_inode_pa(struct ext4_bud
227 ac->ac_inode = pa->pa_inode;
228 + ac->ac_o_ex.fe_len = 1;
232 @@ -4260,7 +4322,7 @@ repeat:
234 ext4_error(sb, __func__, "Error in loading buddy "
235 "information for %u", group);
240 bitmap_bh = ext4_read_block_bitmap(sb, group);
241 Index: linux-2.6.27.21-0.1/fs/ext4/mballoc.h
242 ===================================================================
243 --- linux-2.6.27.21-0.1.orig/fs/ext4/mballoc.h
244 +++ linux-2.6.27.21-0.1/fs/ext4/mballoc.h
247 * for which requests use 2^N search using buddies
249 -#define MB_DEFAULT_ORDER2_REQS 2
250 +#define MB_DEFAULT_ORDER2_REQS 8
253 * default group prealloc size 512 blocks