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
419 * cache->free_space_ctl->extents_thresh, which currently is in test_steal_space_from_bitmap_to_extent()
426 orig_free_space_ops = cache->free_space_ctl->op; in test_steal_space_from_bitmap_to_extent()
427 cache->free_space_ctl->op = &test_free_space_ops; in test_steal_space_from_bitmap_to_extent()
432 ret = test_add_free_space_entry(cache, SZ_128M - SZ_256K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
439 ret = test_add_free_space_entry(cache, SZ_128M + SZ_512K, in test_steal_space_from_bitmap_to_extent()
446 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
457 ret = btrfs_remove_free_space(cache, in test_steal_space_from_bitmap_to_extent()
466 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
470 if (!test_check_exists(cache, SZ_128M + SZ_512K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
479 if (test_check_exists(cache, SZ_128M + 768 * SZ_1K, in test_steal_space_from_bitmap_to_extent()
481 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
489 if (test_check_exists(cache, SZ_128M + SZ_256K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
498 if (test_check_exists(cache, SZ_128M, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
505 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
508 ret = btrfs_add_free_space(cache, SZ_128M, SZ_512K); in test_steal_space_from_bitmap_to_extent()
514 if (!test_check_exists(cache, SZ_128M, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
521 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
523 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
533 ret = btrfs_add_free_space(cache, SZ_128M + SZ_16M, sectorsize); in test_steal_space_from_bitmap_to_extent()
541 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
543 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
552 ret = btrfs_add_free_space(cache, SZ_128M - SZ_128K, SZ_128K); in test_steal_space_from_bitmap_to_extent()
558 if (!test_check_exists(cache, SZ_128M - SZ_128K, SZ_128K)) { 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()
575 * cache: in test_steal_space_from_bitmap_to_extent()
586 if (!test_check_exists(cache, SZ_128M - SZ_256K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
591 if (cache->free_space_ctl->free_space != (SZ_1M + sectorsize)) { in test_steal_space_from_bitmap_to_extent()
592 test_err("cache free space is not 1Mb + %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
596 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
601 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
610 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
614 if (cache->free_space_ctl->free_space != sectorsize) { in test_steal_space_from_bitmap_to_extent()
615 test_err("cache free space is not %u", sectorsize); in test_steal_space_from_bitmap_to_extent()
619 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
628 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
632 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
643 ret = test_add_free_space_entry(cache, SZ_128M + SZ_128K, SZ_128K, 0); in test_steal_space_from_bitmap_to_extent()
650 ret = test_add_free_space_entry(cache, 0, SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
656 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
667 ret = btrfs_remove_free_space(cache, 0, SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
674 if (!test_check_exists(cache, SZ_128M + SZ_128K, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
678 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
687 if (test_check_exists(cache, 0, SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
688 test_err("bitmap region not removed from space cache"); in test_steal_space_from_bitmap_to_extent()
696 if (test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
703 * lets make sure the free space cache marks it as free in the bitmap, in test_steal_space_from_bitmap_to_extent()
706 ret = btrfs_add_free_space(cache, SZ_128M - SZ_512K, SZ_512K); in test_steal_space_from_bitmap_to_extent()
712 if (!test_check_exists(cache, SZ_128M - SZ_512K, SZ_512K)) { in test_steal_space_from_bitmap_to_extent()
719 * the cache after adding that free space region. in test_steal_space_from_bitmap_to_extent()
721 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
731 ret = btrfs_add_free_space(cache, SZ_32M, 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
742 ret = btrfs_add_free_space(cache, SZ_128M, SZ_128K); in test_steal_space_from_bitmap_to_extent()
748 if (!test_check_exists(cache, SZ_128M, SZ_128K)) { in test_steal_space_from_bitmap_to_extent()
757 ret = check_num_extents_and_bitmaps(cache, 2, 1); in test_steal_space_from_bitmap_to_extent()
765 * cache: in test_steal_space_from_bitmap_to_extent()
776 if (!test_check_exists(cache, SZ_128M - 768 * SZ_1K, SZ_1M)) { in test_steal_space_from_bitmap_to_extent()
781 if (cache->free_space_ctl->free_space != (SZ_1M + 2 * sectorsize)) { in test_steal_space_from_bitmap_to_extent()
782 test_err("cache free space is not 1Mb + %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
786 offset = btrfs_find_space_for_alloc(cache, 0, SZ_1M, 0, in test_steal_space_from_bitmap_to_extent()
790 "failed to allocate 1Mb from space cache, returned offset is: %llu", in test_steal_space_from_bitmap_to_extent()
799 ret = check_num_extents_and_bitmaps(cache, 1, 1); in test_steal_space_from_bitmap_to_extent()
803 if (cache->free_space_ctl->free_space != 2 * sectorsize) { in test_steal_space_from_bitmap_to_extent()
804 test_err("cache free space is not %u", 2 * sectorsize); in test_steal_space_from_bitmap_to_extent()
808 offset = btrfs_find_space_for_alloc(cache, in test_steal_space_from_bitmap_to_extent()
817 ret = check_cache_empty(cache); in test_steal_space_from_bitmap_to_extent()
821 cache->free_space_ctl->op = orig_free_space_ops; in test_steal_space_from_bitmap_to_extent()
822 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_steal_space_from_bitmap_to_extent()
830 struct btrfs_block_group *cache; in btrfs_test_free_space_cache() local
834 test_msg("running btrfs free space cache tests"); in btrfs_test_free_space_cache()
846 cache = btrfs_alloc_dummy_block_group(fs_info, in btrfs_test_free_space_cache()
848 if (!cache) { in btrfs_test_free_space_cache()
863 ret = test_extents(cache); in btrfs_test_free_space_cache()
866 ret = test_bitmaps(cache, sectorsize); in btrfs_test_free_space_cache()
869 ret = test_bitmaps_and_extents(cache, sectorsize); in btrfs_test_free_space_cache()
873 ret = test_steal_space_from_bitmap_to_extent(cache, sectorsize); in btrfs_test_free_space_cache()
875 btrfs_free_dummy_block_group(cache); in btrfs_test_free_space_cache()