]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/hybrid_allocator_test: a couple broken cases
authorIgor Fedotov <igor.fedotov@croit.io>
Wed, 16 Feb 2022 21:12:31 +0000 (00:12 +0300)
committerJoshua Baergen <jbaergen@digitalocean.com>
Wed, 9 Apr 2025 19:39:02 +0000 (13:39 -0600)
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/test/objectstore/hybrid_allocator_test.cc

index e43d28b28442f6c48a3d935abcf3cf178c4aa4ce..c7ecfde021d31bd8301c11c3ea0576dba0473e10 100755 (executable)
@@ -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)