Lines Matching full:cache

10 #include "../free-space-cache.h"
20 static int test_extents(struct btrfs_block_group *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, u32 sectorsize) in test_bitmaps() argument
97 ret = test_add_free_space_entry(cache, 0, SZ_4M, 1); in test_bitmaps()
103 ret = btrfs_remove_free_space(cache, 0, SZ_4M); in test_bitmaps()
109 if (test_check_exists(cache, 0, SZ_4M)) { in test_bitmaps()
114 ret = test_add_free_space_entry(cache, 0, SZ_4M, 1); in test_bitmaps()
120 ret = btrfs_remove_free_space(cache, SZ_1M, SZ_2M); in test_bitmaps()
133 ret = test_add_free_space_entry(cache, next_bitmap_offset - SZ_2M, in test_bitmaps()
141 ret = btrfs_remove_free_space(cache, next_bitmap_offset - SZ_1M, SZ_2M); in test_bitmaps()
147 if (test_check_exists(cache, next_bitmap_offset - SZ_1M, SZ_2M)) { in test_bitmaps()
152 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps()
158 static int test_bitmaps_and_extents(struct btrfs_block_group *cache, in test_bitmaps_and_extents() argument
171 ret = test_add_free_space_entry(cache, SZ_4M, SZ_1M, 1); in test_bitmaps_and_extents()
177 ret = test_add_free_space_entry(cache, 0, SZ_1M, 0); in test_bitmaps_and_extents()
183 ret = btrfs_remove_free_space(cache, 0, SZ_1M); in test_bitmaps_and_extents()
189 if (test_check_exists(cache, 0, SZ_1M)) { in test_bitmaps_and_extents()
195 ret = test_add_free_space_entry(cache, 0, SZ_1M, 0); in test_bitmaps_and_extents()
201 ret = btrfs_remove_free_space(cache, SZ_4M, SZ_1M); in test_bitmaps_and_extents()
207 if (test_check_exists(cache, SZ_4M, SZ_1M)) { in test_bitmaps_and_extents()
216 ret = test_add_free_space_entry(cache, SZ_1M, SZ_4M, 1); in test_bitmaps_and_extents()
222 ret = btrfs_remove_free_space(cache, SZ_512K, 3 * SZ_1M); in test_bitmaps_and_extents()
228 if (test_check_exists(cache, SZ_512K, 3 * SZ_1M)) { in test_bitmaps_and_extents()
233 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
236 ret = test_add_free_space_entry(cache, SZ_4M, SZ_4M, 1); in test_bitmaps_and_extents()
242 ret = test_add_free_space_entry(cache, SZ_2M, SZ_2M, 0); in test_bitmaps_and_extents()
244 test_err("couldn't add extent to the cache %d", ret); in test_bitmaps_and_extents()
248 ret = btrfs_remove_free_space(cache, 3 * SZ_1M, SZ_4M); in test_bitmaps_and_extents()
254 if (test_check_exists(cache, 3 * SZ_1M, SZ_4M)) { in test_bitmaps_and_extents()
269 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
270 ret = test_add_free_space_entry(cache, bitmap_offset + SZ_4M, SZ_4M, 1); in test_bitmaps_and_extents()
276 ret = test_add_free_space_entry(cache, bitmap_offset - SZ_1M, in test_bitmaps_and_extents()
283 ret = btrfs_remove_free_space(cache, bitmap_offset + SZ_1M, 5 * SZ_1M); in test_bitmaps_and_extents()
289 if (test_check_exists(cache, bitmap_offset + SZ_1M, 5 * SZ_1M)) { in test_bitmaps_and_extents()
294 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
302 ret = test_add_free_space_entry(cache, SZ_1M, SZ_2M, 1); in test_bitmaps_and_extents()
308 ret = test_add_free_space_entry(cache, 3 * SZ_1M, SZ_1M, 0); in test_bitmaps_and_extents()
314 ret = btrfs_remove_free_space(cache, SZ_1M, 3 * SZ_1M); in test_bitmaps_and_extents()
320 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
333 check_num_extents_and_bitmaps(const struct btrfs_block_group *cache, in check_num_extents_and_bitmaps() argument
337 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
339 "incorrect # of extent entries in the cache: %d, expected %d", in check_num_extents_and_bitmaps()
340 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
343 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
345 "incorrect # of extent entries in the cache: %d, expected %d", in check_num_extents_and_bitmaps()
346 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
353 static int check_cache_empty(struct btrfs_block_group *cache) in check_cache_empty() argument
362 if (cache->free_space_ctl->free_space != 0) { in check_cache_empty()
363 test_err("cache free space is not 0"); in check_cache_empty()
368 offset = btrfs_find_space_for_alloc(cache, 0, 4096, 0, in check_cache_empty()
376 /* And no extent nor bitmap entries in the cache anymore. */ in check_cache_empty()
377 return check_num_extents_and_bitmaps(cache, 0, 0); in check_cache_empty()
395 test_steal_space_from_bitmap_to_extent(struct btrfs_block_group *cache, in test_steal_space_from_bitmap_to_extent() argument
402 .recalc_thresholds = cache->free_space_ctl->op->recalc_thresholds, in test_steal_space_from_bitmap_to_extent()
420 * cache->free_space_ctl->extents_thresh, which currently is in test_steal_space_from_bitmap_to_extent()
427 orig_free_space_ops = cache->free_space_ctl->op; in test_steal_space_from_bitmap_to_extent()
428 cache->free_space_ctl->op = &test_free_space_ops; in test_steal_space_from_bitmap_to_extent()
433 ret = test_add_free_space_entry(cache, SZ_128M - SZ_256K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
440 ret = test_add_free_space_entry(cache, SZ_128M + SZ_512K, in test_steal_space_from_bitmap_to_extent()
447 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
458 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
467 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
471 if (!test_check_exists(cache, SZ_128M + SZ_512K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
480 if (test_check_exists(cache, SZ_128M + 768 * SZ_1K, in test_steal_space_from_bitmap_to_extent()
482 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
490 if (test_check_exists(cache, SZ_128M + SZ_256K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
499 if (test_check_exists(cache, SZ_128M, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
506 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
509 ret = btrfs_add_free_space(cache, SZ_128M, SZ_512K); in test_steal_space_from_bitmap_to_extent()
515 if (!test_check_exists(cache, SZ_128M, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
522 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
524 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
534 ret = btrfs_add_free_space(cache, SZ_128M + SZ_16M, sectorsize); in test_steal_space_from_bitmap_to_extent()
542 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
544 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
553 ret = btrfs_add_free_space(cache, SZ_128M - SZ_128K, SZ_128K); in test_steal_space_from_bitmap_to_extent()
559 if (!test_check_exists(cache, SZ_128M - SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
568 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
576 * cache: in test_steal_space_from_bitmap_to_extent()
587 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
592 if (cache->free_space_ctl->free_space != (SZ_1M + sectorsize)) { in test_steal_space_from_bitmap_to_extent()
593 test_err("cache free space is not 1Mb + %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
597 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
602 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
611 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
615 if (cache->free_space_ctl->free_space != sectorsize) { in test_steal_space_from_bitmap_to_extent()
616 test_err("cache free space is not %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
620 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
629 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
633 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
644 ret = test_add_free_space_entry(cache, SZ_128M + SZ_128K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
651 ret = test_add_free_space_entry(cache, 0, SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
657 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
668 ret = btrfs_remove_free_space(cache, 0, SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
675 if (!test_check_exists(cache, SZ_128M + SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
679 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
688 if (test_check_exists(cache, 0, SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
689 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
697 if (test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
704 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
707 ret = btrfs_add_free_space(cache, SZ_128M - SZ_512K, SZ_512K); in test_steal_space_from_bitmap_to_extent()
713 if (!test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
720 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
722 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
732 ret = btrfs_add_free_space(cache, SZ_32M, 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
743 ret = btrfs_add_free_space(cache, SZ_128M, SZ_128K); in test_steal_space_from_bitmap_to_extent()
749 if (!test_check_exists(cache, SZ_128M, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
758 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
766 * cache: in test_steal_space_from_bitmap_to_extent()
777 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
782 if (cache->free_space_ctl->free_space != (SZ_1M + 2 * sectorsize)) { in test_steal_space_from_bitmap_to_extent()
783 test_err("cache free space is not 1Mb + %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
787 offset = btrfs_find_space_for_alloc(cache, 0, SZ_1M, 0, in test_steal_space_from_bitmap_to_extent()
791 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
800 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
804 if (cache->free_space_ctl->free_space != 2 * sectorsize) { in test_steal_space_from_bitmap_to_extent()
805 test_err("cache free space is not %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
809 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
818 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
822 cache->free_space_ctl->op = orig_free_space_ops; in test_steal_space_from_bitmap_to_extent()
823 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
831 struct btrfs_block_group *cache; in btrfs_test_free_space_cache() local
835 test_msg("running btrfs free space cache tests"); in btrfs_test_free_space_cache()
847 cache = btrfs_alloc_dummy_block_group(fs_info, in btrfs_test_free_space_cache()
849 if (!cache) { in btrfs_test_free_space_cache()
864 ret = test_extents(cache); in btrfs_test_free_space_cache()
867 ret = test_bitmaps(cache, sectorsize); in btrfs_test_free_space_cache()
870 ret = test_bitmaps_and_extents(cache, sectorsize); in btrfs_test_free_space_cache()
874 ret = test_steal_space_from_bitmap_to_extent(cache, sectorsize); in btrfs_test_free_space_cache()
876 btrfs_free_dummy_block_group(cache); in btrfs_test_free_space_cache()