]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - fs/btrfs/tests/free-space-tests.c
2 * Copyright (C) 2013 Fusion IO. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
19 #include <linux/slab.h>
20 #include "btrfs-tests.h"
22 #include "../free-space-cache.h"
24 #define BITS_PER_BITMAP (PAGE_CACHE_SIZE * 8)
27 * This test just does basic sanity checking, making sure we can add an exten
28 * entry and remove space from either end and the middle, and make sure we can
29 * remove space that covers adjacent extent entries.
31 static int test_extents(struct btrfs_block_group_cache
*cache
)
35 test_msg("Running extent only tests\n");
37 /* First just make sure we can remove an entire entry */
38 ret
= btrfs_add_free_space(cache
, 0, 4 * 1024 * 1024);
40 test_msg("Error adding initial extents %d\n", ret
);
44 ret
= btrfs_remove_free_space(cache
, 0, 4 * 1024 * 1024);
46 test_msg("Error removing extent %d\n", ret
);
50 if (test_check_exists(cache
, 0, 4 * 1024 * 1024)) {
51 test_msg("Full remove left some lingering space\n");
55 /* Ok edge and middle cases now */
56 ret
= btrfs_add_free_space(cache
, 0, 4 * 1024 * 1024);
58 test_msg("Error adding half extent %d\n", ret
);
62 ret
= btrfs_remove_free_space(cache
, 3 * 1024 * 1024, 1 * 1024 * 1024);
64 test_msg("Error removing tail end %d\n", ret
);
68 ret
= btrfs_remove_free_space(cache
, 0, 1 * 1024 * 1024);
70 test_msg("Error removing front end %d\n", ret
);
74 ret
= btrfs_remove_free_space(cache
, 2 * 1024 * 1024, 4096);
76 test_msg("Error removing middle piece %d\n", ret
);
80 if (test_check_exists(cache
, 0, 1 * 1024 * 1024)) {
81 test_msg("Still have space at the front\n");
85 if (test_check_exists(cache
, 2 * 1024 * 1024, 4096)) {
86 test_msg("Still have space in the middle\n");
90 if (test_check_exists(cache
, 3 * 1024 * 1024, 1 * 1024 * 1024)) {
91 test_msg("Still have space at the end\n");
96 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
101 static int test_bitmaps(struct btrfs_block_group_cache
*cache
)
103 u64 next_bitmap_offset
;
106 test_msg("Running bitmap only tests\n");
108 ret
= test_add_free_space_entry(cache
, 0, 4 * 1024 * 1024, 1);
110 test_msg("Couldn't create a bitmap entry %d\n", ret
);
114 ret
= btrfs_remove_free_space(cache
, 0, 4 * 1024 * 1024);
116 test_msg("Error removing bitmap full range %d\n", ret
);
120 if (test_check_exists(cache
, 0, 4 * 1024 * 1024)) {
121 test_msg("Left some space in bitmap\n");
125 ret
= test_add_free_space_entry(cache
, 0, 4 * 1024 * 1024, 1);
127 test_msg("Couldn't add to our bitmap entry %d\n", ret
);
131 ret
= btrfs_remove_free_space(cache
, 1 * 1024 * 1024, 2 * 1024 * 1024);
133 test_msg("Couldn't remove middle chunk %d\n", ret
);
138 * The first bitmap we have starts at offset 0 so the next one is just
139 * at the end of the first bitmap.
141 next_bitmap_offset
= (u64
)(BITS_PER_BITMAP
* 4096);
143 /* Test a bit straddling two bitmaps */
144 ret
= test_add_free_space_entry(cache
, next_bitmap_offset
-
145 (2 * 1024 * 1024), 4 * 1024 * 1024, 1);
147 test_msg("Couldn't add space that straddles two bitmaps %d\n",
152 ret
= btrfs_remove_free_space(cache
, next_bitmap_offset
-
153 (1 * 1024 * 1024), 2 * 1024 * 1024);
155 test_msg("Couldn't remove overlapping space %d\n", ret
);
159 if (test_check_exists(cache
, next_bitmap_offset
- (1 * 1024 * 1024),
161 test_msg("Left some space when removing overlapping\n");
165 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
170 /* This is the high grade jackassery */
171 static int test_bitmaps_and_extents(struct btrfs_block_group_cache
*cache
)
173 u64 bitmap_offset
= (u64
)(BITS_PER_BITMAP
* 4096);
176 test_msg("Running bitmap and extent tests\n");
179 * First let's do something simple, an extent at the same offset as the
180 * bitmap, but the free space completely in the extent and then
181 * completely in the bitmap.
183 ret
= test_add_free_space_entry(cache
, 4 * 1024 * 1024, 1 * 1024 * 1024, 1);
185 test_msg("Couldn't create bitmap entry %d\n", ret
);
189 ret
= test_add_free_space_entry(cache
, 0, 1 * 1024 * 1024, 0);
191 test_msg("Couldn't add extent entry %d\n", ret
);
195 ret
= btrfs_remove_free_space(cache
, 0, 1 * 1024 * 1024);
197 test_msg("Couldn't remove extent entry %d\n", ret
);
201 if (test_check_exists(cache
, 0, 1 * 1024 * 1024)) {
202 test_msg("Left remnants after our remove\n");
206 /* Now to add back the extent entry and remove from the bitmap */
207 ret
= test_add_free_space_entry(cache
, 0, 1 * 1024 * 1024, 0);
209 test_msg("Couldn't re-add extent entry %d\n", ret
);
213 ret
= btrfs_remove_free_space(cache
, 4 * 1024 * 1024, 1 * 1024 * 1024);
215 test_msg("Couldn't remove from bitmap %d\n", ret
);
219 if (test_check_exists(cache
, 4 * 1024 * 1024, 1 * 1024 * 1024)) {
220 test_msg("Left remnants in the bitmap\n");
225 * Ok so a little more evil, extent entry and bitmap at the same offset,
226 * removing an overlapping chunk.
228 ret
= test_add_free_space_entry(cache
, 1 * 1024 * 1024, 4 * 1024 * 1024, 1);
230 test_msg("Couldn't add to a bitmap %d\n", ret
);
234 ret
= btrfs_remove_free_space(cache
, 512 * 1024, 3 * 1024 * 1024);
236 test_msg("Couldn't remove overlapping space %d\n", ret
);
240 if (test_check_exists(cache
, 512 * 1024, 3 * 1024 * 1024)) {
241 test_msg("Left over pieces after removing overlapping\n");
245 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
247 /* Now with the extent entry offset into the bitmap */
248 ret
= test_add_free_space_entry(cache
, 4 * 1024 * 1024, 4 * 1024 * 1024, 1);
250 test_msg("Couldn't add space to the bitmap %d\n", ret
);
254 ret
= test_add_free_space_entry(cache
, 2 * 1024 * 1024, 2 * 1024 * 1024, 0);
256 test_msg("Couldn't add extent to the cache %d\n", ret
);
260 ret
= btrfs_remove_free_space(cache
, 3 * 1024 * 1024, 4 * 1024 * 1024);
262 test_msg("Problem removing overlapping space %d\n", ret
);
266 if (test_check_exists(cache
, 3 * 1024 * 1024, 4 * 1024 * 1024)) {
267 test_msg("Left something behind when removing space");
272 * This has blown up in the past, the extent entry starts before the
273 * bitmap entry, but we're trying to remove an offset that falls
274 * completely within the bitmap range and is in both the extent entry
275 * and the bitmap entry, looks like this
281 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
282 ret
= test_add_free_space_entry(cache
, bitmap_offset
+ 4 * 1024 * 1024,
285 test_msg("Couldn't add bitmap %d\n", ret
);
289 ret
= test_add_free_space_entry(cache
, bitmap_offset
- 1 * 1024 * 1024,
292 test_msg("Couldn't add extent entry %d\n", ret
);
296 ret
= btrfs_remove_free_space(cache
, bitmap_offset
+ 1 * 1024 * 1024,
299 test_msg("Failed to free our space %d\n", ret
);
303 if (test_check_exists(cache
, bitmap_offset
+ 1 * 1024 * 1024,
305 test_msg("Left stuff over\n");
309 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
312 * This blew up before, we have part of the free space in a bitmap and
313 * then the entirety of the rest of the space in an extent. This used
314 * to return -EAGAIN back from btrfs_remove_extent, make sure this
317 ret
= test_add_free_space_entry(cache
, 1 * 1024 * 1024, 2 * 1024 * 1024, 1);
319 test_msg("Couldn't add bitmap entry %d\n", ret
);
323 ret
= test_add_free_space_entry(cache
, 3 * 1024 * 1024, 1 * 1024 * 1024, 0);
325 test_msg("Couldn't add extent entry %d\n", ret
);
329 ret
= btrfs_remove_free_space(cache
, 1 * 1024 * 1024, 3 * 1024 * 1024);
331 test_msg("Error removing bitmap and extent overlapping %d\n", ret
);
335 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
339 /* Used by test_steal_space_from_bitmap_to_extent(). */
340 static bool test_use_bitmap(struct btrfs_free_space_ctl
*ctl
,
341 struct btrfs_free_space
*info
)
343 return ctl
->free_extents
> 0;
346 /* Used by test_steal_space_from_bitmap_to_extent(). */
348 check_num_extents_and_bitmaps(const struct btrfs_block_group_cache
*cache
,
349 const int num_extents
,
350 const int num_bitmaps
)
352 if (cache
->free_space_ctl
->free_extents
!= num_extents
) {
353 test_msg("Incorrect # of extent entries in the cache: %d, expected %d\n",
354 cache
->free_space_ctl
->free_extents
, num_extents
);
357 if (cache
->free_space_ctl
->total_bitmaps
!= num_bitmaps
) {
358 test_msg("Incorrect # of extent entries in the cache: %d, expected %d\n",
359 cache
->free_space_ctl
->total_bitmaps
, num_bitmaps
);
365 /* Used by test_steal_space_from_bitmap_to_extent(). */
366 static int check_cache_empty(struct btrfs_block_group_cache
*cache
)
372 * Now lets confirm that there's absolutely no free space left to
375 if (cache
->free_space_ctl
->free_space
!= 0) {
376 test_msg("Cache free space is not 0\n");
380 /* And any allocation request, no matter how small, should fail now. */
381 offset
= btrfs_find_space_for_alloc(cache
, 0, 4096, 0,
384 test_msg("Space allocation did not fail, returned offset: %llu",
389 /* And no extent nor bitmap entries in the cache anymore. */
390 return check_num_extents_and_bitmaps(cache
, 0, 0);
394 * Before we were able to steal free space from a bitmap entry to an extent
395 * entry, we could end up with 2 entries representing a contiguous free space.
396 * One would be an extent entry and the other a bitmap entry. Since in order
397 * to allocate space to a caller we use only 1 entry, we couldn't return that
398 * whole range to the caller if it was requested. This forced the caller to
399 * either assume ENOSPC or perform several smaller space allocations, which
400 * wasn't optimal as they could be spread all over the block group while under
401 * concurrency (extra overhead and fragmentation).
403 * This stealing approach is benefical, since we always prefer to allocate from
404 * extent entries, both for clustered and non-clustered allocation requests.
407 test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache
*cache
)
413 bool (*use_bitmap_op
)(struct btrfs_free_space_ctl
*,
414 struct btrfs_free_space
*);
416 test_msg("Running space stealing from bitmap to extent\n");
419 * For this test, we want to ensure we end up with an extent entry
420 * immediately adjacent to a bitmap entry, where the bitmap starts
421 * at an offset where the extent entry ends. We keep adding and
422 * removing free space to reach into this state, but to get there
423 * we need to reach a point where marking new free space doesn't
424 * result in adding new extent entries or merging the new space
425 * with existing extent entries - the space ends up being marked
426 * in an existing bitmap that covers the new free space range.
428 * To get there, we need to reach the threshold defined set at
429 * cache->free_space_ctl->extents_thresh, which currently is
430 * 256 extents on a x86_64 system at least, and a few other
431 * conditions (check free_space_cache.c). Instead of making the
432 * test much longer and complicated, use a "use_bitmap" operation
433 * that forces use of bitmaps as soon as we have at least 1
436 use_bitmap_op
= cache
->free_space_ctl
->op
->use_bitmap
;
437 cache
->free_space_ctl
->op
->use_bitmap
= test_use_bitmap
;
440 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
442 ret
= test_add_free_space_entry(cache
, 128 * 1024 * 1024 - 256 * 1024,
445 test_msg("Couldn't add extent entry %d\n", ret
);
449 /* Bitmap entry covering free space range [128Mb + 512Kb, 256Mb[ */
450 ret
= test_add_free_space_entry(cache
, 128 * 1024 * 1024 + 512 * 1024,
451 128 * 1024 * 1024 - 512 * 1024, 1);
453 test_msg("Couldn't add bitmap entry %d\n", ret
);
457 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
462 * Now make only the first 256Kb of the bitmap marked as free, so that
463 * we end up with only the following ranges marked as free space:
465 * [128Mb - 256Kb, 128Mb - 128Kb[
466 * [128Mb + 512Kb, 128Mb + 768Kb[
468 ret
= btrfs_remove_free_space(cache
,
469 128 * 1024 * 1024 + 768 * 1024,
470 128 * 1024 * 1024 - 768 * 1024);
472 test_msg("Failed to free part of bitmap space %d\n", ret
);
476 /* Confirm that only those 2 ranges are marked as free. */
477 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 256 * 1024,
479 test_msg("Free space range missing\n");
482 if (!test_check_exists(cache
, 128 * 1024 * 1024 + 512 * 1024,
484 test_msg("Free space range missing\n");
489 * Confirm that the bitmap range [128Mb + 768Kb, 256Mb[ isn't marked
492 if (test_check_exists(cache
, 128 * 1024 * 1024 + 768 * 1024,
493 128 * 1024 * 1024 - 768 * 1024)) {
494 test_msg("Bitmap region not removed from space cache\n");
499 * Confirm that the region [128Mb + 256Kb, 128Mb + 512Kb[, which is
500 * covered by the bitmap, isn't marked as free.
502 if (test_check_exists(cache
, 128 * 1024 * 1024 + 256 * 1024,
504 test_msg("Invalid bitmap region marked as free\n");
509 * Confirm that the region [128Mb, 128Mb + 256Kb[, which is covered
510 * by the bitmap too, isn't marked as free either.
512 if (test_check_exists(cache
, 128 * 1024 * 1024,
514 test_msg("Invalid bitmap region marked as free\n");
519 * Now lets mark the region [128Mb, 128Mb + 512Kb[ as free too. But,
520 * lets make sure the free space cache marks it as free in the bitmap,
521 * and doesn't insert a new extent entry to represent this region.
523 ret
= btrfs_add_free_space(cache
, 128 * 1024 * 1024, 512 * 1024);
525 test_msg("Error adding free space: %d\n", ret
);
528 /* Confirm the region is marked as free. */
529 if (!test_check_exists(cache
, 128 * 1024 * 1024, 512 * 1024)) {
530 test_msg("Bitmap region not marked as free\n");
535 * Confirm that no new extent entries or bitmap entries were added to
536 * the cache after adding that free space region.
538 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
543 * Now lets add a small free space region to the right of the previous
544 * one, which is not contiguous with it and is part of the bitmap too.
545 * The goal is to test that the bitmap entry space stealing doesn't
546 * steal this space region.
548 ret
= btrfs_add_free_space(cache
, 128 * 1024 * 1024 + 16 * 1024 * 1024,
551 test_msg("Error adding free space: %d\n", ret
);
556 * Confirm that no new extent entries or bitmap entries were added to
557 * the cache after adding that free space region.
559 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
564 * Now mark the region [128Mb - 128Kb, 128Mb[ as free too. This will
565 * expand the range covered by the existing extent entry that represents
566 * the free space [128Mb - 256Kb, 128Mb - 128Kb[.
568 ret
= btrfs_add_free_space(cache
, 128 * 1024 * 1024 - 128 * 1024,
571 test_msg("Error adding free space: %d\n", ret
);
574 /* Confirm the region is marked as free. */
575 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 128 * 1024,
577 test_msg("Extent region not marked as free\n");
582 * Confirm that our extent entry didn't stole all free space from the
583 * bitmap, because of the small 4Kb free space region.
585 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
590 * So now we have the range [128Mb - 256Kb, 128Mb + 768Kb[ as free
591 * space. Without stealing bitmap free space into extent entry space,
592 * we would have all this free space represented by 2 entries in the
595 * extent entry covering range: [128Mb - 256Kb, 128Mb[
596 * bitmap entry covering range: [128Mb, 128Mb + 768Kb[
598 * Attempting to allocate the whole free space (1Mb) would fail, because
599 * we can't allocate from multiple entries.
600 * With the bitmap free space stealing, we get a single extent entry
601 * that represents the 1Mb free space, and therefore we're able to
602 * allocate the whole free space at once.
604 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 256 * 1024,
606 test_msg("Expected region not marked as free\n");
610 if (cache
->free_space_ctl
->free_space
!= (1 * 1024 * 1024 + 4096)) {
611 test_msg("Cache free space is not 1Mb + 4Kb\n");
615 offset
= btrfs_find_space_for_alloc(cache
,
616 0, 1 * 1024 * 1024, 0,
618 if (offset
!= (128 * 1024 * 1024 - 256 * 1024)) {
619 test_msg("Failed to allocate 1Mb from space cache, returned offset is: %llu\n",
624 /* All that remains is a 4Kb free space region in a bitmap. Confirm. */
625 ret
= check_num_extents_and_bitmaps(cache
, 1, 1);
629 if (cache
->free_space_ctl
->free_space
!= 4096) {
630 test_msg("Cache free space is not 4Kb\n");
634 offset
= btrfs_find_space_for_alloc(cache
,
637 if (offset
!= (128 * 1024 * 1024 + 16 * 1024 * 1024)) {
638 test_msg("Failed to allocate 4Kb from space cache, returned offset is: %llu\n",
643 ret
= check_cache_empty(cache
);
647 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
650 * Now test a similar scenario, but where our extent entry is located
651 * to the right of the bitmap entry, so that we can check that stealing
652 * space from a bitmap to the front of an extent entry works.
656 * Extent entry covering free space range [128Mb + 128Kb, 128Mb + 256Kb[
658 ret
= test_add_free_space_entry(cache
, 128 * 1024 * 1024 + 128 * 1024,
661 test_msg("Couldn't add extent entry %d\n", ret
);
665 /* Bitmap entry covering free space range [0, 128Mb - 512Kb[ */
666 ret
= test_add_free_space_entry(cache
, 0,
667 128 * 1024 * 1024 - 512 * 1024, 1);
669 test_msg("Couldn't add bitmap entry %d\n", ret
);
673 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
678 * Now make only the last 256Kb of the bitmap marked as free, so that
679 * we end up with only the following ranges marked as free space:
681 * [128Mb + 128b, 128Mb + 256Kb[
682 * [128Mb - 768Kb, 128Mb - 512Kb[
684 ret
= btrfs_remove_free_space(cache
,
686 128 * 1024 * 1024 - 768 * 1024);
688 test_msg("Failed to free part of bitmap space %d\n", ret
);
692 /* Confirm that only those 2 ranges are marked as free. */
693 if (!test_check_exists(cache
, 128 * 1024 * 1024 + 128 * 1024,
695 test_msg("Free space range missing\n");
698 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 768 * 1024,
700 test_msg("Free space range missing\n");
705 * Confirm that the bitmap range [0, 128Mb - 768Kb[ isn't marked
708 if (test_check_exists(cache
, 0,
709 128 * 1024 * 1024 - 768 * 1024)) {
710 test_msg("Bitmap region not removed from space cache\n");
715 * Confirm that the region [128Mb - 512Kb, 128Mb[, which is
716 * covered by the bitmap, isn't marked as free.
718 if (test_check_exists(cache
, 128 * 1024 * 1024 - 512 * 1024,
720 test_msg("Invalid bitmap region marked as free\n");
725 * Now lets mark the region [128Mb - 512Kb, 128Mb[ as free too. But,
726 * lets make sure the free space cache marks it as free in the bitmap,
727 * and doesn't insert a new extent entry to represent this region.
729 ret
= btrfs_add_free_space(cache
, 128 * 1024 * 1024 - 512 * 1024,
732 test_msg("Error adding free space: %d\n", ret
);
735 /* Confirm the region is marked as free. */
736 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 512 * 1024,
738 test_msg("Bitmap region not marked as free\n");
743 * Confirm that no new extent entries or bitmap entries were added to
744 * the cache after adding that free space region.
746 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
751 * Now lets add a small free space region to the left of the previous
752 * one, which is not contiguous with it and is part of the bitmap too.
753 * The goal is to test that the bitmap entry space stealing doesn't
754 * steal this space region.
756 ret
= btrfs_add_free_space(cache
, 32 * 1024 * 1024, 8192);
758 test_msg("Error adding free space: %d\n", ret
);
763 * Now mark the region [128Mb, 128Mb + 128Kb[ as free too. This will
764 * expand the range covered by the existing extent entry that represents
765 * the free space [128Mb + 128Kb, 128Mb + 256Kb[.
767 ret
= btrfs_add_free_space(cache
, 128 * 1024 * 1024, 128 * 1024);
769 test_msg("Error adding free space: %d\n", ret
);
772 /* Confirm the region is marked as free. */
773 if (!test_check_exists(cache
, 128 * 1024 * 1024, 128 * 1024)) {
774 test_msg("Extent region not marked as free\n");
779 * Confirm that our extent entry didn't stole all free space from the
780 * bitmap, because of the small 8Kb free space region.
782 ret
= check_num_extents_and_bitmaps(cache
, 2, 1);
787 * So now we have the range [128Mb - 768Kb, 128Mb + 256Kb[ as free
788 * space. Without stealing bitmap free space into extent entry space,
789 * we would have all this free space represented by 2 entries in the
792 * extent entry covering range: [128Mb, 128Mb + 256Kb[
793 * bitmap entry covering range: [128Mb - 768Kb, 128Mb[
795 * Attempting to allocate the whole free space (1Mb) would fail, because
796 * we can't allocate from multiple entries.
797 * With the bitmap free space stealing, we get a single extent entry
798 * that represents the 1Mb free space, and therefore we're able to
799 * allocate the whole free space at once.
801 if (!test_check_exists(cache
, 128 * 1024 * 1024 - 768 * 1024,
803 test_msg("Expected region not marked as free\n");
807 if (cache
->free_space_ctl
->free_space
!= (1 * 1024 * 1024 + 8192)) {
808 test_msg("Cache free space is not 1Mb + 8Kb\n");
812 offset
= btrfs_find_space_for_alloc(cache
,
813 0, 1 * 1024 * 1024, 0,
815 if (offset
!= (128 * 1024 * 1024 - 768 * 1024)) {
816 test_msg("Failed to allocate 1Mb from space cache, returned offset is: %llu\n",
821 /* All that remains is a 8Kb free space region in a bitmap. Confirm. */
822 ret
= check_num_extents_and_bitmaps(cache
, 1, 1);
826 if (cache
->free_space_ctl
->free_space
!= 8192) {
827 test_msg("Cache free space is not 8Kb\n");
831 offset
= btrfs_find_space_for_alloc(cache
,
834 if (offset
!= (32 * 1024 * 1024)) {
835 test_msg("Failed to allocate 8Kb from space cache, returned offset is: %llu\n",
840 ret
= check_cache_empty(cache
);
844 cache
->free_space_ctl
->op
->use_bitmap
= use_bitmap_op
;
845 __btrfs_remove_free_space_cache(cache
->free_space_ctl
);
850 int btrfs_test_free_space_cache(void)
852 struct btrfs_block_group_cache
*cache
;
855 test_msg("Running btrfs free space cache tests\n");
857 cache
= btrfs_alloc_dummy_block_group(1024 * 1024 * 1024);
859 test_msg("Couldn't run the tests\n");
863 ret
= test_extents(cache
);
866 ret
= test_bitmaps(cache
);
869 ret
= test_bitmaps_and_extents(cache
);
873 ret
= test_steal_space_from_bitmap_to_extent(cache
);
875 btrfs_free_dummy_block_group(cache
);
876 test_msg("Free space cache tests finished\n");