Lines Matching refs:cache
28 struct btrfs_block_group_cache *cache; in init_test_block_group() local
30 cache = kzalloc(sizeof(*cache), GFP_NOFS); in init_test_block_group()
31 if (!cache) in init_test_block_group()
33 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in init_test_block_group()
35 if (!cache->free_space_ctl) { in init_test_block_group()
36 kfree(cache); in init_test_block_group()
39 cache->fs_info = btrfs_alloc_dummy_fs_info(); in init_test_block_group()
40 if (!cache->fs_info) { in init_test_block_group()
41 kfree(cache->free_space_ctl); in init_test_block_group()
42 kfree(cache); in init_test_block_group()
46 cache->key.objectid = 0; in init_test_block_group()
47 cache->key.offset = 1024 * 1024 * 1024; in init_test_block_group()
48 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; in init_test_block_group()
49 cache->sectorsize = 4096; in init_test_block_group()
50 cache->full_stripe_len = 4096; in init_test_block_group()
52 spin_lock_init(&cache->lock); in init_test_block_group()
53 INIT_LIST_HEAD(&cache->list); in init_test_block_group()
54 INIT_LIST_HEAD(&cache->cluster_list); in init_test_block_group()
55 INIT_LIST_HEAD(&cache->bg_list); in init_test_block_group()
57 btrfs_init_free_space_ctl(cache); in init_test_block_group()
59 return cache; in init_test_block_group()
67 static int test_extents(struct btrfs_block_group_cache *cache) in test_extents() argument
74 ret = btrfs_add_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
80 ret = btrfs_remove_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
86 if (test_check_exists(cache, 0, 4 * 1024 * 1024)) { in test_extents()
92 ret = btrfs_add_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
98 ret = btrfs_remove_free_space(cache, 3 * 1024 * 1024, 1 * 1024 * 1024); in test_extents()
104 ret = btrfs_remove_free_space(cache, 0, 1 * 1024 * 1024); in test_extents()
110 ret = btrfs_remove_free_space(cache, 2 * 1024 * 1024, 4096); in test_extents()
116 if (test_check_exists(cache, 0, 1 * 1024 * 1024)) { in test_extents()
121 if (test_check_exists(cache, 2 * 1024 * 1024, 4096)) { in test_extents()
126 if (test_check_exists(cache, 3 * 1024 * 1024, 1 * 1024 * 1024)) { in test_extents()
132 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_extents()
137 static int test_bitmaps(struct btrfs_block_group_cache *cache) in test_bitmaps() argument
144 ret = test_add_free_space_entry(cache, 0, 4 * 1024 * 1024, 1); in test_bitmaps()
150 ret = btrfs_remove_free_space(cache, 0, 4 * 1024 * 1024); in test_bitmaps()
156 if (test_check_exists(cache, 0, 4 * 1024 * 1024)) { in test_bitmaps()
161 ret = test_add_free_space_entry(cache, 0, 4 * 1024 * 1024, 1); in test_bitmaps()
167 ret = btrfs_remove_free_space(cache, 1 * 1024 * 1024, 2 * 1024 * 1024); in test_bitmaps()
180 ret = test_add_free_space_entry(cache, next_bitmap_offset - in test_bitmaps()
188 ret = btrfs_remove_free_space(cache, next_bitmap_offset - in test_bitmaps()
195 if (test_check_exists(cache, next_bitmap_offset - (1 * 1024 * 1024), in test_bitmaps()
201 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps()
207 static int test_bitmaps_and_extents(struct btrfs_block_group_cache *cache) in test_bitmaps_and_extents() argument
219 ret = test_add_free_space_entry(cache, 4 * 1024 * 1024, 1 * 1024 * 1024, 1); in test_bitmaps_and_extents()
225 ret = test_add_free_space_entry(cache, 0, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
231 ret = btrfs_remove_free_space(cache, 0, 1 * 1024 * 1024); in test_bitmaps_and_extents()
237 if (test_check_exists(cache, 0, 1 * 1024 * 1024)) { in test_bitmaps_and_extents()
243 ret = test_add_free_space_entry(cache, 0, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
249 ret = btrfs_remove_free_space(cache, 4 * 1024 * 1024, 1 * 1024 * 1024); in test_bitmaps_and_extents()
255 if (test_check_exists(cache, 4 * 1024 * 1024, 1 * 1024 * 1024)) { in test_bitmaps_and_extents()
264 ret = test_add_free_space_entry(cache, 1 * 1024 * 1024, 4 * 1024 * 1024, 1); in test_bitmaps_and_extents()
270 ret = btrfs_remove_free_space(cache, 512 * 1024, 3 * 1024 * 1024); in test_bitmaps_and_extents()
276 if (test_check_exists(cache, 512 * 1024, 3 * 1024 * 1024)) { in test_bitmaps_and_extents()
281 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
284 ret = test_add_free_space_entry(cache, 4 * 1024 * 1024, 4 * 1024 * 1024, 1); in test_bitmaps_and_extents()
290 ret = test_add_free_space_entry(cache, 2 * 1024 * 1024, 2 * 1024 * 1024, 0); in test_bitmaps_and_extents()
296 ret = btrfs_remove_free_space(cache, 3 * 1024 * 1024, 4 * 1024 * 1024); in test_bitmaps_and_extents()
302 if (test_check_exists(cache, 3 * 1024 * 1024, 4 * 1024 * 1024)) { in test_bitmaps_and_extents()
317 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
318 ret = test_add_free_space_entry(cache, bitmap_offset + 4 * 1024 * 1024, in test_bitmaps_and_extents()
325 ret = test_add_free_space_entry(cache, bitmap_offset - 1 * 1024 * 1024, in test_bitmaps_and_extents()
332 ret = btrfs_remove_free_space(cache, bitmap_offset + 1 * 1024 * 1024, in test_bitmaps_and_extents()
339 if (test_check_exists(cache, bitmap_offset + 1 * 1024 * 1024, in test_bitmaps_and_extents()
345 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
353 ret = test_add_free_space_entry(cache, 1 * 1024 * 1024, 2 * 1024 * 1024, 1); in test_bitmaps_and_extents()
359 ret = test_add_free_space_entry(cache, 3 * 1024 * 1024, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
365 ret = btrfs_remove_free_space(cache, 1 * 1024 * 1024, 3 * 1024 * 1024); in test_bitmaps_and_extents()
371 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
384 check_num_extents_and_bitmaps(const struct btrfs_block_group_cache *cache, in check_num_extents_and_bitmaps() argument
388 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
390 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
393 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
395 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
402 static int check_cache_empty(struct btrfs_block_group_cache *cache) in check_cache_empty() argument
411 if (cache->free_space_ctl->free_space != 0) { in check_cache_empty()
417 offset = btrfs_find_space_for_alloc(cache, 0, 4096, 0, in check_cache_empty()
426 return check_num_extents_and_bitmaps(cache, 0, 0); in check_cache_empty()
443 test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) in test_steal_space_from_bitmap_to_extent() argument
472 use_bitmap_op = cache->free_space_ctl->op->use_bitmap; in test_steal_space_from_bitmap_to_extent()
473 cache->free_space_ctl->op->use_bitmap = test_use_bitmap; in test_steal_space_from_bitmap_to_extent()
478 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
486 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 + 512 * 1024, in test_steal_space_from_bitmap_to_extent()
493 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
504 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
513 if (!test_check_exists(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
518 if (!test_check_exists(cache, 128 * 1024 * 1024 + 512 * 1024, in test_steal_space_from_bitmap_to_extent()
528 if (test_check_exists(cache, 128 * 1024 * 1024 + 768 * 1024, in test_steal_space_from_bitmap_to_extent()
538 if (test_check_exists(cache, 128 * 1024 * 1024 + 256 * 1024, in test_steal_space_from_bitmap_to_extent()
548 if (test_check_exists(cache, 128 * 1024 * 1024, in test_steal_space_from_bitmap_to_extent()
559 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024, 512 * 1024); in test_steal_space_from_bitmap_to_extent()
565 if (!test_check_exists(cache, 128 * 1024 * 1024, 512 * 1024)) { in test_steal_space_from_bitmap_to_extent()
574 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
584 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 + 16 * 1024 * 1024, in test_steal_space_from_bitmap_to_extent()
595 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
604 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 - 128 * 1024, in test_steal_space_from_bitmap_to_extent()
611 if (!test_check_exists(cache, 128 * 1024 * 1024 - 128 * 1024, in test_steal_space_from_bitmap_to_extent()
621 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
640 if (!test_check_exists(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
646 if (cache->free_space_ctl->free_space != (1 * 1024 * 1024 + 4096)) { in test_steal_space_from_bitmap_to_extent()
651 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
661 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
665 if (cache->free_space_ctl->free_space != 4096) { in test_steal_space_from_bitmap_to_extent()
670 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
679 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
683 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
694 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 + 128 * 1024, in test_steal_space_from_bitmap_to_extent()
702 ret = test_add_free_space_entry(cache, 0, in test_steal_space_from_bitmap_to_extent()
709 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
720 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
729 if (!test_check_exists(cache, 128 * 1024 * 1024 + 128 * 1024, in test_steal_space_from_bitmap_to_extent()
734 if (!test_check_exists(cache, 128 * 1024 * 1024 - 768 * 1024, in test_steal_space_from_bitmap_to_extent()
744 if (test_check_exists(cache, 0, in test_steal_space_from_bitmap_to_extent()
754 if (test_check_exists(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
765 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
772 if (!test_check_exists(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
782 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
792 ret = btrfs_add_free_space(cache, 32 * 1024 * 1024, 8192); in test_steal_space_from_bitmap_to_extent()
803 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024, 128 * 1024); in test_steal_space_from_bitmap_to_extent()
809 if (!test_check_exists(cache, 128 * 1024 * 1024, 128 * 1024)) { in test_steal_space_from_bitmap_to_extent()
818 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
837 if (!test_check_exists(cache, 128 * 1024 * 1024 - 768 * 1024, in test_steal_space_from_bitmap_to_extent()
843 if (cache->free_space_ctl->free_space != (1 * 1024 * 1024 + 8192)) { in test_steal_space_from_bitmap_to_extent()
848 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
858 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
862 if (cache->free_space_ctl->free_space != 8192) { in test_steal_space_from_bitmap_to_extent()
867 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
876 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
880 cache->free_space_ctl->op->use_bitmap = use_bitmap_op; in test_steal_space_from_bitmap_to_extent()
881 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
888 struct btrfs_block_group_cache *cache; in btrfs_test_free_space_cache() local
894 cache = init_test_block_group(); in btrfs_test_free_space_cache()
895 if (!cache) { in btrfs_test_free_space_cache()
911 cache->fs_info = root->fs_info; in btrfs_test_free_space_cache()
913 ret = test_extents(cache); in btrfs_test_free_space_cache()
916 ret = test_bitmaps(cache); in btrfs_test_free_space_cache()
919 ret = test_bitmaps_and_extents(cache); in btrfs_test_free_space_cache()
923 ret = test_steal_space_from_bitmap_to_extent(cache); in btrfs_test_free_space_cache()
925 __btrfs_remove_free_space_cache(cache->free_space_ctl); in btrfs_test_free_space_cache()
926 kfree(cache->free_space_ctl); in btrfs_test_free_space_cache()
927 kfree(cache); in btrfs_test_free_space_cache()