1 Index: linux-2.6.16.46-0.14/include/linux/ext3_fs_i.h
2 ===================================================================
3 --- linux-2.6.16.46-0.14.orig/include/linux/ext3_fs_i.h
4 +++ linux-2.6.16.46-0.14/include/linux/ext3_fs_i.h
5 @@ -135,6 +135,10 @@ struct ext3_inode_info {
6 struct inode vfs_inode;
8 __u32 i_cached_extent[4];
11 + struct list_head i_prealloc_list;
12 + spinlock_t i_prealloc_lock;
15 #endif /* _LINUX_EXT3_FS_I */
16 Index: linux-2.6.16.46-0.14/include/linux/ext3_fs_sb.h
17 ===================================================================
18 --- linux-2.6.16.46-0.14.orig/include/linux/ext3_fs_sb.h
19 +++ linux-2.6.16.46-0.14/include/linux/ext3_fs_sb.h
21 #include <linux/wait.h>
22 #include <linux/blockgroup_lock.h>
23 #include <linux/percpu_counter.h>
24 +#include <linux/list.h>
26 #include <linux/rbtree.h>
27 +#include <linux/proc_fs.h>
29 +struct ext3_buddy_group_blocks;
30 +struct ext3_locality_group;
31 +struct ext3_mb_history;
32 +#define EXT3_BB_MAX_BLOCKS
35 * third extended-fs super-block data in memory
36 Index: linux-2.6.16.46-0.14/include/linux/ext3_fs.h
37 ===================================================================
38 --- linux-2.6.16.46-0.14.orig/include/linux/ext3_fs.h
39 +++ linux-2.6.16.46-0.14/include/linux/ext3_fs.h
40 @@ -407,6 +407,7 @@ struct ext3_inode {
41 #define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
42 #define EXT3_MOUNT_EXTENTS 0x1000000/* Extents support */
43 #define EXT3_MOUNT_EXTDEBUG 0x2000000/* Extents debug */
44 +#define EXT3_MOUNT_MBALLOC 0x4000000/* Buddy allocation support */
46 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
48 @@ -784,8 +785,9 @@ struct dir_private_info {
49 extern int ext3_bg_has_super(struct super_block *sb, int group);
50 extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
51 extern int ext3_new_block (handle_t *, struct inode *, unsigned long, int *);
52 +extern int ext3_new_block_old (handle_t *, struct inode *, unsigned long, int *);
53 extern void ext3_free_blocks (handle_t *, struct inode *, unsigned long,
55 + unsigned long, int);
56 extern void ext3_free_blocks_sb (handle_t *, struct super_block *,
57 unsigned long, unsigned long, int *);
58 extern unsigned long ext3_count_free_blocks (struct super_block *);
59 Index: linux-2.6.16.46-0.14/fs/ext3/super.c
60 ===================================================================
61 --- linux-2.6.16.46-0.14.orig/fs/ext3/super.c
62 +++ linux-2.6.16.46-0.14/fs/ext3/super.c
63 @@ -681,6 +681,7 @@ enum {
64 Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
66 Opt_extents, Opt_noextents, Opt_extdebug,
67 + Opt_mballoc, Opt_nomballoc, Opt_stripe,
70 static match_table_t tokens = {
71 @@ -740,6 +741,9 @@ static match_table_t tokens = {
72 {Opt_extents, "extents"},
73 {Opt_noextents, "noextents"},
74 {Opt_extdebug, "extdebug"},
75 + {Opt_mballoc, "mballoc"},
76 + {Opt_nomballoc, "nomballoc"},
77 + {Opt_stripe, "stripe=%u"},
79 {Opt_resize, "resize"},
81 @@ -1077,6 +1081,19 @@ clear_qf_name:
83 set_opt (sbi->s_mount_opt, EXTDEBUG);
86 + set_opt(sbi->s_mount_opt, MBALLOC);
89 + clear_opt(sbi->s_mount_opt, MBALLOC);
92 + if (match_int(&args[0], &option))
96 + sbi->s_stripe = option;
100 "EXT3-fs: Unrecognized mount option \"%s\" "
101 @@ -1858,7 +1858,7 @@ static int ext3_fill_super (struct super
102 ext3_count_dirs(sb));
106 + ext3_mb_init(sb, needs_recovery);
110 Index: linux-2.6.16.46-0.14/fs/ext3/extents.c
111 ===================================================================
112 --- linux-2.6.16.46-0.14.orig/fs/ext3/extents.c
113 +++ linux-2.6.16.46-0.14/fs/ext3/extents.c
114 @@ -819,7 +819,7 @@ cleanup:
115 for (i = 0; i < depth; i++) {
118 - ext3_free_blocks(handle, tree->inode, ablocks[i], 1);
119 + ext3_free_blocks(handle, tree->inode, ablocks[i], 1, 1);
123 @@ -1629,7 +1629,7 @@ int ext3_ext_rm_idx(handle_t *handle, st
124 path->p_idx->ei_leaf);
125 bh = sb_find_get_block(tree->inode->i_sb, path->p_idx->ei_leaf);
126 ext3_forget(handle, 1, tree->inode, bh, path->p_idx->ei_leaf);
127 - ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1);
128 + ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1, 1);
132 @@ -2128,10 +2128,12 @@ ext3_remove_blocks(struct ext3_extents_t
133 int needed = ext3_remove_blocks_credits(tree, ex, from, to);
134 handle_t *handle = ext3_journal_start(tree->inode, needed);
135 struct buffer_head *bh;
137 + int i, metadata = 0;
140 return PTR_ERR(handle);
141 + if (S_ISDIR(tree->inode->i_mode) || S_ISLNK(tree->inode->i_mode))
143 if (from >= ex->ee_block && to == ex->ee_block + ex->ee_len - 1) {
145 unsigned long num, start;
146 @@ -2143,7 +2145,7 @@ ext3_remove_blocks(struct ext3_extents_t
147 bh = sb_find_get_block(tree->inode->i_sb, start + i);
148 ext3_forget(handle, 0, tree->inode, bh, start + i);
150 - ext3_free_blocks(handle, tree->inode, start, num);
151 + ext3_free_blocks(handle, tree->inode, start, num, metadata);
152 } else if (from == ex->ee_block && to <= ex->ee_block + ex->ee_len - 1) {
153 printk("strange request: removal %lu-%lu from %u:%u\n",
154 from, to, ex->ee_block, ex->ee_len);
155 @@ -2234,11 +2236,8 @@ int ext3_ext_get_block(handle_t *handle,
156 struct ext3_extent *ex;
157 int goal, newblock, err = 0, depth;
158 struct ext3_extents_tree tree;
159 - unsigned long next;
162 - /* until we have multiblock allocation */
164 + unsigned long allocated = 0;
165 + struct ext3_allocation_request ar;
167 clear_buffer_new(bh_result);
168 ext3_init_tree_desc(&tree, inode);
169 @@ -2310,18 +2309,36 @@ int ext3_ext_get_block(handle_t *handle,
173 + /* find neighbour allocated blocks */
175 + err = ext3_ext_search_left(&tree, path, &ar.lleft, &ar.pleft);
178 + ar.lright = iblock;
179 + err = ext3_ext_search_right(&tree, path, &ar.lright, &ar.pright);
183 /* find next allocated block so that we know how many
184 * blocks we can allocate without ovelapping next extent */
185 - EXT_ASSERT(iblock >= ex->ee_block + ex->ee_len);
186 - next = ext3_ext_next_allocated_block(path);
187 - EXT_ASSERT(next > iblock);
188 - allocated = next - iblock;
189 + EXT_ASSERT(ar.pright == 0 || ar.lright > iblock);
190 + if (ar.pright == 0)
191 + allocated = EXT_MAX_BLOCK - iblock;
193 + allocated = ar.lright - iblock;
194 if (allocated > max_blocks)
195 allocated = max_blocks;
197 /* allocate new block */
198 - goal = ext3_ext_find_goal(inode, path, iblock);
199 - newblock = ext3_new_block(handle, inode, goal, &err);
201 + ar.goal = ext3_ext_find_goal(inode, path, iblock);
202 + ar.logical = iblock;
203 + ar.len = allocated;
204 + if (S_ISREG(inode->i_mode))
205 + ar.flags = EXT3_MB_HINT_DATA;
208 + newblock = ext3_mb_new_blocks(handle, &ar, &err);
211 ext_debug(&tree, "allocate new block: goal %d, found %d\n",
212 @@ -2331,11 +2348,14 @@ int ext3_ext_get_block(handle_t *handle,
213 newex.ee_block = iblock;
214 newex.ee_start = newblock;
215 newex.ee_start_hi = 0;
217 + newex.ee_len = ar.len;
218 err = ext3_ext_insert_extent(handle, &tree, path, &newex);
220 /* free data blocks we just allocated */
221 - ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len);
222 + /* not a good idea to call discard here directly,
223 + * but otherwise we'd need to call it every free() */
224 + ext3_mb_discard_inode_preallocations(inode);
225 + ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len, 0);
229 @@ -2344,6 +2364,7 @@ int ext3_ext_get_block(handle_t *handle,
231 /* previous routine could use block we allocated */
232 newblock = newex.ee_start;
233 + allocated = newex.ee_len;
234 set_buffer_new(bh_result);
236 ext3_ext_put_in_cache(&tree, newex.ee_block, newex.ee_len,
237 @@ -2396,6 +2417,9 @@ void ext3_ext_truncate(struct inode * in
238 down(&EXT3_I(inode)->truncate_sem);
239 ext3_ext_invalidate_cache(&tree);
241 + /* it's important to discard preallocations under truncate_sem */
242 + ext3_mb_discard_inode_preallocations(inode);
245 * TODO: optimization is possible here
246 * probably we need not scaning at all,
247 Index: linux-2.6.18.8/fs/ext3/Makefile
248 ===================================================================
249 --- linux-2.6.18.8.orig/fs/ext3/Makefile
250 +++ linux-2.6.18.8/fs/ext3/Makefile
252 obj-$(CONFIG_EXT3_FS) += ext3.o
254 ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
255 - ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o
256 + ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o mballoc.o
258 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
259 ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
260 Index: linux-2.6.16.46-0.14/fs/ext3/xattr.c
261 ===================================================================
262 --- linux-2.6.16.46-0.14.orig/fs/ext3/xattr.c
263 +++ linux-2.6.16.46-0.14/fs/ext3/xattr.c
264 @@ -484,7 +484,7 @@ ext3_xattr_release_block(handle_t *handl
265 ea_bdebug(bh, "refcount now=0; freeing");
267 mb_cache_entry_free(ce);
268 - ext3_free_blocks(handle, inode, bh->b_blocknr, 1);
269 + ext3_free_blocks(handle, inode, bh->b_blocknr, 1, 1);
271 ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
273 @@ -804,7 +804,7 @@ inserted:
274 new_bh = sb_getblk(sb, block);
277 - ext3_free_blocks(handle, inode, block, 1);
278 + ext3_free_blocks(handle, inode, block, 1, 1);
282 Index: linux-2.6.16.46-0.14/fs/ext3/balloc.c
283 ===================================================================
284 --- linux-2.6.16.46-0.14.orig/fs/ext3/balloc.c
285 +++ linux-2.6.16.46-0.14/fs/ext3/balloc.c
286 @@ -80,7 +80,7 @@ struct ext3_group_desc * ext3_get_group_
288 * Return buffer_head on success or NULL in case of failure.
290 -static struct buffer_head *
291 +struct buffer_head *
292 read_block_bitmap(struct super_block *sb, unsigned int block_group)
294 struct ext3_group_desc * desc;
295 @@ -296,6 +296,8 @@ void ext3_discard_reservation(struct ino
296 struct ext3_reserve_window_node *rsv;
297 spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock;
299 + ext3_mb_discard_inode_preallocations(inode);
304 @@ -491,21 +493,25 @@ error_return:
308 -/* Free given blocks, update quota and i_blocks field */
309 -void ext3_free_blocks(handle_t *handle, struct inode *inode,
310 - unsigned long block, unsigned long count)
311 +void ext3_free_blocks(handle_t *handle, struct inode * inode,
312 + unsigned long block, unsigned long count, int metadata)
314 - struct super_block * sb;
315 - int dquot_freed_blocks;
316 + struct super_block *sb;
319 + /* this isn't the right place to decide whether block is metadata
320 + * inode.c/extents.c knows better, but for safety ... */
321 + if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
322 + ext3_should_journal_data(inode))
327 - printk ("ext3_free_blocks: nonexistent device");
330 - ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
331 - if (dquot_freed_blocks)
332 - DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
333 + if (!test_opt(sb, MBALLOC) || !EXT3_SB(sb)->s_group_info)
334 + ext3_free_blocks_sb(handle, sb, block, count, &freed);
336 + ext3_mb_free_blocks(handle, inode, block, count, metadata, &freed);
338 + DQUOT_FREE_BLOCK(inode, freed);
342 @@ -1154,7 +1160,7 @@ int ext3_should_retry_alloc(struct super
343 * bitmap, and then for any free bit if that fails.
344 * This function also updates quota and i_blocks field.
346 -int ext3_new_block(handle_t *handle, struct inode *inode,
347 +int ext3_new_block_old(handle_t *handle, struct inode *inode,
348 unsigned long goal, int *errp)
350 struct buffer_head *bitmap_bh = NULL;
351 Index: linux-2.6.16.46-0.14/fs/ext3/inode.c
352 ===================================================================
353 --- linux-2.6.16.46-0.14.orig/fs/ext3/inode.c
354 +++ linux-2.6.16.46-0.14/fs/ext3/inode.c
355 @@ -569,7 +569,7 @@ static int ext3_alloc_branch(handle_t *h
356 ext3_journal_forget(handle, branch[i].bh);
358 for (i = 0; i < keys; i++)
359 - ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1);
360 + ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1, 0);
364 @@ -1866,7 +1866,7 @@ ext3_clear_blocks(handle_t *handle, stru
368 - ext3_free_blocks(handle, inode, block_to_free, count);
369 + ext3_free_blocks(handle, inode, block_to_free, count, 0);
373 @@ -2039,7 +2039,7 @@ static void ext3_free_branches(handle_t
374 ext3_journal_test_restart(handle, inode);
377 - ext3_free_blocks(handle, inode, nr, 1);
378 + ext3_free_blocks(handle, inode, nr, 1, 1);