X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Ftest%2Fobjectstore%2FAllocator_test.cc;h=b62e8bbba5229eb109b6e80a30866d14421cc5b9;hb=6d8e3169aa705e9643a46c42cbc5ad810339f421;hp=f6f0c38bec20abc5e9e00bbb3a3bb8328e45891b;hpb=f21c6c9b5b7752e57c3b8688293a6dc8ce9eba9c;p=ceph.git diff --git a/ceph/src/test/objectstore/Allocator_test.cc b/ceph/src/test/objectstore/Allocator_test.cc index f6f0c38be..b62e8bbba 100644 --- a/ceph/src/test/objectstore/Allocator_test.cc +++ b/ceph/src/test/objectstore/Allocator_test.cc @@ -47,6 +47,23 @@ TEST_P(AllocTest, test_alloc_init) ASSERT_EQ(alloc->get_free(), (uint64_t) 0); } +TEST_P(AllocTest, test_init_add_free) +{ + int64_t block_size = 1024; + int64_t capacity = 4 * 1024 * block_size; + + { + init_alloc(capacity, block_size); + + auto free = alloc->get_free(); + alloc->init_add_free(block_size, 0); + ASSERT_EQ(free, alloc->get_free()); + + alloc->init_rm_free(block_size, 0); + ASSERT_EQ(free, alloc->get_free()); + } +} + TEST_P(AllocTest, test_alloc_min_alloc) { int64_t block_size = 1024; @@ -498,6 +515,47 @@ TEST_P(AllocTest, test_alloc_47883) EXPECT_EQ(got, 0x630000); } +TEST_P(AllocTest, test_alloc_50656_best_fit) +{ + uint64_t block = 0x1000; + uint64_t size = 0x3b9e400000; + + init_alloc(size, block); + + // too few free extents - causes best fit mode for avls + for (size_t i = 0; i < 0x10; i++) { + alloc->init_add_free(i * 2 * 0x100000, 0x100000); + } + + alloc->init_add_free(0x1e1bd13000, 0x404000); + + PExtentVector extents; + auto need = 0x400000; + auto got = alloc->allocate(need, 0x10000, 0, (int64_t)0, &extents); + EXPECT_GT(got, 0); + EXPECT_EQ(got, 0x400000); +} + +TEST_P(AllocTest, test_alloc_50656_first_fit) +{ + uint64_t block = 0x1000; + uint64_t size = 0x3b9e400000; + + init_alloc(size, block); + + for (size_t i = 0; i < 0x10000; i += 2) { + alloc->init_add_free(i * 0x100000, 0x100000); + } + + alloc->init_add_free(0x1e1bd13000, 0x404000); + + PExtentVector extents; + auto need = 0x400000; + auto got = alloc->allocate(need, 0x10000, 0, (int64_t)0, &extents); + EXPECT_GT(got, 0); + EXPECT_EQ(got, 0x400000); +} + INSTANTIATE_TEST_SUITE_P( Allocator, AllocTest,