]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/mballoc.c
ext4: start searching for the right extent from the goal group.
[linux-2.6-omap-h63xx.git] / fs / ext4 / mballoc.c
index 873ad9b3418ceeeb6b232566e525b60ccac07616..bdb9f299157a37ffb54c654803313eec90fba22b 100644 (file)
@@ -381,22 +381,28 @@ static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
 
 static inline int mb_find_next_zero_bit(void *addr, int max, int start)
 {
-       int fix = 0;
+       int fix = 0, ret, tmpmax;
        addr = mb_correct_addr_and_bit(&fix, addr);
-       max += fix;
+       tmpmax = max + fix;
        start += fix;
 
-       return ext4_find_next_zero_bit(addr, max, start) - fix;
+       ret = ext4_find_next_zero_bit(addr, tmpmax, start) - fix;
+       if (ret > max)
+               return max;
+       return ret;
 }
 
 static inline int mb_find_next_bit(void *addr, int max, int start)
 {
-       int fix = 0;
+       int fix = 0, ret, tmpmax;
        addr = mb_correct_addr_and_bit(&fix, addr);
-       max += fix;
+       tmpmax = max + fix;
        start += fix;
 
-       return ext4_find_next_bit(addr, max, start) - fix;
+       ret = ext4_find_next_bit(addr, tmpmax, start) - fix;
+       if (ret > max)
+               return max;
+       return ret;
 }
 
 static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
@@ -1730,10 +1736,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
                ac->ac_g_ex.fe_start = sbi->s_mb_last_start;
                spin_unlock(&sbi->s_md_lock);
        }
-
-       /* searching for the right group start from the goal value specified */
-       group = ac->ac_g_ex.fe_group;
-
        /* Let's just scan groups to find more-less suitable blocks */
        cr = ac->ac_2order ? 0 : 1;
        /*
@@ -1743,6 +1745,12 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 repeat:
        for (; cr < 4 && ac->ac_status == AC_STATUS_CONTINUE; cr++) {
                ac->ac_criteria = cr;
+               /*
+                * searching for the right group start
+                * from the goal value specified
+                */
+               group = ac->ac_g_ex.fe_group;
+
                for (i = 0; i < EXT4_SB(sb)->s_groups_count; group++, i++) {
                        struct ext4_group_info *grp;
                        struct ext4_group_desc *desc;
@@ -2745,8 +2753,6 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
        sbi = EXT4_SB(sb);
        es = sbi->s_es;
 
-       ext4_debug("using block group %lu(%d)\n", ac->ac_b_ex.fe_group,
-                       gdp->bg_free_blocks_count);
 
        err = -EIO;
        bitmap_bh = read_block_bitmap(sb, ac->ac_b_ex.fe_group);
@@ -2762,6 +2768,9 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
        if (!gdp)
                goto out_err;
 
+       ext4_debug("using block group %lu(%d)\n", ac->ac_b_ex.fe_group,
+                       gdp->bg_free_blocks_count);
+
        err = ext4_journal_get_write_access(handle, gdp_bh);
        if (err)
                goto out_err;
@@ -3094,8 +3103,7 @@ static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac,
 static void ext4_mb_use_group_pa(struct ext4_allocation_context *ac,
                                struct ext4_prealloc_space *pa)
 {
-       unsigned len = ac->ac_o_ex.fe_len;
-
+       unsigned int len = ac->ac_o_ex.fe_len;
        ext4_get_group_no_and_offset(ac->ac_sb, pa->pa_pstart,
                                        &ac->ac_b_ex.fe_group,
                                        &ac->ac_b_ex.fe_start);
@@ -3473,8 +3481,6 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
                if (bit >= end)
                        break;
                next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
-               if (next > end)
-                       next = end;
                start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +
                                le32_to_cpu(sbi->s_es->s_first_data_block);
                mb_debug("    free preallocated %u/%u in group %u\n",