1 ext4: Remove old legacy block allocator
3 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
4 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
5 index 02068fa..59566c0 100644
8 @@ -83,6 +83,7 @@ static int ext4_group_used_meta_blocks(struct super_block *sb,
13 /* Initializes an uninitialized block bitmap if given, and returns the
14 * number of blocks free in the group. */
15 unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
16 @@ -345,303 +346,6 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
21 - * The reservation window structure operations
22 - * --------------------------------------------
23 - * Operations include:
24 - * dump, find, add, remove, is_empty, find_next_reservable_window, etc.
26 - * We use a red-black tree to represent per-filesystem reservation
32 - * __rsv_window_dump() -- Dump the filesystem block allocation reservation map
33 - * @rb_root: root of per-filesystem reservation rb tree
34 - * @verbose: verbose mode
35 - * @fn: function which wishes to dump the reservation map
37 - * If verbose is turned on, it will print the whole block reservation
38 - * windows(start, end). Otherwise, it will only print out the "bad" windows,
39 - * those windows that overlap with their immediate neighbors.
42 -static void __rsv_window_dump(struct rb_root *root, int verbose,
46 - struct ext4_reserve_window_node *rsv, *prev;
54 - printk(KERN_DEBUG "Block Allocation Reservation "
55 - "Windows Map (%s):\n", fn);
57 - rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
59 - printk(KERN_DEBUG "reservation window 0x%p "
60 - "start: %llu, end: %llu\n",
61 - rsv, rsv->rsv_start, rsv->rsv_end);
62 - if (rsv->rsv_start && rsv->rsv_start >= rsv->rsv_end) {
63 - printk(KERN_DEBUG "Bad reservation %p (start >= end)\n",
67 - if (prev && prev->rsv_end >= rsv->rsv_start) {
68 - printk(KERN_DEBUG "Bad reservation %p "
69 - "(prev->end >= start)\n", rsv);
74 - printk(KERN_DEBUG "Restarting reservation "
75 - "walk in verbose mode\n");
83 - printk(KERN_DEBUG "Window map complete.\n");
86 -#define rsv_window_dump(root, verbose) \
87 - __rsv_window_dump((root), (verbose), __func__)
89 -#define rsv_window_dump(root, verbose) do {} while (0)
93 - * goal_in_my_reservation()
94 - * @rsv: inode's reservation window
95 - * @grp_goal: given goal block relative to the allocation block group
96 - * @group: the current allocation block group
97 - * @sb: filesystem super block
99 - * Test if the given goal block (group relative) is within the file's
100 - * own block reservation window range.
102 - * If the reservation window is outside the goal allocation group, return 0;
103 - * grp_goal (given goal block) could be -1, which means no specific
104 - * goal block. In this case, always return 1.
105 - * If the goal block is within the reservation window, return 1;
106 - * otherwise, return 0;
109 -goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal,
110 - ext4_group_t group, struct super_block *sb)
112 - ext4_fsblk_t group_first_block, group_last_block;
114 - group_first_block = ext4_group_first_block_no(sb, group);
115 - group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
117 - if ((rsv->_rsv_start > group_last_block) ||
118 - (rsv->_rsv_end < group_first_block))
120 - if ((grp_goal >= 0) && ((grp_goal + group_first_block < rsv->_rsv_start)
121 - || (grp_goal + group_first_block > rsv->_rsv_end)))
127 - * search_reserve_window()
128 - * @rb_root: root of reservation tree
129 - * @goal: target allocation block
131 - * Find the reserved window which includes the goal, or the previous one
132 - * if the goal is not in any window.
133 - * Returns NULL if there are no windows or if all windows start after the goal.
135 -static struct ext4_reserve_window_node *
136 -search_reserve_window(struct rb_root *root, ext4_fsblk_t goal)
138 - struct rb_node *n = root->rb_node;
139 - struct ext4_reserve_window_node *rsv;
145 - rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
147 - if (goal < rsv->rsv_start)
149 - else if (goal > rsv->rsv_end)
155 - * We've fallen off the end of the tree: the goal wasn't inside
156 - * any particular node. OK, the previous node must be to one
157 - * side of the interval containing the goal. If it's the RHS,
158 - * we need to back up one.
160 - if (rsv->rsv_start > goal) {
161 - n = rb_prev(&rsv->rsv_node);
162 - rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
168 - * ext4_rsv_window_add() -- Insert a window to the block reservation rb tree.
170 - * @rsv: reservation window to add
172 - * Must be called with rsv_lock hold.
174 -void ext4_rsv_window_add(struct super_block *sb,
175 - struct ext4_reserve_window_node *rsv)
177 - struct rb_root *root = &EXT4_SB(sb)->s_rsv_window_root;
178 - struct rb_node *node = &rsv->rsv_node;
179 - ext4_fsblk_t start = rsv->rsv_start;
181 - struct rb_node **p = &root->rb_node;
182 - struct rb_node *parent = NULL;
183 - struct ext4_reserve_window_node *this;
188 - this = rb_entry(parent, struct ext4_reserve_window_node, rsv_node);
190 - if (start < this->rsv_start)
191 - p = &(*p)->rb_left;
192 - else if (start > this->rsv_end)
193 - p = &(*p)->rb_right;
195 - rsv_window_dump(root, 1);
200 - rb_link_node(node, parent, p);
201 - rb_insert_color(node, root);
205 - * ext4_rsv_window_remove() -- unlink a window from the reservation rb tree
207 - * @rsv: reservation window to remove
209 - * Mark the block reservation window as not allocated, and unlink it
210 - * from the filesystem reservation window rb tree. Must be called with
213 -static void rsv_window_remove(struct super_block *sb,
214 - struct ext4_reserve_window_node *rsv)
216 - rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
217 - rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
218 - rsv->rsv_alloc_hit = 0;
219 - rb_erase(&rsv->rsv_node, &EXT4_SB(sb)->s_rsv_window_root);
223 - * rsv_is_empty() -- Check if the reservation window is allocated.
224 - * @rsv: given reservation window to check
226 - * returns 1 if the end block is EXT4_RESERVE_WINDOW_NOT_ALLOCATED.
228 -static inline int rsv_is_empty(struct ext4_reserve_window *rsv)
230 - /* a valid reservation end block could not be 0 */
231 - return rsv->_rsv_end == EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
235 - * ext4_init_block_alloc_info()
236 - * @inode: file inode structure
238 - * Allocate and initialize the reservation window structure, and
239 - * link the window to the ext4 inode structure at last
241 - * The reservation window structure is only dynamically allocated
242 - * and linked to ext4 inode the first time the open file
243 - * needs a new block. So, before every ext4_new_block(s) call, for
244 - * regular files, we should check whether the reservation window
245 - * structure exists or not. In the latter case, this function is called.
246 - * Fail to do so will result in block reservation being turned off for that
249 - * This function is called from ext4_get_blocks_handle(), also called
250 - * when setting the reservation window size through ioctl before the file
251 - * is open for write (needs block allocation).
253 - * Needs down_write(i_data_sem) protection prior to call this function.
255 -void ext4_init_block_alloc_info(struct inode *inode)
257 - struct ext4_inode_info *ei = EXT4_I(inode);
258 - struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
259 - struct super_block *sb = inode->i_sb;
261 - block_i = kmalloc(sizeof(*block_i), GFP_NOFS);
263 - struct ext4_reserve_window_node *rsv = &block_i->rsv_window_node;
265 - rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
266 - rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
269 - * if filesystem is mounted with NORESERVATION, the goal
270 - * reservation window size is set to zero to indicate
271 - * block reservation is off
273 - if (!test_opt(sb, RESERVATION))
274 - rsv->rsv_goal_size = 0;
276 - rsv->rsv_goal_size = EXT4_DEFAULT_RESERVE_BLOCKS;
277 - rsv->rsv_alloc_hit = 0;
278 - block_i->last_alloc_logical_block = 0;
279 - block_i->last_alloc_physical_block = 0;
281 - ei->i_block_alloc_info = block_i;
285 - * ext4_discard_reservation()
288 - * Discard(free) block reservation window on last file close, or truncate
289 - * or at last iput().
291 - * It is being called in three cases:
292 - * ext4_release_file(): last writer close the file
293 - * ext4_clear_inode(): last iput(), when nobody link to this file.
294 - * ext4_truncate(): when the block indirect map is about to change.
297 -void ext4_discard_reservation(struct inode *inode)
299 - struct ext4_inode_info *ei = EXT4_I(inode);
300 - struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
301 - struct ext4_reserve_window_node *rsv;
302 - spinlock_t *rsv_lock = &EXT4_SB(inode->i_sb)->s_rsv_window_lock;
304 - ext4_mb_discard_inode_preallocations(inode);
309 - rsv = &block_i->rsv_window_node;
310 - if (!rsv_is_empty(&rsv->rsv_window)) {
311 - spin_lock(rsv_lock);
312 - if (!rsv_is_empty(&rsv->rsv_window))
313 - rsv_window_remove(inode->i_sb, rsv);
314 - spin_unlock(rsv_lock);
319 * ext4_free_blocks_sb() -- Free given blocks and update quota
320 @@ -650,6 +354,13 @@ void ext4_discard_reservation(struct inode *inode)
321 * @block: start physcial block to free
322 * @count: number of blocks to free
323 * @pdquot_freed_blocks: pointer to quota
325 + * XXX This function is only used by the on-line resizing code, which
326 + * should probably be fixed up to call the mballoc variant. There
327 + * this needs to be cleaned up later; in fact, I'm not convinced this
328 + * is 100% correct in the face of the mballoc code. The online resizing
329 + * code needs to be fixed up to more tightly (and correctly) interlock
330 + * with the mballoc code.
332 void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
333 ext4_fsblk_t block, unsigned long count,
334 @@ -861,747 +572,13 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
338 - if (!test_opt(sb, MBALLOC) || !EXT4_SB(sb)->s_group_info)
339 - ext4_free_blocks_sb(handle, sb, block, count,
340 - &dquot_freed_blocks);
342 - ext4_mb_free_blocks(handle, inode, block, count,
343 - metadata, &dquot_freed_blocks);
344 + ext4_mb_free_blocks(handle, inode, block, count,
345 + metadata, &dquot_freed_blocks);
346 if (dquot_freed_blocks)
347 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
352 - * ext4_test_allocatable()
353 - * @nr: given allocation block group
354 - * @bh: bufferhead contains the bitmap of the given block group
356 - * For ext4 allocations, we must not reuse any blocks which are
357 - * allocated in the bitmap buffer's "last committed data" copy. This
358 - * prevents deletes from freeing up the page for reuse until we have
359 - * committed the delete transaction.
361 - * If we didn't do this, then deleting something and reallocating it as
362 - * data would allow the old block to be overwritten before the
363 - * transaction committed (because we force data to disk before commit).
364 - * This would lead to corruption if we crashed between overwriting the
365 - * data and committing the delete.
367 - * @@@ We may want to make this allocation behaviour conditional on
368 - * data-writes at some point, and disable it for metadata allocations or
369 - * sync-data inodes.
371 -static int ext4_test_allocatable(ext4_grpblk_t nr, struct buffer_head *bh)
374 - struct journal_head *jh = bh2jh(bh);
376 - if (ext4_test_bit(nr, bh->b_data))
379 - jbd_lock_bh_state(bh);
380 - if (!jh->b_committed_data)
383 - ret = !ext4_test_bit(nr, jh->b_committed_data);
384 - jbd_unlock_bh_state(bh);
389 - * bitmap_search_next_usable_block()
390 - * @start: the starting block (group relative) of the search
391 - * @bh: bufferhead contains the block group bitmap
392 - * @maxblocks: the ending block (group relative) of the reservation
394 - * The bitmap search --- search forward alternately through the actual
395 - * bitmap on disk and the last-committed copy in journal, until we find a
396 - * bit free in both bitmaps.
398 -static ext4_grpblk_t
399 -bitmap_search_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
400 - ext4_grpblk_t maxblocks)
402 - ext4_grpblk_t next;
403 - struct journal_head *jh = bh2jh(bh);
405 - while (start < maxblocks) {
406 - next = ext4_find_next_zero_bit(bh->b_data, maxblocks, start);
407 - if (next >= maxblocks)
409 - if (ext4_test_allocatable(next, bh))
411 - jbd_lock_bh_state(bh);
412 - if (jh->b_committed_data)
413 - start = ext4_find_next_zero_bit(jh->b_committed_data,
415 - jbd_unlock_bh_state(bh);
421 - * find_next_usable_block()
422 - * @start: the starting block (group relative) to find next
423 - * allocatable block in bitmap.
424 - * @bh: bufferhead contains the block group bitmap
425 - * @maxblocks: the ending block (group relative) for the search
427 - * Find an allocatable block in a bitmap. We honor both the bitmap and
428 - * its last-committed copy (if that exists), and perform the "most
429 - * appropriate allocation" algorithm of looking for a free block near
430 - * the initial goal; then for a free byte somewhere in the bitmap; then
431 - * for any free bit in the bitmap.
433 -static ext4_grpblk_t
434 -find_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
435 - ext4_grpblk_t maxblocks)
437 - ext4_grpblk_t here, next;
442 - * The goal was occupied; search forward for a free
443 - * block within the next XX blocks.
445 - * end_goal is more or less random, but it has to be
446 - * less than EXT4_BLOCKS_PER_GROUP. Aligning up to the
447 - * next 64-bit boundary is simple..
449 - ext4_grpblk_t end_goal = (start + 63) & ~63;
450 - if (end_goal > maxblocks)
451 - end_goal = maxblocks;
452 - here = ext4_find_next_zero_bit(bh->b_data, end_goal, start);
453 - if (here < end_goal && ext4_test_allocatable(here, bh))
455 - ext4_debug("Bit not found near goal\n");
462 - p = ((char *)bh->b_data) + (here >> 3);
463 - r = memscan(p, 0, ((maxblocks + 7) >> 3) - (here >> 3));
464 - next = (r - ((char *)bh->b_data)) << 3;
466 - if (next < maxblocks && next >= start && ext4_test_allocatable(next, bh))
470 - * The bitmap search --- search forward alternately through the actual
471 - * bitmap and the last-committed copy until we find a bit free in
474 - here = bitmap_search_next_usable_block(here, bh, maxblocks);
480 - * @block: the free block (group relative) to allocate
481 - * @bh: the bufferhead containts the block group bitmap
483 - * We think we can allocate this block in this bitmap. Try to set the bit.
484 - * If that succeeds then check that nobody has allocated and then freed the
485 - * block since we saw that is was not marked in b_committed_data. If it _was_
486 - * allocated and freed then clear the bit in the bitmap again and return
490 -claim_block(spinlock_t *lock, ext4_grpblk_t block, struct buffer_head *bh)
492 - struct journal_head *jh = bh2jh(bh);
495 - if (ext4_set_bit_atomic(lock, block, bh->b_data))
497 - jbd_lock_bh_state(bh);
498 - if (jh->b_committed_data && ext4_test_bit(block, jh->b_committed_data)) {
499 - ext4_clear_bit_atomic(lock, block, bh->b_data);
504 - jbd_unlock_bh_state(bh);
509 - * ext4_try_to_allocate()
511 - * @handle: handle to this transaction
512 - * @group: given allocation block group
513 - * @bitmap_bh: bufferhead holds the block bitmap
514 - * @grp_goal: given target block within the group
515 - * @count: target number of blocks to allocate
516 - * @my_rsv: reservation window
518 - * Attempt to allocate blocks within a give range. Set the range of allocation
519 - * first, then find the first free bit(s) from the bitmap (within the range),
520 - * and at last, allocate the blocks by claiming the found free bit as allocated.
522 - * To set the range of this allocation:
523 - * if there is a reservation window, only try to allocate block(s) from the
524 - * file's own reservation window;
525 - * Otherwise, the allocation range starts from the give goal block, ends at
526 - * the block group's last block.
528 - * If we failed to allocate the desired block then we may end up crossing to a
529 - * new bitmap. In that case we must release write access to the old one via
530 - * ext4_journal_release_buffer(), else we'll run out of credits.
532 -static ext4_grpblk_t
533 -ext4_try_to_allocate(struct super_block *sb, handle_t *handle,
534 - ext4_group_t group, struct buffer_head *bitmap_bh,
535 - ext4_grpblk_t grp_goal, unsigned long *count,
536 - struct ext4_reserve_window *my_rsv)
538 - ext4_fsblk_t group_first_block;
539 - ext4_grpblk_t start, end;
540 - unsigned long num = 0;
542 - /* we do allocation within the reservation window if we have a window */
544 - group_first_block = ext4_group_first_block_no(sb, group);
545 - if (my_rsv->_rsv_start >= group_first_block)
546 - start = my_rsv->_rsv_start - group_first_block;
548 - /* reservation window cross group boundary */
550 - end = my_rsv->_rsv_end - group_first_block + 1;
551 - if (end > EXT4_BLOCKS_PER_GROUP(sb))
552 - /* reservation window crosses group boundary */
553 - end = EXT4_BLOCKS_PER_GROUP(sb);
554 - if ((start <= grp_goal) && (grp_goal < end))
563 - end = EXT4_BLOCKS_PER_GROUP(sb);
566 - BUG_ON(start > EXT4_BLOCKS_PER_GROUP(sb));
569 - if (grp_goal < 0 || !ext4_test_allocatable(grp_goal, bitmap_bh)) {
570 - grp_goal = find_next_usable_block(start, bitmap_bh, end);
576 - for (i = 0; i < 7 && grp_goal > start &&
577 - ext4_test_allocatable(grp_goal - 1,
585 - if (!claim_block(sb_bgl_lock(EXT4_SB(sb), group),
586 - grp_goal, bitmap_bh)) {
588 - * The block was allocated by another thread, or it was
589 - * allocated and then freed by another thread
599 - while (num < *count && grp_goal < end
600 - && ext4_test_allocatable(grp_goal, bitmap_bh)
601 - && claim_block(sb_bgl_lock(EXT4_SB(sb), group),
602 - grp_goal, bitmap_bh)) {
607 - return grp_goal - num;
614 - * find_next_reservable_window():
615 - * find a reservable space within the given range.
616 - * It does not allocate the reservation window for now:
617 - * alloc_new_reservation() will do the work later.
619 - * @search_head: the head of the searching list;
620 - * This is not necessarily the list head of the whole filesystem
622 - * We have both head and start_block to assist the search
623 - * for the reservable space. The list starts from head,
624 - * but we will shift to the place where start_block is,
625 - * then start from there, when looking for a reservable space.
627 - * @size: the target new reservation window size
629 - * @group_first_block: the first block we consider to start
630 - * the real search from
633 - * the maximum block number that our goal reservable space
634 - * could start from. This is normally the last block in this
635 - * group. The search will end when we found the start of next
636 - * possible reservable space is out of this boundary.
637 - * This could handle the cross boundary reservation window
640 - * basically we search from the given range, rather than the whole
641 - * reservation double linked list, (start_block, last_block)
642 - * to find a free region that is of my size and has not
646 -static int find_next_reservable_window(
647 - struct ext4_reserve_window_node *search_head,
648 - struct ext4_reserve_window_node *my_rsv,
649 - struct super_block *sb,
650 - ext4_fsblk_t start_block,
651 - ext4_fsblk_t last_block)
653 - struct rb_node *next;
654 - struct ext4_reserve_window_node *rsv, *prev;
656 - int size = my_rsv->rsv_goal_size;
658 - /* TODO: make the start of the reservation window byte-aligned */
659 - /* cur = *start_block & ~7;*/
666 - if (cur <= rsv->rsv_end)
667 - cur = rsv->rsv_end + 1;
670 - * in the case we could not find a reservable space
671 - * that is what is expected, during the re-search, we could
672 - * remember what's the largest reservable space we could have
673 - * and return that one.
675 - * For now it will fail if we could not find the reservable
676 - * space with expected-size (or more)...
678 - if (cur > last_block)
679 - return -1; /* fail */
682 - next = rb_next(&rsv->rsv_node);
683 - rsv = rb_entry(next, struct ext4_reserve_window_node, rsv_node);
686 - * Reached the last reservation, we can just append to the
692 - if (cur + size <= rsv->rsv_start) {
694 - * Found a reserveable space big enough. We could
695 - * have a reservation across the group boundary here
701 - * we come here either :
702 - * when we reach the end of the whole list,
703 - * and there is empty reservable space after last entry in the list.
704 - * append it to the end of the list.
706 - * or we found one reservable space in the middle of the list,
707 - * return the reservation window that we could append to.
711 - if ((prev != my_rsv) && (!rsv_is_empty(&my_rsv->rsv_window)))
712 - rsv_window_remove(sb, my_rsv);
715 - * Let's book the whole avaliable window for now. We will check the
716 - * disk bitmap later and then, if there are free blocks then we adjust
717 - * the window size if it's larger than requested.
718 - * Otherwise, we will remove this node from the tree next time
719 - * call find_next_reservable_window.
721 - my_rsv->rsv_start = cur;
722 - my_rsv->rsv_end = cur + size - 1;
723 - my_rsv->rsv_alloc_hit = 0;
725 - if (prev != my_rsv)
726 - ext4_rsv_window_add(sb, my_rsv);
732 - * alloc_new_reservation()--allocate a new reservation window
734 - * To make a new reservation, we search part of the filesystem
735 - * reservation list (the list that inside the group). We try to
736 - * allocate a new reservation window near the allocation goal,
737 - * or the beginning of the group, if there is no goal.
739 - * We first find a reservable space after the goal, then from
740 - * there, we check the bitmap for the first free block after
741 - * it. If there is no free block until the end of group, then the
742 - * whole group is full, we failed. Otherwise, check if the free
743 - * block is inside the expected reservable space, if so, we
745 - * If the first free block is outside the reservable space, then
746 - * start from the first free block, we search for next available
747 - * space, and go on.
749 - * on succeed, a new reservation will be found and inserted into the list
750 - * It contains at least one free block, and it does not overlap with other
751 - * reservation windows.
753 - * failed: we failed to find a reservation window in this group
755 - * @rsv: the reservation
757 - * @grp_goal: The goal (group-relative). It is where the search for a
758 - * free reservable space should start from.
759 - * if we have a grp_goal(grp_goal >0 ), then start from there,
760 - * no grp_goal(grp_goal = -1), we start from the first block
763 - * @sb: the super block
764 - * @group: the group we are trying to allocate in
765 - * @bitmap_bh: the block group block bitmap
768 -static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv,
769 - ext4_grpblk_t grp_goal, struct super_block *sb,
770 - ext4_group_t group, struct buffer_head *bitmap_bh)
772 - struct ext4_reserve_window_node *search_head;
773 - ext4_fsblk_t group_first_block, group_end_block, start_block;
774 - ext4_grpblk_t first_free_block;
775 - struct rb_root *fs_rsv_root = &EXT4_SB(sb)->s_rsv_window_root;
776 - unsigned long size;
778 - spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
780 - group_first_block = ext4_group_first_block_no(sb, group);
781 - group_end_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
784 - start_block = group_first_block;
786 - start_block = grp_goal + group_first_block;
788 - size = my_rsv->rsv_goal_size;
790 - if (!rsv_is_empty(&my_rsv->rsv_window)) {
792 - * if the old reservation is cross group boundary
793 - * and if the goal is inside the old reservation window,
794 - * we will come here when we just failed to allocate from
795 - * the first part of the window. We still have another part
796 - * that belongs to the next group. In this case, there is no
797 - * point to discard our window and try to allocate a new one
798 - * in this group(which will fail). we should
799 - * keep the reservation window, just simply move on.
801 - * Maybe we could shift the start block of the reservation
802 - * window to the first block of next group.
805 - if ((my_rsv->rsv_start <= group_end_block) &&
806 - (my_rsv->rsv_end > group_end_block) &&
807 - (start_block >= my_rsv->rsv_start))
810 - if ((my_rsv->rsv_alloc_hit >
811 - (my_rsv->rsv_end - my_rsv->rsv_start + 1) / 2)) {
813 - * if the previously allocation hit ratio is
814 - * greater than 1/2, then we double the size of
815 - * the reservation window the next time,
816 - * otherwise we keep the same size window
819 - if (size > EXT4_MAX_RESERVE_BLOCKS)
820 - size = EXT4_MAX_RESERVE_BLOCKS;
821 - my_rsv->rsv_goal_size = size;
825 - spin_lock(rsv_lock);
827 - * shift the search start to the window near the goal block
829 - search_head = search_reserve_window(fs_rsv_root, start_block);
832 - * find_next_reservable_window() simply finds a reservable window
833 - * inside the given range(start_block, group_end_block).
835 - * To make sure the reservation window has a free bit inside it, we
836 - * need to check the bitmap after we found a reservable window.
839 - ret = find_next_reservable_window(search_head, my_rsv, sb,
840 - start_block, group_end_block);
843 - if (!rsv_is_empty(&my_rsv->rsv_window))
844 - rsv_window_remove(sb, my_rsv);
845 - spin_unlock(rsv_lock);
850 - * On success, find_next_reservable_window() returns the
851 - * reservation window where there is a reservable space after it.
852 - * Before we reserve this reservable space, we need
853 - * to make sure there is at least a free block inside this region.
855 - * searching the first free bit on the block bitmap and copy of
856 - * last committed bitmap alternatively, until we found a allocatable
857 - * block. Search start from the start block of the reservable space
860 - spin_unlock(rsv_lock);
861 - first_free_block = bitmap_search_next_usable_block(
862 - my_rsv->rsv_start - group_first_block,
863 - bitmap_bh, group_end_block - group_first_block + 1);
865 - if (first_free_block < 0) {
867 - * no free block left on the bitmap, no point
868 - * to reserve the space. return failed.
870 - spin_lock(rsv_lock);
871 - if (!rsv_is_empty(&my_rsv->rsv_window))
872 - rsv_window_remove(sb, my_rsv);
873 - spin_unlock(rsv_lock);
874 - return -1; /* failed */
877 - start_block = first_free_block + group_first_block;
879 - * check if the first free block is within the
880 - * free space we just reserved
882 - if (start_block >= my_rsv->rsv_start && start_block <= my_rsv->rsv_end)
883 - return 0; /* success */
885 - * if the first free bit we found is out of the reservable space
886 - * continue search for next reservable space,
887 - * start from where the free block is,
888 - * we also shift the list head to where we stopped last time
890 - search_head = my_rsv;
891 - spin_lock(rsv_lock);
896 - * try_to_extend_reservation()
897 - * @my_rsv: given reservation window
899 - * @size: the delta to extend
901 - * Attempt to expand the reservation window large enough to have
902 - * required number of free blocks
904 - * Since ext4_try_to_allocate() will always allocate blocks within
905 - * the reservation window range, if the window size is too small,
906 - * multiple blocks allocation has to stop at the end of the reservation
907 - * window. To make this more efficient, given the total number of
908 - * blocks needed and the current size of the window, we try to
909 - * expand the reservation window size if necessary on a best-effort
910 - * basis before ext4_new_blocks() tries to allocate blocks,
912 -static void try_to_extend_reservation(struct ext4_reserve_window_node *my_rsv,
913 - struct super_block *sb, int size)
915 - struct ext4_reserve_window_node *next_rsv;
916 - struct rb_node *next;
917 - spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
919 - if (!spin_trylock(rsv_lock))
922 - next = rb_next(&my_rsv->rsv_node);
925 - my_rsv->rsv_end += size;
927 - next_rsv = rb_entry(next, struct ext4_reserve_window_node, rsv_node);
929 - if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size)
930 - my_rsv->rsv_end += size;
932 - my_rsv->rsv_end = next_rsv->rsv_start - 1;
934 - spin_unlock(rsv_lock);
938 - * ext4_try_to_allocate_with_rsv()
940 - * @handle: handle to this transaction
941 - * @group: given allocation block group
942 - * @bitmap_bh: bufferhead holds the block bitmap
943 - * @grp_goal: given target block within the group
944 - * @count: target number of blocks to allocate
945 - * @my_rsv: reservation window
946 - * @errp: pointer to store the error code
948 - * This is the main function used to allocate a new block and its reservation
951 - * Each time when a new block allocation is need, first try to allocate from
952 - * its own reservation. If it does not have a reservation window, instead of
953 - * looking for a free bit on bitmap first, then look up the reservation list to
954 - * see if it is inside somebody else's reservation window, we try to allocate a
955 - * reservation window for it starting from the goal first. Then do the block
956 - * allocation within the reservation window.
958 - * This will avoid keeping on searching the reservation list again and
959 - * again when somebody is looking for a free block (without
960 - * reservation), and there are lots of free blocks, but they are all
963 - * We use a red-black tree for the per-filesystem reservation list.
966 -static ext4_grpblk_t
967 -ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
968 - ext4_group_t group, struct buffer_head *bitmap_bh,
969 - ext4_grpblk_t grp_goal,
970 - struct ext4_reserve_window_node *my_rsv,
971 - unsigned long *count, int *errp)
973 - ext4_fsblk_t group_first_block, group_last_block;
974 - ext4_grpblk_t ret = 0;
976 - unsigned long num = *count;
981 - * Make sure we use undo access for the bitmap, because it is critical
982 - * that we do the frozen_data COW on bitmap buffers in all cases even
983 - * if the buffer is in BJ_Forget state in the committing transaction.
985 - BUFFER_TRACE(bitmap_bh, "get undo access for new block");
986 - fatal = ext4_journal_get_undo_access(handle, bitmap_bh);
993 - * we don't deal with reservation when
994 - * filesystem is mounted without reservation
995 - * or the file is not a regular file
996 - * or last attempt to allocate a block with reservation turned on failed
998 - if (my_rsv == NULL) {
999 - ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
1000 - grp_goal, count, NULL);
1004 - * grp_goal is a group relative block number (if there is a goal)
1005 - * 0 <= grp_goal < EXT4_BLOCKS_PER_GROUP(sb)
1006 - * first block is a filesystem wide block number
1007 - * first block is the block number of the first block in this group
1009 - group_first_block = ext4_group_first_block_no(sb, group);
1010 - group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1013 - * Basically we will allocate a new block from inode's reservation
1016 - * We need to allocate a new reservation window, if:
1017 - * a) inode does not have a reservation window; or
1018 - * b) last attempt to allocate a block from existing reservation
1020 - * c) we come here with a goal and with a reservation window
1022 - * We do not need to allocate a new reservation window if we come here
1023 - * at the beginning with a goal and the goal is inside the window, or
1024 - * we don't have a goal but already have a reservation window.
1025 - * then we could go to allocate from the reservation window directly.
1028 - if (rsv_is_empty(&my_rsv->rsv_window) || (ret < 0) ||
1029 - !goal_in_my_reservation(&my_rsv->rsv_window,
1030 - grp_goal, group, sb)) {
1031 - if (my_rsv->rsv_goal_size < *count)
1032 - my_rsv->rsv_goal_size = *count;
1033 - ret = alloc_new_reservation(my_rsv, grp_goal, sb,
1034 - group, bitmap_bh);
1036 - break; /* failed */
1038 - if (!goal_in_my_reservation(&my_rsv->rsv_window,
1039 - grp_goal, group, sb))
1041 - } else if (grp_goal >= 0) {
1042 - int curr = my_rsv->rsv_end -
1043 - (grp_goal + group_first_block) + 1;
1045 - if (curr < *count)
1046 - try_to_extend_reservation(my_rsv, sb,
1050 - if ((my_rsv->rsv_start > group_last_block) ||
1051 - (my_rsv->rsv_end < group_first_block)) {
1052 - rsv_window_dump(&EXT4_SB(sb)->s_rsv_window_root, 1);
1055 - ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
1056 - grp_goal, &num, &my_rsv->rsv_window);
1058 - my_rsv->rsv_alloc_hit += num;
1060 - break; /* succeed */
1066 - BUFFER_TRACE(bitmap_bh, "journal_dirty_metadata for "
1068 - fatal = ext4_journal_dirty_metadata(handle, bitmap_bh);
1076 - BUFFER_TRACE(bitmap_bh, "journal_release_buffer");
1077 - ext4_journal_release_buffer(handle, bitmap_bh);
1081 int ext4_claim_free_blocks(struct ext4_sb_info *sbi,
1084 @@ -1702,310 +679,6 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
1085 return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
1089 - * ext4_old_new_blocks() -- core block bitmap based block allocation function
1091 - * @handle: handle to this transaction
1092 - * @inode: file inode
1093 - * @goal: given target block(filesystem wide)
1094 - * @count: target number of blocks to allocate
1095 - * @errp: error code
1097 - * ext4_old_new_blocks uses a goal block to assist allocation and look up
1098 - * the block bitmap directly to do block allocation. It tries to
1099 - * allocate block(s) from the block group contains the goal block first. If
1100 - * that fails, it will try to allocate block(s) from other block groups
1101 - * without any specific goal block.
1103 - * This function is called when -o nomballoc mount option is enabled
1106 -ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
1107 - ext4_fsblk_t goal, unsigned long *count, int *errp)
1109 - struct buffer_head *bitmap_bh = NULL;
1110 - struct buffer_head *gdp_bh;
1111 - ext4_group_t group_no;
1112 - ext4_group_t goal_group;
1113 - ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */
1114 - ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/
1115 - ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */
1116 - ext4_group_t bgi; /* blockgroup iteration index */
1117 - int fatal = 0, err;
1118 - int performed_allocation = 0;
1119 - ext4_grpblk_t free_blocks; /* number of free blocks in a group */
1120 - struct super_block *sb;
1121 - struct ext4_group_desc *gdp;
1122 - struct ext4_super_block *es;
1123 - struct ext4_sb_info *sbi;
1124 - struct ext4_reserve_window_node *my_rsv = NULL;
1125 - struct ext4_block_alloc_info *block_i;
1126 - unsigned short windowsz = 0;
1127 - ext4_group_t ngroups;
1128 - unsigned long num = *count;
1133 - printk(KERN_ERR "ext4_new_block: nonexistent superblock");
1137 - sbi = EXT4_SB(sb);
1138 - if (!EXT4_I(inode)->i_delalloc_reserved_flag) {
1140 - * With delalloc we already reserved the blocks
1142 - while (*count && ext4_claim_free_blocks(sbi, *count)) {
1143 - /* let others to free the space */
1145 - *count = *count >> 1;
1149 - return 0; /*return with ENOSPC error */
1154 - * Check quota for allocation of this block.
1156 - if (DQUOT_ALLOC_BLOCK(inode, num)) {
1161 - sbi = EXT4_SB(sb);
1162 - es = EXT4_SB(sb)->s_es;
1163 - ext4_debug("goal=%llu.\n", goal);
1165 - * Allocate a block from reservation only when
1166 - * filesystem is mounted with reservation(default,-o reservation), and
1167 - * it's a regular file, and
1168 - * the desired window size is greater than 0 (One could use ioctl
1169 - * command EXT4_IOC_SETRSVSZ to set the window size to 0 to turn off
1170 - * reservation on that particular file)
1172 - block_i = EXT4_I(inode)->i_block_alloc_info;
1173 - if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
1174 - my_rsv = &block_i->rsv_window_node;
1177 - * First, test whether the goal block is free.
1179 - if (goal < le32_to_cpu(es->s_first_data_block) ||
1180 - goal >= ext4_blocks_count(es))
1181 - goal = le32_to_cpu(es->s_first_data_block);
1182 - ext4_get_group_no_and_offset(sb, goal, &group_no, &grp_target_blk);
1183 - goal_group = group_no;
1185 - gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
1189 - free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
1191 - if (free_blocks > 0) {
1193 - * try to allocate with group target block
1194 - * in the goal group. If we have low free_blocks
1195 - * count turn off reservation
1197 - if (my_rsv && (free_blocks < windowsz)
1198 - && (rsv_is_empty(&my_rsv->rsv_window)))
1201 - bitmap_bh = ext4_read_block_bitmap(sb, group_no);
1204 - grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
1205 - group_no, bitmap_bh, grp_target_blk,
1206 - my_rsv, &num, &fatal);
1209 - if (grp_alloc_blk >= 0)
1213 - ngroups = EXT4_SB(sb)->s_groups_count;
1217 - * Now search the rest of the groups. We assume that
1218 - * group_no and gdp correctly point to the last group visited.
1220 - for (bgi = 0; bgi < ngroups; bgi++) {
1222 - if (group_no >= ngroups)
1224 - gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
1227 - free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
1229 - * skip this group if the number of
1230 - * free blocks is less than half of the reservation
1233 - if (my_rsv && (free_blocks <= (windowsz/2)))
1236 - brelse(bitmap_bh);
1237 - bitmap_bh = ext4_read_block_bitmap(sb, group_no);
1241 - * try to allocate block(s) from this group, without a goal(-1).
1243 - grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
1244 - group_no, bitmap_bh, -1, my_rsv,
1248 - if (grp_alloc_blk >= 0)
1252 - * We may end up a bogus ealier ENOSPC error due to
1253 - * filesystem is "full" of reservations, but
1254 - * there maybe indeed free blocks avaliable on disk
1255 - * In this case, we just forget about the reservations
1256 - * just do block allocation as without reservations.
1261 - group_no = goal_group;
1264 - /* No space left on the device */
1270 - ext4_debug("using block group %lu(%d)\n",
1271 - group_no, gdp->bg_free_blocks_count);
1273 - BUFFER_TRACE(gdp_bh, "get_write_access");
1274 - fatal = ext4_journal_get_write_access(handle, gdp_bh);
1278 - ret_block = grp_alloc_blk + ext4_group_first_block_no(sb, group_no);
1280 - if (in_range(ext4_block_bitmap(sb, gdp), ret_block, num) ||
1281 - in_range(ext4_inode_bitmap(sb, gdp), ret_block, num) ||
1282 - in_range(ret_block, ext4_inode_table(sb, gdp),
1283 - EXT4_SB(sb)->s_itb_per_group) ||
1284 - in_range(ret_block + num - 1, ext4_inode_table(sb, gdp),
1285 - EXT4_SB(sb)->s_itb_per_group)) {
1286 - ext4_error(sb, "ext4_new_block",
1287 - "Allocating block in system zone - "
1288 - "blocks from %llu, length %lu",
1291 - * claim_block marked the blocks we allocated
1292 - * as in use. So we may want to selectively
1293 - * mark some of the blocks as free
1298 - performed_allocation = 1;
1300 -#ifdef CONFIG_JBD2_DEBUG
1302 - struct buffer_head *debug_bh;
1304 - /* Record bitmap buffer state in the newly allocated block */
1305 - debug_bh = sb_find_get_block(sb, ret_block);
1307 - BUFFER_TRACE(debug_bh, "state when allocated");
1308 - BUFFER_TRACE2(debug_bh, bitmap_bh, "bitmap state");
1312 - jbd_lock_bh_state(bitmap_bh);
1313 - spin_lock(sb_bgl_lock(sbi, group_no));
1314 - if (buffer_jbd(bitmap_bh) && bh2jh(bitmap_bh)->b_committed_data) {
1317 - for (i = 0; i < num; i++) {
1318 - if (ext4_test_bit(grp_alloc_blk+i,
1319 - bh2jh(bitmap_bh)->b_committed_data)) {
1320 - printk(KERN_ERR "%s: block was unexpectedly "
1321 - "set in b_committed_data\n", __func__);
1325 - ext4_debug("found bit %d\n", grp_alloc_blk);
1326 - spin_unlock(sb_bgl_lock(sbi, group_no));
1327 - jbd_unlock_bh_state(bitmap_bh);
1330 - if (ret_block + num - 1 >= ext4_blocks_count(es)) {
1331 - ext4_error(sb, "ext4_new_block",
1332 - "block(%llu) >= blocks count(%llu) - "
1333 - "block_group = %lu, es == %p ", ret_block,
1334 - ext4_blocks_count(es), group_no, es);
1339 - * It is up to the caller to add the new buffer to a journal
1340 - * list of some description. We don't know in advance whether
1341 - * the caller wants to use it as metadata or data.
1343 - spin_lock(sb_bgl_lock(sbi, group_no));
1344 - if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))
1345 - gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
1346 - le16_add_cpu(&gdp->bg_free_blocks_count, -num);
1347 - gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp);
1348 - spin_unlock(sb_bgl_lock(sbi, group_no));
1349 - percpu_counter_sub(&sbi->s_freeblocks_counter, num);
1351 - * Now reduce the dirty block count also. Should not go negative
1353 - percpu_counter_sub(&sbi->s_dirtyblocks_counter, num);
1354 - if (sbi->s_log_groups_per_flex) {
1355 - ext4_group_t flex_group = ext4_flex_group(sbi, group_no);
1356 - spin_lock(sb_bgl_lock(sbi, flex_group));
1357 - sbi->s_flex_groups[flex_group].free_blocks -= num;
1358 - spin_unlock(sb_bgl_lock(sbi, flex_group));
1361 - BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
1362 - err = ext4_journal_dirty_metadata(handle, gdp_bh);
1371 - brelse(bitmap_bh);
1372 - DQUOT_FREE_BLOCK(inode, *count-num);
1381 - ext4_std_error(sb, fatal);
1384 - * Undo the block allocation
1386 - if (!performed_allocation)
1387 - DQUOT_FREE_BLOCK(inode, *count);
1388 - brelse(bitmap_bh);
1392 #define EXT4_META_BLOCK 0x1
1394 static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode,
1395 @@ -2015,10 +688,6 @@ static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode,
1396 struct ext4_allocation_request ar;
1399 - if (!test_opt(inode->i_sb, MBALLOC)) {
1400 - return ext4_old_new_blocks(handle, inode, goal, count, errp);
1403 memset(&ar, 0, sizeof(ar));
1404 /* Fill with neighbour allocated blocks */
1406 @@ -2239,3 +908,4 @@ unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
1407 return ext4_bg_num_gdb_meta(sb,group);
1411 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
1412 index 922d187..c50c04c 100644
1413 --- a/fs/ext4/ext4.h
1414 +++ b/fs/ext4/ext4.h
1415 @@ -539,7 +539,6 @@ do { \
1416 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
1417 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
1418 #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
1419 -#define EXT4_MOUNT_MBALLOC 0x4000000 /* Buddy allocation support */
1420 #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
1421 /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
1422 #ifndef _LINUX_EXT2_FS_H
1423 @@ -1002,8 +1001,6 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
1424 extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
1425 ext4_lblk_t iblock, ext4_fsblk_t goal,
1426 unsigned long *count, int *errp);
1427 -extern ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,
1428 - ext4_fsblk_t goal, unsigned long *count, int *errp);
1429 extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
1430 extern ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,
1432 @@ -1018,8 +1015,6 @@ extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
1433 ext4_group_t block_group,
1434 struct buffer_head ** bh);
1435 extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
1436 -extern void ext4_init_block_alloc_info(struct inode *);
1437 -extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
1440 extern int ext4_check_dir_entry(const char *, struct inode *,
1441 @@ -1054,7 +1049,7 @@ extern int ext4_mb_release(struct super_block *);
1442 extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
1443 struct ext4_allocation_request *, int *);
1444 extern int ext4_mb_reserve_blocks(struct super_block *, int);
1445 -extern void ext4_mb_discard_inode_preallocations(struct inode *);
1446 +extern void ext4_discard_preallocations(struct inode *);
1447 extern int __init init_ext4_mballoc(void);
1448 extern void exit_ext4_mballoc(void);
1449 extern void ext4_mb_free_blocks(handle_t *, struct inode *,
1450 @@ -1084,7 +1079,6 @@ extern int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
1451 struct kstat *stat);
1452 extern void ext4_delete_inode(struct inode *);
1453 extern int ext4_sync_inode(handle_t *, struct inode *);
1454 -extern void ext4_discard_reservation(struct inode *);
1455 extern void ext4_dirty_inode(struct inode *);
1456 extern int ext4_change_inode_journal_flag(struct inode *, int);
1457 extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
1458 diff --git a/fs/ext4/ext4_i.h b/fs/ext4/ext4_i.h
1459 index ef7409f..2875eec 100644
1460 --- a/fs/ext4/ext4_i.h
1461 +++ b/fs/ext4/ext4_i.h
1462 @@ -33,38 +33,6 @@ typedef __u32 ext4_lblk_t;
1463 /* data type for block group number */
1464 typedef unsigned long ext4_group_t;
1466 -struct ext4_reserve_window {
1467 - ext4_fsblk_t _rsv_start; /* First byte reserved */
1468 - ext4_fsblk_t _rsv_end; /* Last byte reserved or 0 */
1471 -struct ext4_reserve_window_node {
1472 - struct rb_node rsv_node;
1473 - __u32 rsv_goal_size;
1474 - __u32 rsv_alloc_hit;
1475 - struct ext4_reserve_window rsv_window;
1478 -struct ext4_block_alloc_info {
1479 - /* information about reservation window */
1480 - struct ext4_reserve_window_node rsv_window_node;
1482 - * was i_next_alloc_block in ext4_inode_info
1483 - * is the logical (file-relative) number of the
1484 - * most-recently-allocated block in this file.
1485 - * We use this for detecting linearly ascending allocation requests.
1487 - ext4_lblk_t last_alloc_logical_block;
1489 - * Was i_next_alloc_goal in ext4_inode_info
1490 - * is the *physical* companion to i_next_alloc_block.
1491 - * it the physical block number of the block which was most-recentl
1492 - * allocated to this file. This give us the goal (target) for the next
1493 - * allocation when we detect linearly ascending requests.
1495 - ext4_fsblk_t last_alloc_physical_block;
1498 #define rsv_start rsv_window._rsv_start
1499 #define rsv_end rsv_window._rsv_end
1501 @@ -97,9 +65,6 @@ struct ext4_inode_info {
1502 ext4_group_t i_block_group;
1503 __u32 i_state; /* Dynamic state flags for ext4 */
1505 - /* block reservation info */
1506 - struct ext4_block_alloc_info *i_block_alloc_info;
1508 ext4_lblk_t i_dir_start_lookup;
1509 #ifdef CONFIG_EXT4DEV_FS_XATTR
1511 diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h
1512 index 94e0757..6a0b40d 100644
1513 --- a/fs/ext4/ext4_sb.h
1514 +++ b/fs/ext4/ext4_sb.h
1515 @@ -67,7 +67,6 @@ struct ext4_sb_info {
1516 /* root of the per fs reservation window tree */
1517 spinlock_t s_rsv_window_lock;
1518 struct rb_root s_rsv_window_root;
1519 - struct ext4_reserve_window_node s_rsv_window_head;
1522 struct inode *s_journal_inode;
1523 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
1524 index e8758df..c8f81f2 100644
1525 --- a/fs/ext4/extents.c
1526 +++ b/fs/ext4/extents.c
1527 @@ -2697,11 +2697,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
1531 - * Okay, we need to do block allocation. Lazily initialize the block
1532 - * allocation info here if necessary.
1533 + * Okay, we need to do block allocation.
1535 - if (S_ISREG(inode->i_mode) && (!EXT4_I(inode)->i_block_alloc_info))
1536 - ext4_init_block_alloc_info(inode);
1538 /* find neighbour allocated blocks */
1540 @@ -2761,7 +2758,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
1541 /* free data blocks we just allocated */
1542 /* not a good idea to call discard here directly,
1543 * but otherwise we'd need to call it every free() */
1544 - ext4_mb_discard_inode_preallocations(inode);
1545 + ext4_discard_preallocations(inode);
1546 ext4_free_blocks(handle, inode, ext_pblock(&newex),
1547 ext4_ext_get_actual_len(&newex), 0);
1549 @@ -2825,7 +2822,7 @@ void ext4_ext_truncate(struct inode *inode)
1550 down_write(&EXT4_I(inode)->i_data_sem);
1551 ext4_ext_invalidate_cache(inode);
1553 - ext4_discard_reservation(inode);
1554 + ext4_discard_preallocations(inode);
1557 * TODO: optimization is possible here.
1558 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
1559 index 11b289f..62796b7 100644
1560 --- a/fs/ext4/file.c
1561 +++ b/fs/ext4/file.c
1562 @@ -38,7 +38,7 @@ static int ext4_release_file(struct inode *inode, struct file *filp)
1563 (atomic_read(&inode->i_writecount) == 1))
1565 down_write(&EXT4_I(inode)->i_data_sem);
1566 - ext4_discard_reservation(inode);
1567 + ext4_discard_preallocations(inode);
1568 up_write(&EXT4_I(inode)->i_data_sem);
1570 if (is_dx(inode) && filp->private_data)
1571 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
1572 index 5e66a2f..1343bf1 100644
1573 --- a/fs/ext4/ialloc.c
1574 +++ b/fs/ext4/ialloc.c
1575 @@ -817,7 +817,6 @@ got:
1576 ei->i_flags &= ~EXT4_DIRSYNC_FL;
1579 - ei->i_block_alloc_info = NULL;
1580 ei->i_block_group = group;
1582 ext4_set_inode_flags(inode);
1583 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
1584 index 5bd700f..193b09f 100644
1585 --- a/fs/ext4/inode.c
1586 +++ b/fs/ext4/inode.c
1587 @@ -486,18 +486,9 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
1588 static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
1591 - struct ext4_block_alloc_info *block_i;
1593 - block_i = EXT4_I(inode)->i_block_alloc_info;
1596 - * try the heuristic for sequential allocation,
1597 - * failing that at least try to get decent locality.
1598 + * XXX need to get goal block from mballoc's data structures
1600 - if (block_i && (block == block_i->last_alloc_logical_block + 1)
1601 - && (block_i->last_alloc_physical_block != 0)) {
1602 - return block_i->last_alloc_physical_block + 1;
1605 return ext4_find_near(inode, partial);
1607 @@ -757,10 +748,8 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
1611 - struct ext4_block_alloc_info *block_i;
1612 ext4_fsblk_t current_block;
1614 - block_i = EXT4_I(inode)->i_block_alloc_info;
1616 * If we're splicing into a [td]indirect block (as opposed to the
1617 * inode) then we need to get write access to the [td]indirect block
1618 @@ -786,17 +775,6 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode,
1619 *(where->p + i) = cpu_to_le32(current_block++);
1623 - * update the most recently allocated logical & physical block
1624 - * in i_block_alloc_info, to assist find the proper goal block for next
1628 - block_i->last_alloc_logical_block = block + blks - 1;
1629 - block_i->last_alloc_physical_block =
1630 - le32_to_cpu(where[num].key) + blks - 1;
1633 /* We are done with atomic stuff, now do the rest of housekeeping */
1635 inode->i_ctime = ext4_current_time(inode);
1636 @@ -914,12 +892,8 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
1640 - * Okay, we need to do block allocation. Lazily initialize the block
1641 - * allocation info here if necessary
1642 + * Okay, we need to do block allocation.
1644 - if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
1645 - ext4_init_block_alloc_info(inode);
1647 goal = ext4_find_goal(inode, iblock, partial);
1649 /* the number of blocks need to allocate for [d,t]indirect blocks */
1650 @@ -3738,7 +3712,7 @@ void ext4_truncate(struct inode *inode)
1652 down_write(&ei->i_data_sem);
1654 - ext4_discard_reservation(inode);
1655 + ext4_discard_preallocations(inode);
1658 * The orphan list entry will now protect us from any crash which
1659 @@ -4071,7 +4045,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
1660 ei->i_acl = EXT4_ACL_NOT_CACHED;
1661 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
1663 - ei->i_block_alloc_info = NULL;
1665 ret = __ext4_get_inode_loc(inode, &iloc, 0);
1667 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
1668 index 3e14060..ea27eaa 100644
1669 --- a/fs/ext4/ioctl.c
1670 +++ b/fs/ext4/ioctl.c
1671 @@ -23,7 +23,6 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1672 struct inode *inode = filp->f_dentry->d_inode;
1673 struct ext4_inode_info *ei = EXT4_I(inode);
1675 - unsigned short rsv_window_size;
1677 ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
1679 @@ -190,49 +189,6 @@ setversion_out:
1683 - case EXT4_IOC_GETRSVSZ:
1684 - if (test_opt(inode->i_sb, RESERVATION)
1685 - && S_ISREG(inode->i_mode)
1686 - && ei->i_block_alloc_info) {
1687 - rsv_window_size = ei->i_block_alloc_info->rsv_window_node.rsv_goal_size;
1688 - return put_user(rsv_window_size, (int __user *)arg);
1691 - case EXT4_IOC_SETRSVSZ: {
1694 - if (!test_opt(inode->i_sb, RESERVATION) || !S_ISREG(inode->i_mode))
1697 - if (!is_owner_or_cap(inode))
1700 - if (get_user(rsv_window_size, (int __user *)arg))
1703 - err = mnt_want_write(filp->f_path.mnt);
1707 - if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS)
1708 - rsv_window_size = EXT4_MAX_RESERVE_BLOCKS;
1711 - * need to allocate reservation structure for this inode
1712 - * before set the window size
1714 - down_write(&ei->i_data_sem);
1715 - if (!ei->i_block_alloc_info)
1716 - ext4_init_block_alloc_info(inode);
1718 - if (ei->i_block_alloc_info){
1719 - struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
1720 - rsv->rsv_goal_size = rsv_window_size;
1722 - up_write(&ei->i_data_sem);
1723 - mnt_drop_write(filp->f_path.mnt);
1726 case EXT4_IOC_GROUP_EXTEND: {
1727 ext4_fsblk_t n_blocks_count;
1728 struct super_block *sb = inode->i_sb;
1729 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
1730 index 3373f89..c84b68f 100644
1731 --- a/fs/ext4/mballoc.c
1732 +++ b/fs/ext4/mballoc.c
1733 @@ -534,9 +534,6 @@ static int __mb_check_buddy(struct ext4_buddy *e4b, char *file,
1737 - if (!test_opt(sb, MBALLOC))
1741 static int mb_check_counter;
1742 if (mb_check_counter++ % 100 != 0)
1743 @@ -2487,19 +2484,14 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
1747 - if (!test_opt(sb, MBALLOC))
1750 i = (sb->s_blocksize_bits + 2) * sizeof(unsigned short);
1752 sbi->s_mb_offsets = kmalloc(i, GFP_KERNEL);
1753 if (sbi->s_mb_offsets == NULL) {
1754 - clear_opt(sbi->s_mount_opt, MBALLOC);
1757 sbi->s_mb_maxs = kmalloc(i, GFP_KERNEL);
1758 if (sbi->s_mb_maxs == NULL) {
1759 - clear_opt(sbi->s_mount_opt, MBALLOC);
1760 kfree(sbi->s_mb_maxs);
1763 @@ -2522,7 +2514,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
1764 /* init file for buddy data */
1765 ret = ext4_mb_init_backend(sb);
1767 - clear_opt(sbi->s_mount_opt, MBALLOC);
1768 kfree(sbi->s_mb_offsets);
1769 kfree(sbi->s_mb_maxs);
1771 @@ -2544,7 +2535,6 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
1773 sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
1774 if (sbi->s_locality_groups == NULL) {
1775 - clear_opt(sbi->s_mount_opt, MBALLOC);
1776 kfree(sbi->s_mb_offsets);
1777 kfree(sbi->s_mb_maxs);
1779 @@ -2590,9 +2580,6 @@ int ext4_mb_release(struct super_block *sb)
1780 struct ext4_group_info *grinfo;
1781 struct ext4_sb_info *sbi = EXT4_SB(sb);
1783 - if (!test_opt(sb, MBALLOC))
1786 /* release freed, non-committed blocks */
1787 spin_lock(&sbi->s_md_lock);
1788 list_splice_init(&sbi->s_closed_transaction,
1789 @@ -3799,7 +3786,7 @@ out:
1791 * FIXME!! Make sure it is valid at all the call sites
1793 -void ext4_mb_discard_inode_preallocations(struct inode *inode)
1794 +void ext4_discard_preallocations(struct inode *inode)
1796 struct ext4_inode_info *ei = EXT4_I(inode);
1797 struct super_block *sb = inode->i_sb;
1798 @@ -3811,7 +3798,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode)
1799 struct ext4_buddy e4b;
1802 - if (!test_opt(sb, MBALLOC) || !S_ISREG(inode->i_mode)) {
1803 + if (!S_ISREG(inode->i_mode)) {
1804 /*BUG_ON(!list_empty(&ei->i_prealloc_list));*/
1807 @@ -4293,11 +4280,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
1808 sb = ar->inode->i_sb;
1811 - if (!test_opt(sb, MBALLOC)) {
1812 - block = ext4_old_new_blocks(handle, ar->inode, ar->goal,
1813 - &(ar->len), errp);
1816 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) {
1818 * With delalloc we already reserved the blocks
1819 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
1820 index b60afbc..b6ec184 100644
1821 --- a/fs/ext4/resize.c
1822 +++ b/fs/ext4/resize.c
1823 @@ -870,11 +870,10 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
1824 * We can allocate memory for mb_alloc based on the new group
1827 - if (test_opt(sb, MBALLOC)) {
1828 - err = ext4_mb_add_more_groupinfo(sb, input->group, gdp);
1830 - goto exit_journal;
1832 + err = ext4_mb_add_more_groupinfo(sb, input->group, gdp);
1834 + goto exit_journal;
1837 * Make the new blocks and inodes valid next. We do this before
1838 * increasing the group count so that once the group is enabled,
1839 @@ -1086,8 +1085,15 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1841 * Mark mballoc pages as not up to date so that they will be updated
1842 * next time they are loaded by ext4_mb_load_buddy.
1844 + * XXX Bad, Bad, BAD!!! We should not be overloading the
1845 + * Uptodate flag, particularly on thte bitmap bh, as way of
1846 + * hinting to ext4_mb_load_buddy() that it needs to be
1847 + * overloaded. A user could take a LVM snapshot, then do an
1848 + * on-line fsck, and clear the uptodate flag, and this would
1849 + * not be a bug in userspace, but a bug in the kernel. FIXME!!!
1851 - if (test_opt(sb, MBALLOC)) {
1853 struct ext4_sb_info *sbi = EXT4_SB(sb);
1854 struct inode *inode = sbi->s_buddy_cache;
1855 int blocks_per_page;
1856 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
1857 index 9094095..515af05 100644
1858 --- a/fs/ext4/super.c
1859 +++ b/fs/ext4/super.c
1860 @@ -573,7 +573,6 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
1861 ei->i_acl = EXT4_ACL_NOT_CACHED;
1862 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
1864 - ei->i_block_alloc_info = NULL;
1865 ei->vfs_inode.i_version = 1;
1866 ei->vfs_inode.i_data.writeback_index = 0;
1867 memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
1868 @@ -632,7 +631,6 @@ static void destroy_inodecache(void)
1870 static void ext4_clear_inode(struct inode *inode)
1872 - struct ext4_block_alloc_info *rsv = EXT4_I(inode)->i_block_alloc_info;
1873 #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
1874 if (EXT4_I(inode)->i_acl &&
1875 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
1876 @@ -645,10 +643,7 @@ static void ext4_clear_inode(struct inode *inode)
1877 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
1880 - ext4_discard_reservation(inode);
1881 - EXT4_I(inode)->i_block_alloc_info = NULL;
1882 - if (unlikely(rsv))
1884 + ext4_discard_preallocations(inode);
1885 jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
1886 &EXT4_I(inode)->jinode);
1888 @@ -759,8 +754,6 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
1889 seq_puts(seq, ",nobh");
1890 if (!test_opt(sb, EXTENTS))
1891 seq_puts(seq, ",noextents");
1892 - if (!test_opt(sb, MBALLOC))
1893 - seq_puts(seq, ",nomballoc");
1894 if (test_opt(sb, I_VERSION))
1895 seq_puts(seq, ",i_version");
1896 if (!test_opt(sb, DELALLOC))
1897 @@ -1372,12 +1365,6 @@ set_qf_format:
1898 case Opt_nodelalloc:
1899 clear_opt(sbi->s_mount_opt, DELALLOC);
1902 - set_opt(sbi->s_mount_opt, MBALLOC);
1904 - case Opt_nomballoc:
1905 - clear_opt(sbi->s_mount_opt, MBALLOC);
1908 if (match_int(&args[0], &option))
1910 @@ -2039,11 +2026,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
1911 ext4_warning(sb, __func__,
1912 "extents feature not enabled on this filesystem, "
1915 - * turn on mballoc code by default in ext4 filesystem
1916 - * Use -o nomballoc to turn it off
1918 - set_opt(sbi->s_mount_opt, MBALLOC);
1921 * enable delayed allocation by default
1922 @@ -2300,19 +2282,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
1926 - /* per fileystem reservation list head & lock */
1927 - spin_lock_init(&sbi->s_rsv_window_lock);
1928 - sbi->s_rsv_window_root = RB_ROOT;
1929 - /* Add a single, static dummy reservation to the start of the
1930 - * reservation window list --- it gives us a placeholder for
1931 - * append-at-start-of-list which makes the allocation logic
1932 - * _much_ simpler. */
1933 - sbi->s_rsv_window_head.rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
1934 - sbi->s_rsv_window_head.rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
1935 - sbi->s_rsv_window_head.rsv_alloc_hit = 0;
1936 - sbi->s_rsv_window_head.rsv_goal_size = 0;
1937 - ext4_rsv_window_add(sb, &sbi->s_rsv_window_head);
1939 sbi->s_stripe = ext4_get_stripe_size(sbi);
1942 @@ -2509,7 +2478,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
1943 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n");
1946 - ext4_mb_init(sb, needs_recovery);
1947 + err = ext4_mb_init(sb, needs_recovery);
1949 + printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n",
1951 + goto failed_mount4;