Lines Matching defs:e4b
409 static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
413 BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b));
416 if (order > e4b->bd_blkbits + 1) {
422 *max = 1 << (e4b->bd_blkbits + 3);
424 return EXT4_MB_BITMAP(e4b);
426 bb = EXT4_MB_BUDDY(e4b) + EXT4_SB(e4b->bd_sb)->s_mb_offsets[order];
427 *max = EXT4_SB(e4b->bd_sb)->s_mb_maxs[order];
433 static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
437 struct super_block *sb = e4b->bd_sb;
439 if (unlikely(e4b->bd_info->bb_bitmap == NULL))
441 assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
443 if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) {
446 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
448 ext4_grp_locked_error(sb, e4b->bd_group,
455 mb_clear_bit(first + i, e4b->bd_info->bb_bitmap);
459 static void mb_mark_used_double(struct ext4_buddy *e4b, int first, int count)
463 if (unlikely(e4b->bd_info->bb_bitmap == NULL))
465 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
467 BUG_ON(mb_test_bit(first + i, e4b->bd_info->bb_bitmap));
468 mb_set_bit(first + i, e4b->bd_info->bb_bitmap);
472 static void mb_cmp_bitmaps(struct ext4_buddy *e4b, void *bitmap)
474 if (memcmp(e4b->bd_info->bb_bitmap, bitmap, e4b->bd_sb->s_blocksize)) {
477 b1 = (unsigned char *) e4b->bd_info->bb_bitmap;
479 for (i = 0; i < e4b->bd_sb->s_blocksize; i++) {
484 e4b->bd_group, i, i * 8, b1[i], b2[i]);
493 struct ext4_buddy *e4b, int first, int count)
497 static inline void mb_mark_used_double(struct ext4_buddy *e4b,
502 static inline void mb_cmp_bitmaps(struct ext4_buddy *e4b, void *bitmap)
520 static int __mb_check_buddy(struct ext4_buddy *e4b, char *file,
523 struct super_block *sb = e4b->bd_sb;
524 int order = e4b->bd_blkbits + 1;
545 buddy = mb_find_buddy(e4b, order, &max);
547 buddy2 = mb_find_buddy(e4b, order - 1, &max2);
574 !mb_test_bit(k, EXT4_MB_BITMAP(e4b)));
578 MB_CHECK_ASSERT(e4b->bd_info->bb_counters[order] == count);
583 buddy = mb_find_buddy(e4b, 0, &max);
586 MB_CHECK_ASSERT(i >= e4b->bd_info->bb_first_free);
595 for (j = 0; j < e4b->bd_blkbits + 1; j++) {
596 buddy2 = mb_find_buddy(e4b, j, &max2);
602 MB_CHECK_ASSERT(!EXT4_MB_GRP_NEED_INIT(e4b->bd_info));
603 MB_CHECK_ASSERT(e4b->bd_info->bb_fragments == fragments);
605 grp = ext4_get_group_info(sb, e4b->bd_group);
606 buddy = mb_find_buddy(e4b, 0, &max);
612 MB_CHECK_ASSERT(groupnr == e4b->bd_group);
619 #define mb_check_buddy(e4b) __mb_check_buddy(e4b, \
622 #define mb_check_buddy(e4b)
1046 struct ext4_buddy *e4b)
1063 e4b->bd_blkbits = sb->s_blocksize_bits;
1064 e4b->bd_info = ext4_get_group_info(sb, group);
1065 e4b->bd_sb = sb;
1066 e4b->bd_group = group;
1067 e4b->bd_buddy_page = NULL;
1068 e4b->bd_bitmap_page = NULL;
1069 e4b->alloc_semp = &grp->alloc_sem;
1078 down_read(e4b->alloc_semp);
1086 up_read(e4b->alloc_semp);
1129 mb_cmp_bitmaps(e4b, page_address(page) +
1139 e4b->bd_bitmap_page = page;
1140 e4b->bd_bitmap = page_address(page) + (poff * sb->s_blocksize);
1155 ret = ext4_mb_init_cache(page, e4b->bd_bitmap);
1168 e4b->bd_buddy_page = page;
1169 e4b->bd_buddy = page_address(page) + (poff * sb->s_blocksize);
1172 BUG_ON(e4b->bd_bitmap_page == NULL);
1173 BUG_ON(e4b->bd_buddy_page == NULL);
1178 if (e4b->bd_bitmap_page)
1179 page_cache_release(e4b->bd_bitmap_page);
1180 if (e4b->bd_buddy_page)
1181 page_cache_release(e4b->bd_buddy_page);
1182 e4b->bd_buddy = NULL;
1183 e4b->bd_bitmap = NULL;
1186 up_read(e4b->alloc_semp);
1190 static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)
1192 if (e4b->bd_bitmap_page)
1193 page_cache_release(e4b->bd_bitmap_page);
1194 if (e4b->bd_buddy_page)
1195 page_cache_release(e4b->bd_buddy_page);
1197 if (e4b->alloc_semp)
1198 up_read(e4b->alloc_semp);
1202 static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
1207 BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b));
1208 BUG_ON(block >= (1 << (e4b->bd_blkbits + 3)));
1210 bb = EXT4_MB_BUDDY(e4b);
1211 while (order <= e4b->bd_blkbits + 1) {
1217 bb += 1 << (e4b->bd_blkbits - order);
1259 static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1267 struct super_block *sb = e4b->bd_sb;
1270 assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
1271 mb_check_buddy(e4b);
1272 mb_free_blocks_double(inode, e4b, first, count);
1274 e4b->bd_info->bb_free += count;
1275 if (first < e4b->bd_info->bb_first_free)
1276 e4b->bd_info->bb_first_free = first;
1280 block = !mb_test_bit(first - 1, EXT4_MB_BITMAP(e4b));
1282 max = !mb_test_bit(first + count, EXT4_MB_BITMAP(e4b));
1284 e4b->bd_info->bb_fragments--;
1286 e4b->bd_info->bb_fragments++;
1293 if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) {
1296 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
1298 ext4_grp_locked_error(sb, e4b->bd_group,
1304 mb_clear_bit(block, EXT4_MB_BITMAP(e4b));
1305 e4b->bd_info->bb_counters[order]++;
1308 buddy = mb_find_buddy(e4b, order, &max);
1317 buddy2 = mb_find_buddy(e4b, order + 1, &max);
1328 e4b->bd_info->bb_counters[order]--;
1329 e4b->bd_info->bb_counters[order]--;
1333 e4b->bd_info->bb_counters[order]++;
1339 mb_set_largest_free_order(sb, e4b->bd_info);
1340 mb_check_buddy(e4b);
1343 static int mb_find_extent(struct ext4_buddy *e4b, int order, int block,
1351 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
1354 buddy = mb_find_buddy(e4b, order, &max);
1366 order = mb_find_order_for_block(e4b, block);
1372 ex->fe_group = e4b->bd_group;
1380 (buddy = mb_find_buddy(e4b, order, &max))) {
1386 if (mb_test_bit(next, EXT4_MB_BITMAP(e4b)))
1389 ord = mb_find_order_for_block(e4b, next);
1396 BUG_ON(ex->fe_start + ex->fe_len > (1 << (e4b->bd_blkbits + 3)));
1400 static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
1412 BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3));
1413 BUG_ON(e4b->bd_group != ex->fe_group);
1414 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
1415 mb_check_buddy(e4b);
1416 mb_mark_used_double(e4b, start, len);
1418 e4b->bd_info->bb_free -= len;
1419 if (e4b->bd_info->bb_first_free == start)
1420 e4b->bd_info->bb_first_free += len;
1424 mlen = !mb_test_bit(start - 1, EXT4_MB_BITMAP(e4b));
1425 if (start + len < EXT4_SB(e4b->bd_sb)->s_mb_maxs[0])
1426 max = !mb_test_bit(start + len, EXT4_MB_BITMAP(e4b));
1428 e4b->bd_info->bb_fragments++;
1430 e4b->bd_info->bb_fragments--;
1434 ord = mb_find_order_for_block(e4b, start);
1439 buddy = mb_find_buddy(e4b, ord, &max);
1442 e4b->bd_info->bb_counters[ord]--;
1455 buddy = mb_find_buddy(e4b, ord, &max);
1457 e4b->bd_info->bb_counters[ord]--;
1461 buddy = mb_find_buddy(e4b, ord, &max);
1464 e4b->bd_info->bb_counters[ord]++;
1465 e4b->bd_info->bb_counters[ord]++;
1467 mb_set_largest_free_order(e4b->bd_sb, e4b->bd_info);
1469 mb_set_bits(EXT4_MB_BITMAP(e4b), ex->fe_start, len0);
1470 mb_check_buddy(e4b);
1479 struct ext4_buddy *e4b)
1484 BUG_ON(ac->ac_b_ex.fe_group != e4b->bd_group);
1489 ret = mb_mark_used(e4b, &ac->ac_b_ex);
1506 ac->ac_bitmap_page = e4b->bd_bitmap_page;
1508 ac->ac_buddy_page = e4b->bd_buddy_page;
1511 ac->alloc_semp = e4b->alloc_semp;
1512 e4b->alloc_semp = NULL;
1527 struct ext4_buddy *e4b,
1554 && bex->fe_group == e4b->bd_group) {
1558 max = mb_find_extent(e4b, 0, bex->fe_start, gex->fe_len, &ex);
1560 ext4_mb_use_best_found(ac, e4b);
1568 struct ext4_buddy *e4b)
1585 ext4_mb_use_best_found(ac, e4b);
1594 ext4_mb_use_best_found(ac, e4b);
1622 ext4_mb_check_limits(ac, e4b, 0);
1627 struct ext4_buddy *e4b)
1635 err = ext4_mb_load_buddy(ac->ac_sb, group, e4b);
1640 max = mb_find_extent(e4b, 0, ex.fe_start, ex.fe_len, &ex);
1644 ext4_mb_use_best_found(ac, e4b);
1648 ext4_mb_unload_buddy(e4b);
1655 struct ext4_buddy *e4b)
1666 err = ext4_mb_load_buddy(ac->ac_sb, group, e4b);
1671 max = mb_find_extent(e4b, 0, ac->ac_g_ex.fe_start,
1677 start = ext4_group_first_block_no(ac->ac_sb, e4b->bd_group) +
1683 ext4_mb_use_best_found(ac, e4b);
1691 ext4_mb_use_best_found(ac, e4b);
1700 ext4_mb_use_best_found(ac, e4b);
1703 ext4_mb_unload_buddy(e4b);
1714 struct ext4_buddy *e4b)
1717 struct ext4_group_info *grp = e4b->bd_info;
1728 buddy = mb_find_buddy(e4b, i, &max);
1738 ac->ac_b_ex.fe_group = e4b->bd_group;
1740 ext4_mb_use_best_found(ac, e4b);
1758 struct ext4_buddy *e4b)
1761 void *bitmap = EXT4_MB_BITMAP(e4b);
1766 free = e4b->bd_info->bb_free;
1769 i = e4b->bd_info->bb_first_free;
1780 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1787 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex);
1790 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1802 ext4_mb_measure_extent(ac, &ex, e4b);
1808 ext4_mb_check_limits(ac, e4b, 1);
1817 struct ext4_buddy *e4b)
1821 void *bitmap = EXT4_MB_BITMAP(e4b);
1831 first_group_block = ext4_group_first_block_no(sb, e4b->bd_group);
1839 max = mb_find_extent(e4b, 0, i, sbi->s_stripe, &ex);
1843 ext4_mb_use_best_found(ac, e4b);
1992 struct ext4_buddy e4b;
2004 err = ext4_mb_find_by_goal(ac, &e4b);
2063 err = ext4_mb_load_buddy(sb, group, &e4b);
2075 ext4_mb_unload_buddy(&e4b);
2081 ext4_mb_simple_scan_group(ac, &e4b);
2084 ext4_mb_scan_aligned(ac, &e4b);
2086 ext4_mb_complex_scan_group(ac, &e4b);
2089 ext4_mb_unload_buddy(&e4b);
2103 ext4_mb_try_best_found(ac, &e4b);
2154 struct ext4_buddy e4b;
2171 err = ext4_mb_load_buddy(sb, group, &e4b);
2179 ext4_mb_unload_buddy(&e4b);
2571 struct ext4_buddy e4b;
2587 err = ext4_mb_load_buddy(sb, entry->group, &e4b);
2591 db = e4b.bd_info;
2598 mb_free_blocks(NULL, &e4b, entry->start_blk, entry->count);
2604 page_cache_release(e4b.bd_buddy_page);
2605 page_cache_release(e4b.bd_bitmap_page);
2609 ext4_mb_unload_buddy(&e4b);
3513 ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3517 struct super_block *sb = e4b->bd_sb;
3530 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
3558 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
3579 ext4_mb_release_group_pa(struct ext4_buddy *e4b,
3583 struct super_block *sb = e4b->bd_sb;
3590 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
3591 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
3625 struct ext4_buddy e4b;
3641 err = ext4_mb_load_buddy(sb, group, &e4b);
3709 ext4_mb_release_group_pa(&e4b, pa, ac);
3711 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
3721 ext4_mb_unload_buddy(&e4b);
3735 struct ext4_buddy e4b;
3801 err = ext4_mb_load_buddy(sb, group, &e4b);
3812 ext4_mb_unload_buddy(&e4b);
3818 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
3821 ext4_mb_unload_buddy(&e4b);
3832 struct ext4_buddy *e4b,
4016 struct ext4_buddy e4b;
4071 if (ext4_mb_load_buddy(sb, group, &e4b)) {
4078 ext4_mb_release_group_pa(&e4b, pa, ac);
4081 ext4_mb_unload_buddy(&e4b);
4356 ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
4359 ext4_group_t group = e4b->bd_group;
4362 struct ext4_group_info *db = e4b->bd_info;
4363 struct super_block *sb = e4b->bd_sb;
4369 BUG_ON(e4b->bd_bitmap_page == NULL);
4370 BUG_ON(e4b->bd_buddy_page == NULL);
4381 page_cache_get(e4b->bd_buddy_page);
4382 page_cache_get(e4b->bd_bitmap_page);
4458 struct ext4_buddy e4b;
4575 err = ext4_mb_load_buddy(sb, block_group, &e4b);
4593 ext4_mb_free_metadata(handle, &e4b, new_entry);
4601 mb_free_blocks(inode, &e4b, bit, count);
4602 ext4_mb_return_to_preallocation(inode, &e4b, block, count);
4618 ext4_mb_unload_buddy(&e4b);