Lines Matching full:ac
352 static void ext4_mb_new_preallocation(struct ext4_allocation_context *ac);
1690 static void ext4_mb_use_best_found(struct ext4_allocation_context *ac, in ext4_mb_use_best_found() argument
1693 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_use_best_found()
1696 BUG_ON(ac->ac_b_ex.fe_group != e4b->bd_group); in ext4_mb_use_best_found()
1697 BUG_ON(ac->ac_status == AC_STATUS_FOUND); in ext4_mb_use_best_found()
1699 ac->ac_b_ex.fe_len = min(ac->ac_b_ex.fe_len, ac->ac_g_ex.fe_len); in ext4_mb_use_best_found()
1700 ac->ac_b_ex.fe_logical = ac->ac_g_ex.fe_logical; in ext4_mb_use_best_found()
1701 ret = mb_mark_used(e4b, &ac->ac_b_ex); in ext4_mb_use_best_found()
1705 ac->ac_f_ex = ac->ac_b_ex; in ext4_mb_use_best_found()
1707 ac->ac_status = AC_STATUS_FOUND; in ext4_mb_use_best_found()
1708 ac->ac_tail = ret & 0xffff; in ext4_mb_use_best_found()
1709 ac->ac_buddy = ret >> 16; in ext4_mb_use_best_found()
1718 ac->ac_bitmap_page = e4b->bd_bitmap_page; in ext4_mb_use_best_found()
1719 get_page(ac->ac_bitmap_page); in ext4_mb_use_best_found()
1720 ac->ac_buddy_page = e4b->bd_buddy_page; in ext4_mb_use_best_found()
1721 get_page(ac->ac_buddy_page); in ext4_mb_use_best_found()
1723 if (ac->ac_flags & EXT4_MB_STREAM_ALLOC) { in ext4_mb_use_best_found()
1725 sbi->s_mb_last_group = ac->ac_f_ex.fe_group; in ext4_mb_use_best_found()
1726 sbi->s_mb_last_start = ac->ac_f_ex.fe_start; in ext4_mb_use_best_found()
1734 if (ac->ac_o_ex.fe_len < ac->ac_b_ex.fe_len) in ext4_mb_use_best_found()
1735 ext4_mb_new_preallocation(ac); in ext4_mb_use_best_found()
1739 static void ext4_mb_check_limits(struct ext4_allocation_context *ac, in ext4_mb_check_limits() argument
1743 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_check_limits()
1744 struct ext4_free_extent *bex = &ac->ac_b_ex; in ext4_mb_check_limits()
1745 struct ext4_free_extent *gex = &ac->ac_g_ex; in ext4_mb_check_limits()
1749 if (ac->ac_status == AC_STATUS_FOUND) in ext4_mb_check_limits()
1754 if (ac->ac_found > sbi->s_mb_max_to_scan && in ext4_mb_check_limits()
1755 !(ac->ac_flags & EXT4_MB_HINT_FIRST)) { in ext4_mb_check_limits()
1756 ac->ac_status = AC_STATUS_BREAK; in ext4_mb_check_limits()
1766 if ((finish_group || ac->ac_found > sbi->s_mb_min_to_scan) in ext4_mb_check_limits()
1773 ext4_mb_use_best_found(ac, e4b); in ext4_mb_check_limits()
1789 static void ext4_mb_measure_extent(struct ext4_allocation_context *ac, in ext4_mb_measure_extent() argument
1793 struct ext4_free_extent *bex = &ac->ac_b_ex; in ext4_mb_measure_extent()
1794 struct ext4_free_extent *gex = &ac->ac_g_ex; in ext4_mb_measure_extent()
1797 BUG_ON(ex->fe_len > EXT4_CLUSTERS_PER_GROUP(ac->ac_sb)); in ext4_mb_measure_extent()
1798 BUG_ON(ex->fe_start >= EXT4_CLUSTERS_PER_GROUP(ac->ac_sb)); in ext4_mb_measure_extent()
1799 BUG_ON(ac->ac_status != AC_STATUS_CONTINUE); in ext4_mb_measure_extent()
1801 ac->ac_found++; in ext4_mb_measure_extent()
1806 if (unlikely(ac->ac_flags & EXT4_MB_HINT_FIRST)) { in ext4_mb_measure_extent()
1808 ext4_mb_use_best_found(ac, e4b); in ext4_mb_measure_extent()
1817 ext4_mb_use_best_found(ac, e4b); in ext4_mb_measure_extent()
1845 ext4_mb_check_limits(ac, e4b, 0); in ext4_mb_measure_extent()
1849 int ext4_mb_try_best_found(struct ext4_allocation_context *ac, in ext4_mb_try_best_found() argument
1852 struct ext4_free_extent ex = ac->ac_b_ex; in ext4_mb_try_best_found()
1858 err = ext4_mb_load_buddy(ac->ac_sb, group, e4b); in ext4_mb_try_best_found()
1862 ext4_lock_group(ac->ac_sb, group); in ext4_mb_try_best_found()
1866 ac->ac_b_ex = ex; in ext4_mb_try_best_found()
1867 ext4_mb_use_best_found(ac, e4b); in ext4_mb_try_best_found()
1870 ext4_unlock_group(ac->ac_sb, group); in ext4_mb_try_best_found()
1877 int ext4_mb_find_by_goal(struct ext4_allocation_context *ac, in ext4_mb_find_by_goal() argument
1880 ext4_group_t group = ac->ac_g_ex.fe_group; in ext4_mb_find_by_goal()
1883 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_find_by_goal()
1884 struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group); in ext4_mb_find_by_goal()
1887 if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL)) in ext4_mb_find_by_goal()
1892 err = ext4_mb_load_buddy(ac->ac_sb, group, e4b); in ext4_mb_find_by_goal()
1901 ext4_lock_group(ac->ac_sb, group); in ext4_mb_find_by_goal()
1902 max = mb_find_extent(e4b, ac->ac_g_ex.fe_start, in ext4_mb_find_by_goal()
1903 ac->ac_g_ex.fe_len, &ex); in ext4_mb_find_by_goal()
1906 if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) { in ext4_mb_find_by_goal()
1909 start = ext4_group_first_block_no(ac->ac_sb, e4b->bd_group) + in ext4_mb_find_by_goal()
1913 ac->ac_found++; in ext4_mb_find_by_goal()
1914 ac->ac_b_ex = ex; in ext4_mb_find_by_goal()
1915 ext4_mb_use_best_found(ac, e4b); in ext4_mb_find_by_goal()
1917 } else if (max >= ac->ac_g_ex.fe_len) { in ext4_mb_find_by_goal()
1919 BUG_ON(ex.fe_group != ac->ac_g_ex.fe_group); in ext4_mb_find_by_goal()
1920 BUG_ON(ex.fe_start != ac->ac_g_ex.fe_start); in ext4_mb_find_by_goal()
1921 ac->ac_found++; in ext4_mb_find_by_goal()
1922 ac->ac_b_ex = ex; in ext4_mb_find_by_goal()
1923 ext4_mb_use_best_found(ac, e4b); in ext4_mb_find_by_goal()
1924 } else if (max > 0 && (ac->ac_flags & EXT4_MB_HINT_MERGE)) { in ext4_mb_find_by_goal()
1928 BUG_ON(ex.fe_group != ac->ac_g_ex.fe_group); in ext4_mb_find_by_goal()
1929 BUG_ON(ex.fe_start != ac->ac_g_ex.fe_start); in ext4_mb_find_by_goal()
1930 ac->ac_found++; in ext4_mb_find_by_goal()
1931 ac->ac_b_ex = ex; in ext4_mb_find_by_goal()
1932 ext4_mb_use_best_found(ac, e4b); in ext4_mb_find_by_goal()
1934 ext4_unlock_group(ac->ac_sb, group); in ext4_mb_find_by_goal()
1945 void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac, in ext4_mb_simple_scan_group() argument
1948 struct super_block *sb = ac->ac_sb; in ext4_mb_simple_scan_group()
1955 BUG_ON(ac->ac_2order <= 0); in ext4_mb_simple_scan_group()
1956 for (i = ac->ac_2order; i <= sb->s_blocksize_bits + 1; i++) { in ext4_mb_simple_scan_group()
1965 ext4_grp_locked_error(ac->ac_sb, e4b->bd_group, 0, 0, in ext4_mb_simple_scan_group()
1968 ext4_mark_group_bitmap_corrupted(ac->ac_sb, in ext4_mb_simple_scan_group()
1973 ac->ac_found++; in ext4_mb_simple_scan_group()
1975 ac->ac_b_ex.fe_len = 1 << i; in ext4_mb_simple_scan_group()
1976 ac->ac_b_ex.fe_start = k << i; in ext4_mb_simple_scan_group()
1977 ac->ac_b_ex.fe_group = e4b->bd_group; in ext4_mb_simple_scan_group()
1979 ext4_mb_use_best_found(ac, e4b); in ext4_mb_simple_scan_group()
1981 BUG_ON(ac->ac_f_ex.fe_len != ac->ac_g_ex.fe_len); in ext4_mb_simple_scan_group()
1996 void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, in ext4_mb_complex_scan_group() argument
1999 struct super_block *sb = ac->ac_sb; in ext4_mb_complex_scan_group()
2011 while (free && ac->ac_status == AC_STATUS_CONTINUE) { in ext4_mb_complex_scan_group()
2029 mb_find_extent(e4b, i, ac->ac_g_ex.fe_len, &ex); in ext4_mb_complex_scan_group()
2047 ext4_mb_measure_extent(ac, &ex, e4b); in ext4_mb_complex_scan_group()
2053 ext4_mb_check_limits(ac, e4b, 1); in ext4_mb_complex_scan_group()
2061 void ext4_mb_scan_aligned(struct ext4_allocation_context *ac, in ext4_mb_scan_aligned() argument
2064 struct super_block *sb = ac->ac_sb; in ext4_mb_scan_aligned()
2086 ac->ac_found++; in ext4_mb_scan_aligned()
2088 ac->ac_b_ex = ex; in ext4_mb_scan_aligned()
2089 ext4_mb_use_best_found(ac, e4b); in ext4_mb_scan_aligned()
2102 static bool ext4_mb_good_group(struct ext4_allocation_context *ac, in ext4_mb_good_group() argument
2106 int flex_size = ext4_flex_bg_size(EXT4_SB(ac->ac_sb)); in ext4_mb_good_group()
2107 struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group); in ext4_mb_good_group()
2124 BUG_ON(ac->ac_2order == 0); in ext4_mb_good_group()
2127 if ((ac->ac_flags & EXT4_MB_HINT_DATA) && in ext4_mb_good_group()
2132 if (free < ac->ac_g_ex.fe_len) in ext4_mb_good_group()
2135 if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1) in ext4_mb_good_group()
2138 if (grp->bb_largest_free_order < ac->ac_2order) in ext4_mb_good_group()
2143 if ((free / fragments) >= ac->ac_g_ex.fe_len) in ext4_mb_good_group()
2147 if (free >= ac->ac_g_ex.fe_len) in ext4_mb_good_group()
2164 static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac, in ext4_mb_good_group_nolock() argument
2167 struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group); in ext4_mb_good_group_nolock()
2168 struct super_block *sb = ac->ac_sb; in ext4_mb_good_group_nolock()
2170 bool should_lock = ac->ac_flags & EXT4_MB_STRICT_CHECK; in ext4_mb_good_group_nolock()
2179 if (cr <= 2 && free < ac->ac_g_ex.fe_len) in ext4_mb_good_group_nolock()
2213 ret = ext4_mb_good_group(ac, group, cr); in ext4_mb_good_group_nolock()
2299 ext4_mb_regular_allocator(struct ext4_allocation_context *ac) in ext4_mb_regular_allocator() argument
2310 sb = ac->ac_sb; in ext4_mb_regular_allocator()
2314 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS))) in ext4_mb_regular_allocator()
2317 BUG_ON(ac->ac_status == AC_STATUS_FOUND); in ext4_mb_regular_allocator()
2320 err = ext4_mb_find_by_goal(ac, &e4b); in ext4_mb_regular_allocator()
2321 if (err || ac->ac_status == AC_STATUS_FOUND) in ext4_mb_regular_allocator()
2324 if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY)) in ext4_mb_regular_allocator()
2328 * ac->ac_2order is set only if the fe_len is a power of 2 in ext4_mb_regular_allocator()
2329 * if ac->ac_2order is set we also set criteria to 0 so that we in ext4_mb_regular_allocator()
2332 i = fls(ac->ac_g_ex.fe_len); in ext4_mb_regular_allocator()
2333 ac->ac_2order = 0; in ext4_mb_regular_allocator()
2345 if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0) in ext4_mb_regular_allocator()
2346 ac->ac_2order = array_index_nospec(i - 1, in ext4_mb_regular_allocator()
2351 if (ac->ac_flags & EXT4_MB_STREAM_ALLOC) { in ext4_mb_regular_allocator()
2354 ac->ac_g_ex.fe_group = sbi->s_mb_last_group; in ext4_mb_regular_allocator()
2355 ac->ac_g_ex.fe_start = sbi->s_mb_last_start; in ext4_mb_regular_allocator()
2360 cr = ac->ac_2order ? 0 : 1; in ext4_mb_regular_allocator()
2366 for (; cr < 4 && ac->ac_status == AC_STATUS_CONTINUE; cr++) { in ext4_mb_regular_allocator()
2367 ac->ac_criteria = cr; in ext4_mb_regular_allocator()
2372 group = ac->ac_g_ex.fe_group; in ext4_mb_regular_allocator()
2409 ret = ext4_mb_good_group_nolock(ac, group, cr); in ext4_mb_regular_allocator()
2426 ret = ext4_mb_good_group(ac, group, cr); in ext4_mb_regular_allocator()
2433 ac->ac_groups_scanned++; in ext4_mb_regular_allocator()
2435 ext4_mb_simple_scan_group(ac, &e4b); in ext4_mb_regular_allocator()
2437 !(ac->ac_g_ex.fe_len % sbi->s_stripe)) in ext4_mb_regular_allocator()
2438 ext4_mb_scan_aligned(ac, &e4b); in ext4_mb_regular_allocator()
2440 ext4_mb_complex_scan_group(ac, &e4b); in ext4_mb_regular_allocator()
2445 if (ac->ac_status != AC_STATUS_CONTINUE) in ext4_mb_regular_allocator()
2450 if (ac->ac_b_ex.fe_len > 0 && ac->ac_status != AC_STATUS_FOUND && in ext4_mb_regular_allocator()
2451 !(ac->ac_flags & EXT4_MB_HINT_FIRST)) { in ext4_mb_regular_allocator()
2456 ext4_mb_try_best_found(ac, &e4b); in ext4_mb_regular_allocator()
2457 if (ac->ac_status != AC_STATUS_FOUND) { in ext4_mb_regular_allocator()
2465 ac->ac_b_ex.fe_group, ac->ac_b_ex.fe_start, in ext4_mb_regular_allocator()
2466 ac->ac_b_ex.fe_len, lost); in ext4_mb_regular_allocator()
2468 ac->ac_b_ex.fe_group = 0; in ext4_mb_regular_allocator()
2469 ac->ac_b_ex.fe_start = 0; in ext4_mb_regular_allocator()
2470 ac->ac_b_ex.fe_len = 0; in ext4_mb_regular_allocator()
2471 ac->ac_status = AC_STATUS_CONTINUE; in ext4_mb_regular_allocator()
2472 ac->ac_flags |= EXT4_MB_HINT_FIRST; in ext4_mb_regular_allocator()
2478 if (!err && ac->ac_status != AC_STATUS_FOUND && first_err) in ext4_mb_regular_allocator()
2482 ac->ac_b_ex.fe_len, ac->ac_o_ex.fe_len, ac->ac_status, in ext4_mb_regular_allocator()
2483 ac->ac_flags, cr, err); in ext4_mb_regular_allocator()
3183 * Check quota and mark chosen space (ac->ac_b_ex) non-free in bitmaps
3187 ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, in ext4_mb_mark_diskspace_used() argument
3198 BUG_ON(ac->ac_status != AC_STATUS_FOUND); in ext4_mb_mark_diskspace_used()
3199 BUG_ON(ac->ac_b_ex.fe_len <= 0); in ext4_mb_mark_diskspace_used()
3201 sb = ac->ac_sb; in ext4_mb_mark_diskspace_used()
3204 bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3217 gdp = ext4_get_group_desc(sb, ac->ac_b_ex.fe_group, &gdp_bh); in ext4_mb_mark_diskspace_used()
3221 ext4_debug("using block group %u(%d)\n", ac->ac_b_ex.fe_group, in ext4_mb_mark_diskspace_used()
3229 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); in ext4_mb_mark_diskspace_used()
3231 len = EXT4_C2B(sbi, ac->ac_b_ex.fe_len); in ext4_mb_mark_diskspace_used()
3232 if (!ext4_inode_block_valid(ac->ac_inode, block, len)) { in ext4_mb_mark_diskspace_used()
3239 ext4_lock_group(sb, ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3240 ext4_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start, in ext4_mb_mark_diskspace_used()
3241 ac->ac_b_ex.fe_len); in ext4_mb_mark_diskspace_used()
3242 ext4_unlock_group(sb, ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3249 ext4_lock_group(sb, ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3253 for (i = 0; i < ac->ac_b_ex.fe_len; i++) { in ext4_mb_mark_diskspace_used()
3254 BUG_ON(mb_test_bit(ac->ac_b_ex.fe_start + i, in ext4_mb_mark_diskspace_used()
3259 ext4_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start, in ext4_mb_mark_diskspace_used()
3260 ac->ac_b_ex.fe_len); in ext4_mb_mark_diskspace_used()
3266 ac->ac_b_ex.fe_group, gdp)); in ext4_mb_mark_diskspace_used()
3268 len = ext4_free_group_clusters(sb, gdp) - ac->ac_b_ex.fe_len; in ext4_mb_mark_diskspace_used()
3270 ext4_block_bitmap_csum_set(sb, ac->ac_b_ex.fe_group, gdp, bitmap_bh); in ext4_mb_mark_diskspace_used()
3271 ext4_group_desc_csum_set(sb, ac->ac_b_ex.fe_group, gdp); in ext4_mb_mark_diskspace_used()
3273 ext4_unlock_group(sb, ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3274 percpu_counter_sub(&sbi->s_freeclusters_counter, ac->ac_b_ex.fe_len); in ext4_mb_mark_diskspace_used()
3278 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) in ext4_mb_mark_diskspace_used()
3285 ac->ac_b_ex.fe_group); in ext4_mb_mark_diskspace_used()
3286 atomic64_sub(ac->ac_b_ex.fe_len, in ext4_mb_mark_diskspace_used()
3388 static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac) in ext4_mb_normalize_group_request() argument
3390 struct super_block *sb = ac->ac_sb; in ext4_mb_normalize_group_request()
3391 struct ext4_locality_group *lg = ac->ac_lg; in ext4_mb_normalize_group_request()
3394 ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc; in ext4_mb_normalize_group_request()
3395 mb_debug(sb, "goal %u blocks for locality group\n", ac->ac_g_ex.fe_len); in ext4_mb_normalize_group_request()
3403 ext4_mb_normalize_request(struct ext4_allocation_context *ac, in ext4_mb_normalize_request() argument
3406 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_normalize_request()
3412 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); in ext4_mb_normalize_request()
3417 if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) in ext4_mb_normalize_request()
3421 if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY)) in ext4_mb_normalize_request()
3426 if (ac->ac_flags & EXT4_MB_HINT_NOPREALLOC) in ext4_mb_normalize_request()
3429 if (ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC) { in ext4_mb_normalize_request()
3430 ext4_mb_normalize_group_request(ac); in ext4_mb_normalize_request()
3434 bsbits = ac->ac_sb->s_blocksize_bits; in ext4_mb_normalize_request()
3438 size = ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len); in ext4_mb_normalize_request()
3440 if (size < i_size_read(ac->ac_inode)) in ext4_mb_normalize_request()
3441 size = i_size_read(ac->ac_inode); in ext4_mb_normalize_request()
3468 start_off = ((loff_t)ac->ac_o_ex.fe_logical >> in ext4_mb_normalize_request()
3472 start_off = ((loff_t)ac->ac_o_ex.fe_logical >> in ext4_mb_normalize_request()
3475 } else if (NRL_CHECK_SIZE(ac->ac_o_ex.fe_len, in ext4_mb_normalize_request()
3477 start_off = ((loff_t)ac->ac_o_ex.fe_logical >> in ext4_mb_normalize_request()
3481 start_off = (loff_t) ac->ac_o_ex.fe_logical << bsbits; in ext4_mb_normalize_request()
3482 size = (loff_t) EXT4_C2B(EXT4_SB(ac->ac_sb), in ext4_mb_normalize_request()
3483 ac->ac_o_ex.fe_len) << bsbits; in ext4_mb_normalize_request()
3500 if (size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb)) in ext4_mb_normalize_request()
3501 size = EXT4_BLOCKS_PER_GROUP(ac->ac_sb); in ext4_mb_normalize_request()
3518 pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb), in ext4_mb_normalize_request()
3522 BUG_ON(!(ac->ac_o_ex.fe_logical >= pa_end || in ext4_mb_normalize_request()
3523 ac->ac_o_ex.fe_logical < pa->pa_lstart)); in ext4_mb_normalize_request()
3533 if (pa_end <= ac->ac_o_ex.fe_logical) { in ext4_mb_normalize_request()
3536 } else if (pa->pa_lstart > ac->ac_o_ex.fe_logical) { in ext4_mb_normalize_request()
3552 pa_end = pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb), in ext4_mb_normalize_request()
3560 if (start + size <= ac->ac_o_ex.fe_logical && in ext4_mb_normalize_request()
3561 start > ac->ac_o_ex.fe_logical) { in ext4_mb_normalize_request()
3562 ext4_msg(ac->ac_sb, KERN_ERR, in ext4_mb_normalize_request()
3565 (unsigned long) ac->ac_o_ex.fe_logical); in ext4_mb_normalize_request()
3568 BUG_ON(size <= 0 || size > EXT4_BLOCKS_PER_GROUP(ac->ac_sb)); in ext4_mb_normalize_request()
3574 ac->ac_g_ex.fe_logical = start; in ext4_mb_normalize_request()
3575 ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size); in ext4_mb_normalize_request()
3580 ext4_get_group_no_and_offset(ac->ac_sb, ar->pright - size, in ext4_mb_normalize_request()
3581 &ac->ac_f_ex.fe_group, in ext4_mb_normalize_request()
3582 &ac->ac_f_ex.fe_start); in ext4_mb_normalize_request()
3583 ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL; in ext4_mb_normalize_request()
3587 ext4_get_group_no_and_offset(ac->ac_sb, ar->pleft + 1, in ext4_mb_normalize_request()
3588 &ac->ac_f_ex.fe_group, in ext4_mb_normalize_request()
3589 &ac->ac_f_ex.fe_start); in ext4_mb_normalize_request()
3590 ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL; in ext4_mb_normalize_request()
3593 mb_debug(ac->ac_sb, "goal: %lld(was %lld) blocks at %u\n", size, in ext4_mb_normalize_request()
3597 static void ext4_mb_collect_stats(struct ext4_allocation_context *ac) in ext4_mb_collect_stats() argument
3599 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_collect_stats()
3601 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) { in ext4_mb_collect_stats()
3603 atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated); in ext4_mb_collect_stats()
3604 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len) in ext4_mb_collect_stats()
3606 atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned); in ext4_mb_collect_stats()
3607 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start && in ext4_mb_collect_stats()
3608 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group) in ext4_mb_collect_stats()
3610 if (ac->ac_found > sbi->s_mb_max_to_scan) in ext4_mb_collect_stats()
3614 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC) in ext4_mb_collect_stats()
3615 trace_ext4_mballoc_alloc(ac); in ext4_mb_collect_stats()
3617 trace_ext4_mballoc_prealloc(ac); in ext4_mb_collect_stats()
3624 * zeroed out ac->ac_b_ex.fe_len, so group_pa->pa_free is not changed.
3626 static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac) in ext4_discard_allocated_blocks() argument
3628 struct ext4_prealloc_space *pa = ac->ac_pa; in ext4_discard_allocated_blocks()
3633 if (ac->ac_f_ex.fe_len == 0) in ext4_discard_allocated_blocks()
3635 err = ext4_mb_load_buddy(ac->ac_sb, ac->ac_f_ex.fe_group, &e4b); in ext4_discard_allocated_blocks()
3645 ext4_lock_group(ac->ac_sb, ac->ac_f_ex.fe_group); in ext4_discard_allocated_blocks()
3646 mb_free_blocks(ac->ac_inode, &e4b, ac->ac_f_ex.fe_start, in ext4_discard_allocated_blocks()
3647 ac->ac_f_ex.fe_len); in ext4_discard_allocated_blocks()
3648 ext4_unlock_group(ac->ac_sb, ac->ac_f_ex.fe_group); in ext4_discard_allocated_blocks()
3653 pa->pa_free += ac->ac_b_ex.fe_len; in ext4_discard_allocated_blocks()
3659 static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac, in ext4_mb_use_inode_pa() argument
3662 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_use_inode_pa()
3668 start = pa->pa_pstart + (ac->ac_o_ex.fe_logical - pa->pa_lstart); in ext4_mb_use_inode_pa()
3670 start + EXT4_C2B(sbi, ac->ac_o_ex.fe_len)); in ext4_mb_use_inode_pa()
3672 ext4_get_group_no_and_offset(ac->ac_sb, start, &ac->ac_b_ex.fe_group, in ext4_mb_use_inode_pa()
3673 &ac->ac_b_ex.fe_start); in ext4_mb_use_inode_pa()
3674 ac->ac_b_ex.fe_len = len; in ext4_mb_use_inode_pa()
3675 ac->ac_status = AC_STATUS_FOUND; in ext4_mb_use_inode_pa()
3676 ac->ac_pa = pa; in ext4_mb_use_inode_pa()
3683 mb_debug(ac->ac_sb, "use %llu/%d from inode pa %p\n", start, len, pa); in ext4_mb_use_inode_pa()
3689 static void ext4_mb_use_group_pa(struct ext4_allocation_context *ac, in ext4_mb_use_group_pa() argument
3692 unsigned int len = ac->ac_o_ex.fe_len; in ext4_mb_use_group_pa()
3694 ext4_get_group_no_and_offset(ac->ac_sb, pa->pa_pstart, in ext4_mb_use_group_pa()
3695 &ac->ac_b_ex.fe_group, in ext4_mb_use_group_pa()
3696 &ac->ac_b_ex.fe_start); in ext4_mb_use_group_pa()
3697 ac->ac_b_ex.fe_len = len; in ext4_mb_use_group_pa()
3698 ac->ac_status = AC_STATUS_FOUND; in ext4_mb_use_group_pa()
3699 ac->ac_pa = pa; in ext4_mb_use_group_pa()
3707 mb_debug(ac->ac_sb, "use %u/%u from group pa %p\n", in ext4_mb_use_group_pa()
3744 ext4_mb_use_preallocated(struct ext4_allocation_context *ac) in ext4_mb_use_preallocated() argument
3746 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_use_preallocated()
3748 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); in ext4_mb_use_preallocated()
3754 if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) in ext4_mb_use_preallocated()
3763 if (ac->ac_o_ex.fe_logical < pa->pa_lstart || in ext4_mb_use_preallocated()
3764 ac->ac_o_ex.fe_logical >= (pa->pa_lstart + in ext4_mb_use_preallocated()
3769 if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)) && in ext4_mb_use_preallocated()
3778 ext4_mb_use_inode_pa(ac, pa); in ext4_mb_use_preallocated()
3780 ac->ac_criteria = 10; in ext4_mb_use_preallocated()
3789 if (!(ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC)) in ext4_mb_use_preallocated()
3793 lg = ac->ac_lg; in ext4_mb_use_preallocated()
3796 order = fls(ac->ac_o_ex.fe_len) - 1; in ext4_mb_use_preallocated()
3801 goal_block = ext4_grp_offs_to_block(ac->ac_sb, &ac->ac_g_ex); in ext4_mb_use_preallocated()
3812 pa->pa_free >= ac->ac_o_ex.fe_len) { in ext4_mb_use_preallocated()
3822 ext4_mb_use_group_pa(ac, cpa); in ext4_mb_use_preallocated()
3823 ac->ac_criteria = 20; in ext4_mb_use_preallocated()
3928 static void ext4_mb_put_pa(struct ext4_allocation_context *ac, in ext4_mb_put_pa() argument
3988 ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) in ext4_mb_new_inode_pa() argument
3990 struct super_block *sb = ac->ac_sb; in ext4_mb_new_inode_pa()
3997 BUG_ON(ac->ac_o_ex.fe_len >= ac->ac_b_ex.fe_len); in ext4_mb_new_inode_pa()
3998 BUG_ON(ac->ac_status != AC_STATUS_FOUND); in ext4_mb_new_inode_pa()
3999 BUG_ON(!S_ISREG(ac->ac_inode->i_mode)); in ext4_mb_new_inode_pa()
4000 BUG_ON(ac->ac_pa == NULL); in ext4_mb_new_inode_pa()
4002 pa = ac->ac_pa; in ext4_mb_new_inode_pa()
4004 if (ac->ac_b_ex.fe_len < ac->ac_g_ex.fe_len) { in ext4_mb_new_inode_pa()
4013 BUG_ON(ac->ac_g_ex.fe_logical > ac->ac_o_ex.fe_logical); in ext4_mb_new_inode_pa()
4014 BUG_ON(ac->ac_g_ex.fe_len < ac->ac_o_ex.fe_len); in ext4_mb_new_inode_pa()
4019 winl = ac->ac_o_ex.fe_logical - ac->ac_g_ex.fe_logical; in ext4_mb_new_inode_pa()
4022 wins = EXT4_C2B(sbi, ac->ac_b_ex.fe_len - ac->ac_o_ex.fe_len); in ext4_mb_new_inode_pa()
4027 offs = ac->ac_o_ex.fe_logical % in ext4_mb_new_inode_pa()
4028 EXT4_C2B(sbi, ac->ac_b_ex.fe_len); in ext4_mb_new_inode_pa()
4032 ac->ac_b_ex.fe_logical = ac->ac_o_ex.fe_logical - in ext4_mb_new_inode_pa()
4034 BUG_ON(ac->ac_o_ex.fe_logical < ac->ac_b_ex.fe_logical); in ext4_mb_new_inode_pa()
4035 BUG_ON(ac->ac_o_ex.fe_len > ac->ac_b_ex.fe_len); in ext4_mb_new_inode_pa()
4040 ac->ac_f_ex = ac->ac_b_ex; in ext4_mb_new_inode_pa()
4042 pa->pa_lstart = ac->ac_b_ex.fe_logical; in ext4_mb_new_inode_pa()
4043 pa->pa_pstart = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); in ext4_mb_new_inode_pa()
4044 pa->pa_len = ac->ac_b_ex.fe_len; in ext4_mb_new_inode_pa()
4054 trace_ext4_mb_new_inode_pa(ac, pa); in ext4_mb_new_inode_pa()
4056 ext4_mb_use_inode_pa(ac, pa); in ext4_mb_new_inode_pa()
4059 ei = EXT4_I(ac->ac_inode); in ext4_mb_new_inode_pa()
4060 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group); in ext4_mb_new_inode_pa()
4063 pa->pa_inode = ac->ac_inode; in ext4_mb_new_inode_pa()
4077 ext4_mb_new_group_pa(struct ext4_allocation_context *ac) in ext4_mb_new_group_pa() argument
4079 struct super_block *sb = ac->ac_sb; in ext4_mb_new_group_pa()
4085 BUG_ON(ac->ac_o_ex.fe_len >= ac->ac_b_ex.fe_len); in ext4_mb_new_group_pa()
4086 BUG_ON(ac->ac_status != AC_STATUS_FOUND); in ext4_mb_new_group_pa()
4087 BUG_ON(!S_ISREG(ac->ac_inode->i_mode)); in ext4_mb_new_group_pa()
4088 BUG_ON(ac->ac_pa == NULL); in ext4_mb_new_group_pa()
4090 pa = ac->ac_pa; in ext4_mb_new_group_pa()
4094 ac->ac_f_ex = ac->ac_b_ex; in ext4_mb_new_group_pa()
4096 pa->pa_pstart = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); in ext4_mb_new_group_pa()
4098 pa->pa_len = ac->ac_b_ex.fe_len; in ext4_mb_new_group_pa()
4108 trace_ext4_mb_new_group_pa(ac, pa); in ext4_mb_new_group_pa()
4110 ext4_mb_use_group_pa(ac, pa); in ext4_mb_new_group_pa()
4113 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group); in ext4_mb_new_group_pa()
4114 lg = ac->ac_lg; in ext4_mb_new_group_pa()
4128 static void ext4_mb_new_preallocation(struct ext4_allocation_context *ac) in ext4_mb_new_preallocation() argument
4130 if (ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC) in ext4_mb_new_preallocation()
4131 ext4_mb_new_group_pa(ac); in ext4_mb_new_preallocation()
4133 ext4_mb_new_inode_pa(ac); in ext4_mb_new_preallocation()
4452 static int ext4_mb_pa_alloc(struct ext4_allocation_context *ac) in ext4_mb_pa_alloc() argument
4461 ac->ac_pa = pa; in ext4_mb_pa_alloc()
4465 static void ext4_mb_pa_free(struct ext4_allocation_context *ac) in ext4_mb_pa_free() argument
4467 struct ext4_prealloc_space *pa = ac->ac_pa; in ext4_mb_pa_free()
4470 ac->ac_pa = NULL; in ext4_mb_pa_free()
4507 static void ext4_mb_show_ac(struct ext4_allocation_context *ac) in ext4_mb_show_ac() argument
4509 struct super_block *sb = ac->ac_sb; in ext4_mb_show_ac()
4517 ac->ac_status, ac->ac_flags); in ext4_mb_show_ac()
4521 (unsigned long)ac->ac_o_ex.fe_group, in ext4_mb_show_ac()
4522 (unsigned long)ac->ac_o_ex.fe_start, in ext4_mb_show_ac()
4523 (unsigned long)ac->ac_o_ex.fe_len, in ext4_mb_show_ac()
4524 (unsigned long)ac->ac_o_ex.fe_logical, in ext4_mb_show_ac()
4525 (unsigned long)ac->ac_g_ex.fe_group, in ext4_mb_show_ac()
4526 (unsigned long)ac->ac_g_ex.fe_start, in ext4_mb_show_ac()
4527 (unsigned long)ac->ac_g_ex.fe_len, in ext4_mb_show_ac()
4528 (unsigned long)ac->ac_g_ex.fe_logical, in ext4_mb_show_ac()
4529 (unsigned long)ac->ac_b_ex.fe_group, in ext4_mb_show_ac()
4530 (unsigned long)ac->ac_b_ex.fe_start, in ext4_mb_show_ac()
4531 (unsigned long)ac->ac_b_ex.fe_len, in ext4_mb_show_ac()
4532 (unsigned long)ac->ac_b_ex.fe_logical, in ext4_mb_show_ac()
4533 (int)ac->ac_criteria); in ext4_mb_show_ac()
4534 mb_debug(sb, "%u found", ac->ac_found); in ext4_mb_show_ac()
4542 static inline void ext4_mb_show_ac(struct ext4_allocation_context *ac) in ext4_mb_show_ac() argument
4544 ext4_mb_show_pa(ac->ac_sb); in ext4_mb_show_ac()
4556 static void ext4_mb_group_or_file(struct ext4_allocation_context *ac) in ext4_mb_group_or_file() argument
4558 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_group_or_file()
4559 int bsbits = ac->ac_sb->s_blocksize_bits; in ext4_mb_group_or_file()
4562 if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) in ext4_mb_group_or_file()
4565 if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY)) in ext4_mb_group_or_file()
4568 size = ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len); in ext4_mb_group_or_file()
4569 isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1) in ext4_mb_group_or_file()
4573 !inode_is_open_for_write(ac->ac_inode)) { in ext4_mb_group_or_file()
4574 ac->ac_flags |= EXT4_MB_HINT_NOPREALLOC; in ext4_mb_group_or_file()
4579 ac->ac_flags |= EXT4_MB_STREAM_ALLOC; in ext4_mb_group_or_file()
4586 ac->ac_flags |= EXT4_MB_STREAM_ALLOC; in ext4_mb_group_or_file()
4590 BUG_ON(ac->ac_lg != NULL); in ext4_mb_group_or_file()
4596 ac->ac_lg = raw_cpu_ptr(sbi->s_locality_groups); in ext4_mb_group_or_file()
4599 ac->ac_flags |= EXT4_MB_HINT_GROUP_ALLOC; in ext4_mb_group_or_file()
4602 mutex_lock(&ac->ac_lg->lg_mutex); in ext4_mb_group_or_file()
4606 ext4_mb_initialize_context(struct ext4_allocation_context *ac, in ext4_mb_initialize_context() argument
4632 ac->ac_b_ex.fe_logical = EXT4_LBLK_CMASK(sbi, ar->logical); in ext4_mb_initialize_context()
4633 ac->ac_status = AC_STATUS_CONTINUE; in ext4_mb_initialize_context()
4634 ac->ac_sb = sb; in ext4_mb_initialize_context()
4635 ac->ac_inode = ar->inode; in ext4_mb_initialize_context()
4636 ac->ac_o_ex.fe_logical = ac->ac_b_ex.fe_logical; in ext4_mb_initialize_context()
4637 ac->ac_o_ex.fe_group = group; in ext4_mb_initialize_context()
4638 ac->ac_o_ex.fe_start = block; in ext4_mb_initialize_context()
4639 ac->ac_o_ex.fe_len = len; in ext4_mb_initialize_context()
4640 ac->ac_g_ex = ac->ac_o_ex; in ext4_mb_initialize_context()
4641 ac->ac_flags = ar->flags; in ext4_mb_initialize_context()
4645 ext4_mb_group_or_file(ac); in ext4_mb_initialize_context()
4647 mb_debug(sb, "init ac: %u blocks @ %u, goal %u, flags 0x%x, 2^%d, " in ext4_mb_initialize_context()
4650 (unsigned) ar->goal, ac->ac_flags, ac->ac_2order, in ext4_mb_initialize_context()
4744 static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac) in ext4_mb_add_n_trim() argument
4747 struct super_block *sb = ac->ac_sb; in ext4_mb_add_n_trim()
4748 struct ext4_locality_group *lg = ac->ac_lg; in ext4_mb_add_n_trim()
4749 struct ext4_prealloc_space *tmp_pa, *pa = ac->ac_pa; in ext4_mb_add_n_trim()
4812 static int ext4_mb_release_context(struct ext4_allocation_context *ac) in ext4_mb_release_context() argument
4814 struct inode *inode = ac->ac_inode; in ext4_mb_release_context()
4816 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); in ext4_mb_release_context()
4817 struct ext4_prealloc_space *pa = ac->ac_pa; in ext4_mb_release_context()
4822 pa->pa_pstart += EXT4_C2B(sbi, ac->ac_b_ex.fe_len); in ext4_mb_release_context()
4823 pa->pa_lstart += EXT4_C2B(sbi, ac->ac_b_ex.fe_len); in ext4_mb_release_context()
4824 pa->pa_free -= ac->ac_b_ex.fe_len; in ext4_mb_release_context()
4825 pa->pa_len -= ac->ac_b_ex.fe_len; in ext4_mb_release_context()
4838 ext4_mb_add_n_trim(ac); in ext4_mb_release_context()
4852 ext4_mb_put_pa(ac, ac->ac_sb, pa); in ext4_mb_release_context()
4854 if (ac->ac_bitmap_page) in ext4_mb_release_context()
4855 put_page(ac->ac_bitmap_page); in ext4_mb_release_context()
4856 if (ac->ac_buddy_page) in ext4_mb_release_context()
4857 put_page(ac->ac_buddy_page); in ext4_mb_release_context()
4858 if (ac->ac_flags & EXT4_MB_HINT_GROUP_ALLOC) in ext4_mb_release_context()
4859 mutex_unlock(&ac->ac_lg->lg_mutex); in ext4_mb_release_context()
4860 ext4_mb_collect_stats(ac); in ext4_mb_release_context()
4882 struct ext4_allocation_context *ac, u64 *seq) in ext4_mb_discard_preallocations_should_retry() argument
4888 freed = ext4_mb_discard_preallocations(sb, ac->ac_o_ex.fe_len); in ext4_mb_discard_preallocations_should_retry()
4894 if (!(ac->ac_flags & EXT4_MB_STRICT_CHECK) || seq_retry != *seq) { in ext4_mb_discard_preallocations_should_retry()
4895 ac->ac_flags |= EXT4_MB_STRICT_CHECK; in ext4_mb_discard_preallocations_should_retry()
4916 struct ext4_allocation_context *ac = NULL; in ext4_mb_new_blocks() local
4973 ac = kmem_cache_zalloc(ext4_ac_cachep, GFP_NOFS); in ext4_mb_new_blocks()
4974 if (!ac) { in ext4_mb_new_blocks()
4980 *errp = ext4_mb_initialize_context(ac, ar); in ext4_mb_new_blocks()
4986 ac->ac_op = EXT4_MB_HISTORY_PREALLOC; in ext4_mb_new_blocks()
4988 if (!ext4_mb_use_preallocated(ac)) { in ext4_mb_new_blocks()
4989 ac->ac_op = EXT4_MB_HISTORY_ALLOC; in ext4_mb_new_blocks()
4990 ext4_mb_normalize_request(ac, ar); in ext4_mb_new_blocks()
4992 *errp = ext4_mb_pa_alloc(ac); in ext4_mb_new_blocks()
4997 *errp = ext4_mb_regular_allocator(ac); in ext4_mb_new_blocks()
5001 * ac->ac_status == AC_STATUS_FOUND. in ext4_mb_new_blocks()
5002 * And error from above mean ac->ac_status != AC_STATUS_FOUND in ext4_mb_new_blocks()
5006 ext4_mb_pa_free(ac); in ext4_mb_new_blocks()
5007 ext4_discard_allocated_blocks(ac); in ext4_mb_new_blocks()
5010 if (ac->ac_status == AC_STATUS_FOUND && in ext4_mb_new_blocks()
5011 ac->ac_o_ex.fe_len >= ac->ac_f_ex.fe_len) in ext4_mb_new_blocks()
5012 ext4_mb_pa_free(ac); in ext4_mb_new_blocks()
5014 if (likely(ac->ac_status == AC_STATUS_FOUND)) { in ext4_mb_new_blocks()
5015 *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_clstrs); in ext4_mb_new_blocks()
5017 ext4_discard_allocated_blocks(ac); in ext4_mb_new_blocks()
5020 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); in ext4_mb_new_blocks()
5021 ar->len = ac->ac_b_ex.fe_len; in ext4_mb_new_blocks()
5024 if (ext4_mb_discard_preallocations_should_retry(sb, ac, &seq)) in ext4_mb_new_blocks()
5030 ext4_mb_pa_free(ac); in ext4_mb_new_blocks()
5036 ac->ac_b_ex.fe_len = 0; in ext4_mb_new_blocks()
5038 ext4_mb_show_ac(ac); in ext4_mb_new_blocks()
5040 ext4_mb_release_context(ac); in ext4_mb_new_blocks()
5042 if (ac) in ext4_mb_new_blocks()
5043 kmem_cache_free(ext4_ac_cachep, ac); in ext4_mb_new_blocks()