Lines Matching refs:cache
27 struct btrfs_block_group_cache *cache; in init_test_block_group() local
29 cache = kzalloc(sizeof(*cache), GFP_NOFS); in init_test_block_group()
30 if (!cache) in init_test_block_group()
32 cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl), in init_test_block_group()
34 if (!cache->free_space_ctl) { in init_test_block_group()
35 kfree(cache); in init_test_block_group()
39 cache->key.objectid = 0; in init_test_block_group()
40 cache->key.offset = 1024 * 1024 * 1024; in init_test_block_group()
41 cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; in init_test_block_group()
42 cache->sectorsize = 4096; in init_test_block_group()
43 cache->full_stripe_len = 4096; in init_test_block_group()
45 spin_lock_init(&cache->lock); in init_test_block_group()
46 INIT_LIST_HEAD(&cache->list); in init_test_block_group()
47 INIT_LIST_HEAD(&cache->cluster_list); in init_test_block_group()
48 INIT_LIST_HEAD(&cache->bg_list); in init_test_block_group()
50 btrfs_init_free_space_ctl(cache); in init_test_block_group()
52 return cache; in init_test_block_group()
60 static int test_extents(struct btrfs_block_group_cache *cache) in test_extents() argument
67 ret = btrfs_add_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
73 ret = btrfs_remove_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
79 if (test_check_exists(cache, 0, 4 * 1024 * 1024)) { in test_extents()
85 ret = btrfs_add_free_space(cache, 0, 4 * 1024 * 1024); in test_extents()
91 ret = btrfs_remove_free_space(cache, 3 * 1024 * 1024, 1 * 1024 * 1024); in test_extents()
97 ret = btrfs_remove_free_space(cache, 0, 1 * 1024 * 1024); in test_extents()
103 ret = btrfs_remove_free_space(cache, 2 * 1024 * 1024, 4096); in test_extents()
109 if (test_check_exists(cache, 0, 1 * 1024 * 1024)) { in test_extents()
114 if (test_check_exists(cache, 2 * 1024 * 1024, 4096)) { in test_extents()
119 if (test_check_exists(cache, 3 * 1024 * 1024, 1 * 1024 * 1024)) { in test_extents()
125 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_extents()
130 static int test_bitmaps(struct btrfs_block_group_cache *cache) in test_bitmaps() argument
137 ret = test_add_free_space_entry(cache, 0, 4 * 1024 * 1024, 1); in test_bitmaps()
143 ret = btrfs_remove_free_space(cache, 0, 4 * 1024 * 1024); in test_bitmaps()
149 if (test_check_exists(cache, 0, 4 * 1024 * 1024)) { in test_bitmaps()
154 ret = test_add_free_space_entry(cache, 0, 4 * 1024 * 1024, 1); in test_bitmaps()
160 ret = btrfs_remove_free_space(cache, 1 * 1024 * 1024, 2 * 1024 * 1024); in test_bitmaps()
173 ret = test_add_free_space_entry(cache, next_bitmap_offset - in test_bitmaps()
181 ret = btrfs_remove_free_space(cache, next_bitmap_offset - in test_bitmaps()
188 if (test_check_exists(cache, next_bitmap_offset - (1 * 1024 * 1024), in test_bitmaps()
194 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps()
200 static int test_bitmaps_and_extents(struct btrfs_block_group_cache *cache) in test_bitmaps_and_extents() argument
212 ret = test_add_free_space_entry(cache, 4 * 1024 * 1024, 1 * 1024 * 1024, 1); in test_bitmaps_and_extents()
218 ret = test_add_free_space_entry(cache, 0, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
224 ret = btrfs_remove_free_space(cache, 0, 1 * 1024 * 1024); in test_bitmaps_and_extents()
230 if (test_check_exists(cache, 0, 1 * 1024 * 1024)) { in test_bitmaps_and_extents()
236 ret = test_add_free_space_entry(cache, 0, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
242 ret = btrfs_remove_free_space(cache, 4 * 1024 * 1024, 1 * 1024 * 1024); in test_bitmaps_and_extents()
248 if (test_check_exists(cache, 4 * 1024 * 1024, 1 * 1024 * 1024)) { in test_bitmaps_and_extents()
257 ret = test_add_free_space_entry(cache, 1 * 1024 * 1024, 4 * 1024 * 1024, 1); in test_bitmaps_and_extents()
263 ret = btrfs_remove_free_space(cache, 512 * 1024, 3 * 1024 * 1024); in test_bitmaps_and_extents()
269 if (test_check_exists(cache, 512 * 1024, 3 * 1024 * 1024)) { in test_bitmaps_and_extents()
274 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
277 ret = test_add_free_space_entry(cache, 4 * 1024 * 1024, 4 * 1024 * 1024, 1); in test_bitmaps_and_extents()
283 ret = test_add_free_space_entry(cache, 2 * 1024 * 1024, 2 * 1024 * 1024, 0); in test_bitmaps_and_extents()
289 ret = btrfs_remove_free_space(cache, 3 * 1024 * 1024, 4 * 1024 * 1024); in test_bitmaps_and_extents()
295 if (test_check_exists(cache, 3 * 1024 * 1024, 4 * 1024 * 1024)) { in test_bitmaps_and_extents()
310 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
311 ret = test_add_free_space_entry(cache, bitmap_offset + 4 * 1024 * 1024, in test_bitmaps_and_extents()
318 ret = test_add_free_space_entry(cache, bitmap_offset - 1 * 1024 * 1024, in test_bitmaps_and_extents()
325 ret = btrfs_remove_free_space(cache, bitmap_offset + 1 * 1024 * 1024, in test_bitmaps_and_extents()
332 if (test_check_exists(cache, bitmap_offset + 1 * 1024 * 1024, in test_bitmaps_and_extents()
338 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
346 ret = test_add_free_space_entry(cache, 1 * 1024 * 1024, 2 * 1024 * 1024, 1); in test_bitmaps_and_extents()
352 ret = test_add_free_space_entry(cache, 3 * 1024 * 1024, 1 * 1024 * 1024, 0); in test_bitmaps_and_extents()
358 ret = btrfs_remove_free_space(cache, 1 * 1024 * 1024, 3 * 1024 * 1024); in test_bitmaps_and_extents()
364 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
377 check_num_extents_and_bitmaps(const struct btrfs_block_group_cache *cache, in check_num_extents_and_bitmaps() argument
381 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
383 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
386 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
388 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
395 static int check_cache_empty(struct btrfs_block_group_cache *cache) in check_cache_empty() argument
404 if (cache->free_space_ctl->free_space != 0) { in check_cache_empty()
410 offset = btrfs_find_space_for_alloc(cache, 0, 4096, 0, in check_cache_empty()
419 return check_num_extents_and_bitmaps(cache, 0, 0); in check_cache_empty()
436 test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache) in test_steal_space_from_bitmap_to_extent() argument
465 use_bitmap_op = cache->free_space_ctl->op->use_bitmap; in test_steal_space_from_bitmap_to_extent()
466 cache->free_space_ctl->op->use_bitmap = test_use_bitmap; in test_steal_space_from_bitmap_to_extent()
471 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
479 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 + 512 * 1024, in test_steal_space_from_bitmap_to_extent()
486 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
497 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
506 if (!test_check_exists(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
511 if (!test_check_exists(cache, 128 * 1024 * 1024 + 512 * 1024, in test_steal_space_from_bitmap_to_extent()
521 if (test_check_exists(cache, 128 * 1024 * 1024 + 768 * 1024, in test_steal_space_from_bitmap_to_extent()
531 if (test_check_exists(cache, 128 * 1024 * 1024 + 256 * 1024, in test_steal_space_from_bitmap_to_extent()
541 if (test_check_exists(cache, 128 * 1024 * 1024, in test_steal_space_from_bitmap_to_extent()
552 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024, 512 * 1024); in test_steal_space_from_bitmap_to_extent()
558 if (!test_check_exists(cache, 128 * 1024 * 1024, 512 * 1024)) { in test_steal_space_from_bitmap_to_extent()
567 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
577 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 + 16 * 1024 * 1024, in test_steal_space_from_bitmap_to_extent()
588 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
597 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 - 128 * 1024, in test_steal_space_from_bitmap_to_extent()
604 if (!test_check_exists(cache, 128 * 1024 * 1024 - 128 * 1024, in test_steal_space_from_bitmap_to_extent()
614 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
633 if (!test_check_exists(cache, 128 * 1024 * 1024 - 256 * 1024, in test_steal_space_from_bitmap_to_extent()
639 if (cache->free_space_ctl->free_space != (1 * 1024 * 1024 + 4096)) { in test_steal_space_from_bitmap_to_extent()
644 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
654 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
658 if (cache->free_space_ctl->free_space != 4096) { in test_steal_space_from_bitmap_to_extent()
663 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
672 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
676 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
687 ret = test_add_free_space_entry(cache, 128 * 1024 * 1024 + 128 * 1024, in test_steal_space_from_bitmap_to_extent()
695 ret = test_add_free_space_entry(cache, 0, in test_steal_space_from_bitmap_to_extent()
702 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
713 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
722 if (!test_check_exists(cache, 128 * 1024 * 1024 + 128 * 1024, in test_steal_space_from_bitmap_to_extent()
727 if (!test_check_exists(cache, 128 * 1024 * 1024 - 768 * 1024, in test_steal_space_from_bitmap_to_extent()
737 if (test_check_exists(cache, 0, in test_steal_space_from_bitmap_to_extent()
747 if (test_check_exists(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
758 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
765 if (!test_check_exists(cache, 128 * 1024 * 1024 - 512 * 1024, in test_steal_space_from_bitmap_to_extent()
775 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
785 ret = btrfs_add_free_space(cache, 32 * 1024 * 1024, 8192); in test_steal_space_from_bitmap_to_extent()
796 ret = btrfs_add_free_space(cache, 128 * 1024 * 1024, 128 * 1024); in test_steal_space_from_bitmap_to_extent()
802 if (!test_check_exists(cache, 128 * 1024 * 1024, 128 * 1024)) { in test_steal_space_from_bitmap_to_extent()
811 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
830 if (!test_check_exists(cache, 128 * 1024 * 1024 - 768 * 1024, in test_steal_space_from_bitmap_to_extent()
836 if (cache->free_space_ctl->free_space != (1 * 1024 * 1024 + 8192)) { in test_steal_space_from_bitmap_to_extent()
841 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
851 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
855 if (cache->free_space_ctl->free_space != 8192) { in test_steal_space_from_bitmap_to_extent()
860 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
869 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
873 cache->free_space_ctl->op->use_bitmap = use_bitmap_op; in test_steal_space_from_bitmap_to_extent()
874 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
881 struct btrfs_block_group_cache *cache; in btrfs_test_free_space_cache() local
886 cache = init_test_block_group(); in btrfs_test_free_space_cache()
887 if (!cache) { in btrfs_test_free_space_cache()
892 ret = test_extents(cache); in btrfs_test_free_space_cache()
895 ret = test_bitmaps(cache); in btrfs_test_free_space_cache()
898 ret = test_bitmaps_and_extents(cache); in btrfs_test_free_space_cache()
902 ret = test_steal_space_from_bitmap_to_extent(cache); in btrfs_test_free_space_cache()
904 __btrfs_remove_free_space_cache(cache->free_space_ctl); in btrfs_test_free_space_cache()
905 kfree(cache->free_space_ctl); in btrfs_test_free_space_cache()
906 kfree(cache); in btrfs_test_free_space_cache()