From af8930617ab211a15417c052aafca2b1806c1b26 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Thu, 12 Mar 2020 13:29:03 +0100 Subject: [PATCH] os/bluestore: Adds shutdown in destructor of AvlAllocator Adds shutdown. Fixes incorrect mempool accounting. Signed-off-by: Adam Kupczyk (cherry picked from commit ea95309f478428b6e4b3af93b19459f6b5cc162d) Conflicts: src/test/objectstore/Allocator_bench.cc trivial --- src/os/bluestore/AvlAllocator.cc | 5 ++++ src/os/bluestore/AvlAllocator.h | 1 + src/test/objectstore/Allocator_bench.cc | 34 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index ccc3c756379cb..c2108210327f1 100755 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -212,6 +212,11 @@ AvlAllocator::AvlAllocator(CephContext* cct, cct(cct) {} +AvlAllocator::~AvlAllocator() +{ + shutdown(); +} + int64_t AvlAllocator::allocate( uint64_t want, uint64_t unit, diff --git a/src/os/bluestore/AvlAllocator.h b/src/os/bluestore/AvlAllocator.h index a855d975da611..cb6ebbce58478 100755 --- a/src/os/bluestore/AvlAllocator.h +++ b/src/os/bluestore/AvlAllocator.h @@ -50,6 +50,7 @@ class AvlAllocator final : public Allocator { public: AvlAllocator(CephContext* cct, int64_t device_size, int64_t block_size, const std::string& name); + ~AvlAllocator(); int64_t allocate( uint64_t want, uint64_t unit, diff --git a/src/test/objectstore/Allocator_bench.cc b/src/test/objectstore/Allocator_bench.cc index 4f3c40f42168c..cfadee5306d9c 100755 --- a/src/test/objectstore/Allocator_bench.cc +++ b/src/test/objectstore/Allocator_bench.cc @@ -329,7 +329,39 @@ TEST_P(AllocTest, test_alloc_bench_10_300) doOverwriteTest(capacity, prefill, overwrite); } -INSTANTIATE_TEST_CASE_P( +TEST_P(AllocTest, mempoolAccounting) +{ + uint64_t bytes = mempool::bluestore_alloc::allocated_bytes(); + uint64_t items = mempool::bluestore_alloc::allocated_items(); + + uint64_t alloc_size = 4 * 1024; + uint64_t capacity = 512ll * 1024 * 1024 * 1024; + Allocator* alloc = Allocator::create(g_ceph_context, string(GetParam()), + capacity, alloc_size); + ASSERT_NE(alloc, nullptr); + alloc->init_add_free(0, capacity); + + std::map all_allocs; + for (size_t i = 0; i < 10000; i++) { + PExtentVector tmp; + alloc->allocate(alloc_size, alloc_size, 0, 0, &tmp); + all_allocs[rand()] = tmp; + alloc->allocate(alloc_size, alloc_size, 0, 0, &tmp); + all_allocs[rand()] = tmp; + + auto it = all_allocs.upper_bound(rand()); + if (it != all_allocs.end()) { + alloc->release(it->second); + all_allocs.erase(it); + } + } + + delete(alloc); + ASSERT_EQ(mempool::bluestore_alloc::allocated_bytes(), bytes); + ASSERT_EQ(mempool::bluestore_alloc::allocated_items(), items); +} + +INSTANTIATE_TEST_SUITE_P( Allocator, AllocTest, ::testing::Values("stupid", "bitmap", "avl")); -- 2.39.5