1 Index: linux-stage/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/ext4.h 2011-03-14 16:18:28.300241437 +0800
4 +++ linux-stage/fs/ext4/ext4.h 2011-03-14 16:33:17.056087375 +0800
6 ext4_grpblk_t bb_free; /* total free blocks */
7 ext4_grpblk_t bb_fragments; /* nr of freespace fragments */
8 struct list_head bb_prealloc_list;
9 + unsigned long bb_prealloc_nr;
13 Index: linux-stage/fs/ext4/mballoc.c
14 ===================================================================
15 --- linux-stage.orig/fs/ext4/mballoc.c 2011-03-14 16:18:28.336242149 +0800
16 +++ linux-stage/fs/ext4/mballoc.c 2011-03-14 16:33:27.072292006 +0800
18 static struct kmem_cache *ext4_pspace_cachep;
19 static struct kmem_cache *ext4_ac_cachep;
20 static struct kmem_cache *ext4_free_ext_cachep;
21 -static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
22 +static int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
24 static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
29 static noinline_for_stack
30 -void ext4_mb_generate_buddy(struct super_block *sb,
31 +int ext4_mb_generate_buddy(struct super_block *sb,
32 void *buddy, void *bitmap, ext4_group_t group)
34 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
36 grp->bb_fragments = fragments;
38 if (free != grp->bb_free) {
39 - ext4_grp_locked_error(sb, group, __func__,
40 - "EXT4-fs: group %u: %u blocks in bitmap, %u in gd",
41 - group, free, grp->bb_free);
43 - * If we intent to continue, we consider group descritor
44 - * corrupt and update bb_free using bitmap value
46 - grp->bb_free = free;
47 + struct ext4_group_desc *gdp;
48 + gdp = ext4_get_group_desc (sb, group, NULL);
49 + ext4_error(sb, "group %lu: %u blocks in bitmap, %u in bb, "
50 + "%u in gd, %lu pa's\n", (long unsigned int)group,
51 + free, grp->bb_free, ext4_free_blks_count(sb, gdp),
52 + grp->bb_prealloc_nr);
56 clear_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state));
58 EXT4_SB(sb)->s_mb_buddies_generated++;
59 EXT4_SB(sb)->s_mb_generation_time += period;
60 spin_unlock(&EXT4_SB(sb)->s_bal_lock);
65 /* The buddy information is attached the buddy cache inode
67 first_block = page->index * blocks_per_page;
69 memset(page_address(page), 0xff, PAGE_CACHE_SIZE);
70 - for (i = 0; i < blocks_per_page; i++) {
71 + for (i = 0; i < blocks_per_page && err == 0; i++) {
73 struct ext4_group_info *grinfo;
76 * incore got set to the group block bitmap below
78 ext4_lock_group(sb, group);
79 - ext4_mb_generate_buddy(sb, data, incore, group);
80 + err = ext4_mb_generate_buddy(sb, data, incore, group);
81 ext4_unlock_group(sb, group);
85 memcpy(data, bitmap, blocksize);
87 /* mark all preallocated blks used in in-core bitmap */
88 - ext4_mb_generate_from_pa(sb, data, group);
89 + err = ext4_mb_generate_from_pa(sb, data, group);
90 ext4_mb_generate_from_freelist(sb, data, group);
91 ext4_unlock_group(sb, group);
97 - SetPageUptodate(page);
98 + if (likely(err == 0))
99 + SetPageUptodate(page);
103 @@ -2142,9 +2144,11 @@
104 static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
106 struct super_block *sb = seq->private;
107 + struct ext4_group_desc *gdp;
108 ext4_group_t group = (ext4_group_t) ((unsigned long) v);
112 struct ext4_buddy e4b;
114 struct ext4_group_info info;
115 @@ -2153,10 +2157,10 @@
119 - seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
120 + seq_printf(seq, "#%-5s: %-5s %-5s %-5s %-5s %-5s"
121 "[ %-5s %-5s %-5s %-5s %-5s %-5s %-5s "
122 "%-5s %-5s %-5s %-5s %-5s %-5s %-5s ]\n",
123 - "group", "free", "frags", "first",
124 + "group", "free", "frags", "first", "first", "pa",
125 "2^0", "2^1", "2^2", "2^3", "2^4", "2^5", "2^6",
126 "2^7", "2^8", "2^9", "2^10", "2^11", "2^12", "2^13");
128 @@ -2167,13 +2171,20 @@
129 seq_printf(seq, "#%-5u: I/O error\n", group);
133 + gdp = ext4_get_group_desc(sb, group, NULL);
135 + free = ext4_free_blks_count(sb, gdp);
137 ext4_lock_group(sb, group);
138 memcpy(&sg, ext4_get_group_info(sb, group), i);
139 ext4_unlock_group(sb, group);
140 ext4_mb_release_desc(&e4b);
142 - seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
143 - sg.info.bb_fragments, sg.info.bb_first_free);
144 + seq_printf(seq, "#%-5lu: %-5u %-5u %-5u %-5u %-5lu [",
145 + (long unsigned int)group, sg.info.bb_free, free,
146 + sg.info.bb_fragments, sg.info.bb_first_free,
147 + sg.info.bb_prealloc_nr);
148 for (i = 0; i <= 13; i++)
149 seq_printf(seq, " %-5u", i <= sb->s_blocksize_bits + 1 ?
150 sg.info.bb_counters[i] : 0);
151 @@ -3354,23 +3365,68 @@
155 + * check free blocks in bitmap match free block in group descriptor
156 + * do this before taking preallocated blocks into account to be able
157 + * to detect on-disk corruptions. The group lock should be hold by the
160 +int ext4_mb_check_ondisk_bitmap(struct super_block *sb, void *bitmap,
161 + struct ext4_group_desc *gdp, int group)
163 + unsigned short max = EXT4_BLOCKS_PER_GROUP(sb);
164 + unsigned short i, first, free = 0;
166 + i = mb_find_next_zero_bit(bitmap, max, 0);
170 + i = mb_find_next_bit(bitmap, max, i);
175 + i = mb_find_next_zero_bit(bitmap, max, i);
178 + if (free != ext4_free_blks_count(sb, gdp)) {
179 + ext4_error(sb, "on-disk bitmap for group %d"
180 + "corrupted: %u blocks free in bitmap, %u - in gd\n",
181 + group, free, ext4_free_blks_count(sb, gdp));
188 * the function goes through all preallocation in this group and marks them
189 * used in in-core bitmap. buddy must be generated from this bitmap
190 * Need to be called with ext4 group lock held
192 static noinline_for_stack
193 -void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
194 +int ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
197 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
198 struct ext4_prealloc_space *pa;
199 + struct ext4_group_desc *gdp;
200 struct list_head *cur;
201 ext4_group_t groupnr;
203 int preallocated = 0;
209 + gdp = ext4_get_group_desc (sb, group, NULL);
213 + /* before applying preallocations, check bitmap consistency */
214 + err = ext4_mb_check_ondisk_bitmap(sb, bitmap, gdp, group);
218 /* all form of preallocation discards first load group,
219 * so the only competing code is preallocation use.
220 * we don't need any locking here
221 @@ -3386,14 +3442,23 @@
224 spin_unlock(&pa->pa_lock);
225 - if (unlikely(len == 0))
226 + if (unlikely(len == 0)) {
230 BUG_ON(groupnr != group);
231 mb_set_bits(bitmap, start, len);
235 + if (count + skip != grp->bb_prealloc_nr) {
236 + ext4_error(sb, "lost preallocations: "
237 + "count %d, bb_prealloc_nr %lu, skip %d\n",
238 + count, grp->bb_prealloc_nr, skip);
241 mb_debug(1, "prellocated %u for group %u\n", preallocated, group);
245 static void ext4_mb_pa_callback(struct rcu_head *head)
246 @@ -3452,6 +3517,7 @@
248 ext4_lock_group(sb, grp);
249 list_del(&pa->pa_group_list);
250 + ext4_get_group_info(sb, grp)->bb_prealloc_nr--;
251 ext4_unlock_group(sb, grp);
253 spin_lock(pa->pa_obj_lock);
254 @@ -3543,6 +3609,7 @@
256 ext4_lock_group(sb, ac->ac_b_ex.fe_group);
257 list_add(&pa->pa_group_list, &grp->bb_prealloc_list);
258 + grp->bb_prealloc_nr++;
259 ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
261 spin_lock(pa->pa_obj_lock);
262 @@ -3604,6 +3671,7 @@
264 ext4_lock_group(sb, ac->ac_b_ex.fe_group);
265 list_add(&pa->pa_group_list, &grp->bb_prealloc_list);
266 + grp->bb_prealloc_nr++;
267 ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
270 @@ -3802,6 +3870,8 @@
272 spin_unlock(&pa->pa_lock);
274 + BUG_ON(grp->bb_prealloc_nr == 0);
275 + grp->bb_prealloc_nr--;
276 list_del(&pa->pa_group_list);
277 list_add(&pa->u.pa_tmp_list, &list);
279 @@ -3942,7 +4012,7 @@
281 ext4_error(sb, "Error loading buddy information for %u",
287 bitmap_bh = ext4_read_block_bitmap(sb, group);
288 @@ -3954,6 +4024,8 @@
291 ext4_lock_group(sb, group);
292 + BUG_ON(e4b.bd_info->bb_prealloc_nr == 0);
293 + e4b.bd_info->bb_prealloc_nr--;
294 list_del(&pa->pa_group_list);
295 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
296 ext4_unlock_group(sb, group);
297 @@ -4227,6 +4299,7 @@
299 ext4_lock_group(sb, group);
300 list_del(&pa->pa_group_list);
301 + ext4_get_group_info(sb, group)->bb_prealloc_nr--;
302 ext4_mb_release_group_pa(&e4b, pa, ac);
303 ext4_unlock_group(sb, group);
305 Index: linux-stage/fs/ext4/mballoc.h
306 ===================================================================
307 --- linux-stage.orig/fs/ext4/mballoc.h 2011-03-14 16:18:26.670209322 +0800
308 +++ linux-stage/fs/ext4/mballoc.h 2011-03-14 16:32:50.859552482 +0800
311 * for which requests use 2^N search using buddies
313 -#define MB_DEFAULT_ORDER2_REQS 2
314 +#define MB_DEFAULT_ORDER2_REQS 8
317 * default group prealloc size 512 blocks