Lines Matching full:cache
10 #include "../free-space-cache.h"
20 static int test_extents(struct btrfs_block_group_cache *cache) in test_extents() argument
27 ret = btrfs_add_free_space(cache, 0, SZ_4M); in test_extents()
33 ret = btrfs_remove_free_space(cache, 0, SZ_4M); in test_extents()
39 if (test_check_exists(cache, 0, SZ_4M)) { in test_extents()
45 ret = btrfs_add_free_space(cache, 0, SZ_4M); in test_extents()
51 ret = btrfs_remove_free_space(cache, 3 * SZ_1M, SZ_1M); in test_extents()
57 ret = btrfs_remove_free_space(cache, 0, SZ_1M); in test_extents()
63 ret = btrfs_remove_free_space(cache, SZ_2M, 4096); in test_extents()
69 if (test_check_exists(cache, 0, SZ_1M)) { in test_extents()
74 if (test_check_exists(cache, SZ_2M, 4096)) { in test_extents()
79 if (test_check_exists(cache, 3 * SZ_1M, SZ_1M)) { in test_extents()
85 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_extents()
90 static int test_bitmaps(struct btrfs_block_group_cache *cache, in test_bitmaps() argument
98 ret = test_add_free_space_entry(cache, 0, SZ_4M, 1); in test_bitmaps()
104 ret = btrfs_remove_free_space(cache, 0, SZ_4M); in test_bitmaps()
110 if (test_check_exists(cache, 0, SZ_4M)) { in test_bitmaps()
115 ret = test_add_free_space_entry(cache, 0, SZ_4M, 1); in test_bitmaps()
121 ret = btrfs_remove_free_space(cache, SZ_1M, SZ_2M); in test_bitmaps()
134 ret = test_add_free_space_entry(cache, next_bitmap_offset - SZ_2M, in test_bitmaps()
142 ret = btrfs_remove_free_space(cache, next_bitmap_offset - SZ_1M, SZ_2M); in test_bitmaps()
148 if (test_check_exists(cache, next_bitmap_offset - SZ_1M, SZ_2M)) { in test_bitmaps()
153 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps()
159 static int test_bitmaps_and_extents(struct btrfs_block_group_cache *cache, in test_bitmaps_and_extents() argument
172 ret = test_add_free_space_entry(cache, SZ_4M, SZ_1M, 1); in test_bitmaps_and_extents()
178 ret = test_add_free_space_entry(cache, 0, SZ_1M, 0); in test_bitmaps_and_extents()
184 ret = btrfs_remove_free_space(cache, 0, SZ_1M); in test_bitmaps_and_extents()
190 if (test_check_exists(cache, 0, SZ_1M)) { in test_bitmaps_and_extents()
196 ret = test_add_free_space_entry(cache, 0, SZ_1M, 0); in test_bitmaps_and_extents()
202 ret = btrfs_remove_free_space(cache, SZ_4M, SZ_1M); in test_bitmaps_and_extents()
208 if (test_check_exists(cache, SZ_4M, SZ_1M)) { in test_bitmaps_and_extents()
217 ret = test_add_free_space_entry(cache, SZ_1M, SZ_4M, 1); in test_bitmaps_and_extents()
223 ret = btrfs_remove_free_space(cache, SZ_512K, 3 * SZ_1M); in test_bitmaps_and_extents()
229 if (test_check_exists(cache, SZ_512K, 3 * SZ_1M)) { in test_bitmaps_and_extents()
234 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
237 ret = test_add_free_space_entry(cache, SZ_4M, SZ_4M, 1); in test_bitmaps_and_extents()
243 ret = test_add_free_space_entry(cache, SZ_2M, SZ_2M, 0); in test_bitmaps_and_extents()
245 test_err("couldn't add extent to the cache %d", ret); in test_bitmaps_and_extents()
249 ret = btrfs_remove_free_space(cache, 3 * SZ_1M, SZ_4M); in test_bitmaps_and_extents()
255 if (test_check_exists(cache, 3 * SZ_1M, SZ_4M)) { in test_bitmaps_and_extents()
270 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
271 ret = test_add_free_space_entry(cache, bitmap_offset + SZ_4M, SZ_4M, 1); in test_bitmaps_and_extents()
277 ret = test_add_free_space_entry(cache, bitmap_offset - SZ_1M, in test_bitmaps_and_extents()
284 ret = btrfs_remove_free_space(cache, bitmap_offset + SZ_1M, 5 * SZ_1M); in test_bitmaps_and_extents()
290 if (test_check_exists(cache, bitmap_offset + SZ_1M, 5 * SZ_1M)) { in test_bitmaps_and_extents()
295 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
303 ret = test_add_free_space_entry(cache, SZ_1M, SZ_2M, 1); in test_bitmaps_and_extents()
309 ret = test_add_free_space_entry(cache, 3 * SZ_1M, SZ_1M, 0); in test_bitmaps_and_extents()
315 ret = btrfs_remove_free_space(cache, SZ_1M, 3 * SZ_1M); in test_bitmaps_and_extents()
321 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
334 check_num_extents_and_bitmaps(const struct btrfs_block_group_cache *cache, in check_num_extents_and_bitmaps() argument
338 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
340 "incorrect # of extent entries in the cache: %d, expected %d", in check_num_extents_and_bitmaps()
341 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
344 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
346 "incorrect # of extent entries in the cache: %d, expected %d", in check_num_extents_and_bitmaps()
347 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
354 static int check_cache_empty(struct btrfs_block_group_cache *cache) in check_cache_empty() argument
363 if (cache->free_space_ctl->free_space != 0) { in check_cache_empty()
364 test_err("cache free space is not 0"); in check_cache_empty()
369 offset = btrfs_find_space_for_alloc(cache, 0, 4096, 0, in check_cache_empty()
377 /* And no extent nor bitmap entries in the cache anymore. */ in check_cache_empty()
378 return check_num_extents_and_bitmaps(cache, 0, 0); in check_cache_empty()
396 test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache, in test_steal_space_from_bitmap_to_extent() argument
403 .recalc_thresholds = cache->free_space_ctl->op->recalc_thresholds, in test_steal_space_from_bitmap_to_extent()
421 * cache->free_space_ctl->extents_thresh, which currently is in test_steal_space_from_bitmap_to_extent()
428 orig_free_space_ops = cache->free_space_ctl->op; in test_steal_space_from_bitmap_to_extent()
429 cache->free_space_ctl->op = &test_free_space_ops; in test_steal_space_from_bitmap_to_extent()
434 ret = test_add_free_space_entry(cache, SZ_128M - SZ_256K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
441 ret = test_add_free_space_entry(cache, SZ_128M + SZ_512K, in test_steal_space_from_bitmap_to_extent()
448 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
459 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
468 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
472 if (!test_check_exists(cache, SZ_128M + SZ_512K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
481 if (test_check_exists(cache, SZ_128M + 768 * SZ_1K, in test_steal_space_from_bitmap_to_extent()
483 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
491 if (test_check_exists(cache, SZ_128M + SZ_256K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
500 if (test_check_exists(cache, SZ_128M, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
507 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
510 ret = btrfs_add_free_space(cache, SZ_128M, SZ_512K); in test_steal_space_from_bitmap_to_extent()
516 if (!test_check_exists(cache, SZ_128M, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
523 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
525 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
535 ret = btrfs_add_free_space(cache, SZ_128M + SZ_16M, sectorsize); in test_steal_space_from_bitmap_to_extent()
543 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
545 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
554 ret = btrfs_add_free_space(cache, SZ_128M - SZ_128K, SZ_128K); in test_steal_space_from_bitmap_to_extent()
560 if (!test_check_exists(cache, SZ_128M - SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
569 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
577 * cache: in test_steal_space_from_bitmap_to_extent()
588 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
593 if (cache->free_space_ctl->free_space != (SZ_1M + sectorsize)) { in test_steal_space_from_bitmap_to_extent()
594 test_err("cache free space is not 1Mb + %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
598 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
603 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
612 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
616 if (cache->free_space_ctl->free_space != sectorsize) { in test_steal_space_from_bitmap_to_extent()
617 test_err("cache free space is not %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
621 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
630 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
634 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
645 ret = test_add_free_space_entry(cache, SZ_128M + SZ_128K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
652 ret = test_add_free_space_entry(cache, 0, SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
658 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
669 ret = btrfs_remove_free_space(cache, 0, SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
676 if (!test_check_exists(cache, SZ_128M + SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
680 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
689 if (test_check_exists(cache, 0, SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
690 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
698 if (test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
705 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
708 ret = btrfs_add_free_space(cache, SZ_128M - SZ_512K, SZ_512K); in test_steal_space_from_bitmap_to_extent()
714 if (!test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
721 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
723 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
733 ret = btrfs_add_free_space(cache, SZ_32M, 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
744 ret = btrfs_add_free_space(cache, SZ_128M, SZ_128K); in test_steal_space_from_bitmap_to_extent()
750 if (!test_check_exists(cache, SZ_128M, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
759 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
767 * cache: in test_steal_space_from_bitmap_to_extent()
778 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
783 if (cache->free_space_ctl->free_space != (SZ_1M + 2 * sectorsize)) { in test_steal_space_from_bitmap_to_extent()
784 test_err("cache free space is not 1Mb + %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
788 offset = btrfs_find_space_for_alloc(cache, 0, SZ_1M, 0, in test_steal_space_from_bitmap_to_extent()
792 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
801 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
805 if (cache->free_space_ctl->free_space != 2 * sectorsize) { in test_steal_space_from_bitmap_to_extent()
806 test_err("cache free space is not %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
810 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
819 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
823 cache->free_space_ctl->op = orig_free_space_ops; in test_steal_space_from_bitmap_to_extent()
824 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
832 struct btrfs_block_group_cache *cache; in btrfs_test_free_space_cache() local
836 test_msg("running btrfs free space cache tests"); in btrfs_test_free_space_cache()
848 cache = btrfs_alloc_dummy_block_group(fs_info, in btrfs_test_free_space_cache()
850 if (!cache) { in btrfs_test_free_space_cache()
865 ret = test_extents(cache); in btrfs_test_free_space_cache()
868 ret = test_bitmaps(cache, sectorsize); in btrfs_test_free_space_cache()
871 ret = test_bitmaps_and_extents(cache, sectorsize); in btrfs_test_free_space_cache()
875 ret = test_steal_space_from_bitmap_to_extent(cache, sectorsize); in btrfs_test_free_space_cache()
877 btrfs_free_dummy_block_group(cache); in btrfs_test_free_space_cache()