From 7b7550a51e0aa6af12f0771613f3400169e25157 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Thu, 17 Feb 2022 00:12:31 +0300 Subject: [PATCH] test/hybrid_allocator_test: a couple broken cases Signed-off-by: Igor Fedotov --- src/test/objectstore/hybrid_allocator_test.cc | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/test/objectstore/hybrid_allocator_test.cc b/src/test/objectstore/hybrid_allocator_test.cc index e43d28b2844..c7ecfde021d 100755 --- a/src/test/objectstore/hybrid_allocator_test.cc +++ b/src/test/objectstore/hybrid_allocator_test.cc @@ -29,6 +29,32 @@ public: const uint64_t _1m = 1024 * 1024; const uint64_t _4m = 4 * 1024 * 1024; +TEST(BitmapAllocator, claim_edge) +{ + { + uint64_t block_size = 0x1000; + uint64_t capacity = _1m; + BitmapAllocator ha(g_ceph_context, capacity, block_size, + "test_allocator"); + + ha.init_add_free(0x1000, _1m - 0x2000); + auto r = ha.claim_free_to_left(0); + ASSERT_EQ(r, 0); + + ha.foreach([&](uint64_t o, uint64_t l) { + ASSERT_EQ(o, 0x1000); + ASSERT_EQ(l, 0xfe000); + }); + + r = ha.claim_free_to_right(0); + ASSERT_EQ(r, 0); + ha.foreach([&](uint64_t o, uint64_t l) { + ASSERT_EQ(o, 0x1000); + ASSERT_EQ(l, 0xfe000); + }); + } +} + TEST(HybridAllocator, basic) { { @@ -82,7 +108,7 @@ TEST(HybridAllocator, basic) ASSERT_EQ(_1m * 8, ha.get_bmap_free()); // so we have at avl: 2M~2M, 8M~4M, 400M~4M , 408M~4M - // and at bmap: 0~1M, 16M~1M, 18M~2M, 24~4M + // and at bmap: 0~1M, 16M~4M, 24~1M, 26~2M PExtentVector extents; // allocate 4K, to be served from bitmap @@ -105,7 +131,7 @@ TEST(HybridAllocator, basic) release_set.clear(); // again we have at avl: 2M~2M, 8M~4M, 400M~4M , 408M~4M - // and at bmap: 0~1M, 16M~1M, 18M~2M, 24~4M + // and at bmap: 0~1M, 16M~4M, 24M~1M, 26~2M // add 12M~3M which will go to avl ha.init_add_free(3 * _4m, 3 * _1m); @@ -205,6 +231,39 @@ TEST(HybridAllocator, basic) ASSERT_EQ(_1m * 3 + 0x2000, ha.get_avl_free()); ASSERT_EQ(0x1000, ha.get_bmap_free()); } + { + uint64_t block_size = 0x1000; + uint64_t capacity = 0x10000 * _1m; // = 64GB + TestHybridAllocator ha(g_ceph_context, capacity, block_size, + 4 * sizeof(range_seg_t), "test_hybrid_allocator"); + + // to be at avl + ha.init_add_free(0, 2 * _1m); + ha.init_add_free(4 * _1m , 2 * _1m); + ha.init_add_free(8 * _1m, 2 * _1m); + ha.init_add_free(16 * _1m, 4 * _1m); + + // to be at bitmap + ha.init_add_free(24 * _1m, 1 * _1m); + ha.init_add_free(28 * _1m, 1 * _1m); + + ASSERT_EQ(_1m * 10, ha.get_avl_free()); + ASSERT_EQ(_1m * 2, ha.get_bmap_free()); + + // allocate 12M using 2M chunks. 10M to be returned + PExtentVector extents; + EXPECT_EQ(10 * _1m, ha.allocate(12 * _1m, 2 * _1m, + 0, (int64_t)0, &extents)); + + // release everything allocated + for (auto& e : extents) { + ha.init_add_free(e.offset, e.length); + } + extents.clear(); + + ASSERT_EQ(_1m * 10, ha.get_avl_free()); + ASSERT_EQ(_1m * 2, ha.get_bmap_free()); + } } TEST(HybridAllocator, fragmentation) -- 2.39.5