Lines Matching +full:free +full:- +full:running
1 // SPDX-License-Identifier: GPL-2.0
7 #include "btrfs-tests.h"
9 #include "../disk-io.h"
10 #include "../free-space-cache.h"
11 #include "../block-group.h"
24 test_msg("running extent only tests"); in test_extents()
41 return -1; in test_extents()
71 return -1; in test_extents()
76 return -1; in test_extents()
81 return -1; in test_extents()
85 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_extents()
95 test_msg("running bitmap only tests"); in test_bitmaps()
111 return -1; 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()
149 return -1; in test_bitmaps()
152 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps()
164 test_msg("running bitmap and extent tests"); in test_bitmaps_and_extents()
168 * bitmap, but the free space completely in the extent and then in test_bitmaps_and_extents()
191 return -1; in test_bitmaps_and_extents()
197 test_err("couldn't re-add extent entry %d", ret); in test_bitmaps_and_extents()
209 return -1; in test_bitmaps_and_extents()
230 return -1; in test_bitmaps_and_extents()
233 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
256 return -1; in test_bitmaps_and_extents()
269 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
276 ret = test_add_free_space_entry(cache, bitmap_offset - SZ_1M, in test_bitmaps_and_extents()
285 test_err("failed to free our space %d", ret); in test_bitmaps_and_extents()
291 return -1; in test_bitmaps_and_extents()
294 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
297 * This blew up before, we have part of the free space in a bitmap and in test_bitmaps_and_extents()
299 * to return -EAGAIN back from btrfs_remove_extent, make sure this in test_bitmaps_and_extents()
320 __btrfs_remove_free_space_cache(cache->free_space_ctl); in test_bitmaps_and_extents()
328 return ctl->free_extents > 0; in test_use_bitmap()
337 if (cache->free_space_ctl->free_extents != num_extents) { in check_num_extents_and_bitmaps()
340 cache->free_space_ctl->free_extents, num_extents); in check_num_extents_and_bitmaps()
341 return -EINVAL; in check_num_extents_and_bitmaps()
343 if (cache->free_space_ctl->total_bitmaps != num_bitmaps) { in check_num_extents_and_bitmaps()
346 cache->free_space_ctl->total_bitmaps, num_bitmaps); in check_num_extents_and_bitmaps()
347 return -EINVAL; in check_num_extents_and_bitmaps()
359 * Now lets confirm that there's absolutely no free space left to in check_cache_empty()
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()
364 return -EINVAL; in check_cache_empty()
373 return -EINVAL; in check_cache_empty()
381 * Before we were able to steal free space from a bitmap entry to an extent
382 * entry, we could end up with 2 entries representing a contiguous free space.
391 * from extent entries, both for clustered and non-clustered allocation
402 .recalc_thresholds = cache->free_space_ctl->op->recalc_thresholds, in test_steal_space_from_bitmap_to_extent()
407 test_msg("running space stealing from bitmap to extent tests"); in test_steal_space_from_bitmap_to_extent()
413 * removing free space to reach into this state, but to get there in test_steal_space_from_bitmap_to_extent()
414 * we need to reach a point where marking new free space doesn't in test_steal_space_from_bitmap_to_extent()
416 * with existing extent entries - the space ends up being marked in test_steal_space_from_bitmap_to_extent()
417 * in an existing bitmap that covers the new free space range. 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()
431 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[ 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()
439 /* Bitmap entry covering free space range [128Mb + 512Kb, 256Mb[ */ in test_steal_space_from_bitmap_to_extent()
441 SZ_128M - SZ_512K, 1); in test_steal_space_from_bitmap_to_extent()
452 * Now make only the first 256Kb of the bitmap marked as free, so that in test_steal_space_from_bitmap_to_extent()
453 * we end up with only the following ranges marked as free space: in test_steal_space_from_bitmap_to_extent()
455 * [128Mb - 256Kb, 128Mb - 128Kb[ in test_steal_space_from_bitmap_to_extent()
460 SZ_128M - 768 * SZ_1K); in test_steal_space_from_bitmap_to_extent()
462 test_err("failed to free part of bitmap space %d", ret); in test_steal_space_from_bitmap_to_extent()
466 /* Confirm that only those 2 ranges are marked as free. */ 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()
468 test_err("free space range missing"); in test_steal_space_from_bitmap_to_extent()
469 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
472 test_err("free space range missing"); in test_steal_space_from_bitmap_to_extent()
473 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
478 * as free anymore. in test_steal_space_from_bitmap_to_extent()
481 SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
483 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
488 * covered by the bitmap, isn't marked as free. in test_steal_space_from_bitmap_to_extent()
491 test_err("invalid bitmap region marked as free"); in test_steal_space_from_bitmap_to_extent()
492 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
497 * by the bitmap too, isn't marked as free either. in test_steal_space_from_bitmap_to_extent()
500 test_err("invalid bitmap region marked as free"); in test_steal_space_from_bitmap_to_extent()
501 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
505 * Now lets mark the region [128Mb, 128Mb + 512Kb[ as free too. But, 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()
511 test_err("error adding free space: %d", ret); in test_steal_space_from_bitmap_to_extent()
514 /* Confirm the region is marked as free. */ in test_steal_space_from_bitmap_to_extent()
516 test_err("bitmap region not marked as free"); in test_steal_space_from_bitmap_to_extent()
517 return -ENOENT; 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()
529 * Now lets add a small free space region to the right of the previous in test_steal_space_from_bitmap_to_extent()
536 test_err("error adding free space: %d", ret); 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()
549 * Now mark the region [128Mb - 128Kb, 128Mb[ as free too. This will in test_steal_space_from_bitmap_to_extent()
551 * the free space [128Mb - 256Kb, 128Mb - 128Kb[. 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()
555 test_err("error adding free space: %d", ret); in test_steal_space_from_bitmap_to_extent()
558 /* Confirm the region is marked as free. */ 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()
560 test_err("extent region not marked as free"); in test_steal_space_from_bitmap_to_extent()
561 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
565 * Confirm that our extent entry didn't stole all free space from the in test_steal_space_from_bitmap_to_extent()
566 * bitmap, because of the small 4Kb free space region. in test_steal_space_from_bitmap_to_extent()
573 * So now we have the range [128Mb - 256Kb, 128Mb + 768Kb[ as free in test_steal_space_from_bitmap_to_extent()
574 * space. Without stealing bitmap free space into extent entry space, in test_steal_space_from_bitmap_to_extent()
575 * we would have all this free space represented by 2 entries in the in test_steal_space_from_bitmap_to_extent()
578 * extent entry covering range: [128Mb - 256Kb, 128Mb[ in test_steal_space_from_bitmap_to_extent()
581 * Attempting to allocate the whole free space (1Mb) would fail, because in test_steal_space_from_bitmap_to_extent()
583 * With the bitmap free space stealing, we get a single extent entry in test_steal_space_from_bitmap_to_extent()
584 * that represents the 1Mb free space, and therefore we're able to in test_steal_space_from_bitmap_to_extent()
585 * allocate the whole free space at once. 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()
588 test_err("expected region not marked as free"); in test_steal_space_from_bitmap_to_extent()
589 return -ENOENT; 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()
594 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
600 if (offset != (SZ_128M - SZ_256K)) { in test_steal_space_from_bitmap_to_extent()
604 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
608 * All that remains is a sectorsize free space region in a bitmap. 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()
617 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
626 return -EINVAL; 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()
642 * Extent entry covering free space range [128Mb + 128Kb, 128Mb + 256Kb[ in test_steal_space_from_bitmap_to_extent()
650 /* Bitmap entry covering free space range [0, 128Mb - 512Kb[ */ 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()
662 * Now make only the last 256Kb of the bitmap marked as free, so that in test_steal_space_from_bitmap_to_extent()
663 * we end up with only the following ranges marked as free space: in test_steal_space_from_bitmap_to_extent()
666 * [128Mb - 768Kb, 128Mb - 512Kb[ 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()
670 test_err("failed to free part of bitmap space %d", ret); in test_steal_space_from_bitmap_to_extent()
674 /* Confirm that only those 2 ranges are marked as free. */ in test_steal_space_from_bitmap_to_extent()
676 test_err("free space range missing"); in test_steal_space_from_bitmap_to_extent()
677 return -ENOENT; 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()
680 test_err("free space range missing"); in test_steal_space_from_bitmap_to_extent()
681 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
685 * Confirm that the bitmap range [0, 128Mb - 768Kb[ isn't marked in test_steal_space_from_bitmap_to_extent()
686 * as free anymore. 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()
690 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
694 * Confirm that the region [128Mb - 512Kb, 128Mb[, which is in test_steal_space_from_bitmap_to_extent()
695 * covered by the bitmap, isn't marked as free. 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()
698 test_err("invalid bitmap region marked as free"); in test_steal_space_from_bitmap_to_extent()
699 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
703 * Now lets mark the region [128Mb - 512Kb, 128Mb[ as free too. But, 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()
709 test_err("error adding free space: %d", ret); in test_steal_space_from_bitmap_to_extent()
712 /* Confirm the region is marked as free. */ 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()
714 test_err("bitmap region not marked as free"); in test_steal_space_from_bitmap_to_extent()
715 return -ENOENT; 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()
727 * Now lets add a small free space region to the left of the previous in test_steal_space_from_bitmap_to_extent()
734 test_err("error adding free space: %d", ret); in test_steal_space_from_bitmap_to_extent()
739 * Now mark the region [128Mb, 128Mb + 128Kb[ as free too. This will in test_steal_space_from_bitmap_to_extent()
741 * the free space [128Mb + 128Kb, 128Mb + 256Kb[. in test_steal_space_from_bitmap_to_extent()
745 test_err("error adding free space: %d", ret); in test_steal_space_from_bitmap_to_extent()
748 /* Confirm the region is marked as free. */ in test_steal_space_from_bitmap_to_extent()
750 test_err("extent region not marked as free"); in test_steal_space_from_bitmap_to_extent()
751 return -ENOENT; in test_steal_space_from_bitmap_to_extent()
755 * Confirm that our extent entry didn't stole all free space from the in test_steal_space_from_bitmap_to_extent()
756 * bitmap, because of the small 2 * sectorsize free space region. in test_steal_space_from_bitmap_to_extent()
763 * So now we have the range [128Mb - 768Kb, 128Mb + 256Kb[ as free in test_steal_space_from_bitmap_to_extent()
764 * space. Without stealing bitmap free space into extent entry space, in test_steal_space_from_bitmap_to_extent()
765 * we would have all this free space represented by 2 entries in the in test_steal_space_from_bitmap_to_extent()
769 * bitmap entry covering range: [128Mb - 768Kb, 128Mb[ in test_steal_space_from_bitmap_to_extent()
771 * Attempting to allocate the whole free space (1Mb) would fail, because in test_steal_space_from_bitmap_to_extent()
773 * With the bitmap free space stealing, we get a single extent entry in test_steal_space_from_bitmap_to_extent()
774 * that represents the 1Mb free space, and therefore we're able to in test_steal_space_from_bitmap_to_extent()
775 * allocate the whole free space at once. 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()
778 test_err("expected region not marked as free"); in test_steal_space_from_bitmap_to_extent()
779 return -ENOENT; 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()
784 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
789 if (offset != (SZ_128M - 768 * SZ_1K)) { in test_steal_space_from_bitmap_to_extent()
793 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
797 * All that remains is 2 * sectorsize free space region 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()
806 return -EINVAL; in test_steal_space_from_bitmap_to_extent()
815 return -EINVAL; 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()
833 int ret = -ENOMEM; in btrfs_test_free_space_cache()
835 test_msg("running btrfs free space cache tests"); in btrfs_test_free_space_cache()
839 return -ENOMEM; in btrfs_test_free_space_cache()
862 root->fs_info->extent_root = root; in btrfs_test_free_space_cache()