]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Adds shutdown in destructor of AvlAllocator
authorAdam Kupczyk <akupczyk@redhat.com>
Thu, 12 Mar 2020 12:29:03 +0000 (13:29 +0100)
committerIgor Fedotov <ifedotov@suse.com>
Sat, 25 Jul 2020 10:55:22 +0000 (13:55 +0300)
Adds shutdown. Fixes incorrect mempool accounting.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(cherry picked from commit ea95309f478428b6e4b3af93b19459f6b5cc162d)

 Conflicts:
src/test/objectstore/Allocator_bench.cc
 trivial

src/os/bluestore/AvlAllocator.cc
src/os/bluestore/AvlAllocator.h
src/test/objectstore/Allocator_bench.cc

index ccc3c756379cb4ffca3cc9933feff9a9459cf3ad..c2108210327f1877e81ff34f5ca1291da78535fc 100755 (executable)
@@ -212,6 +212,11 @@ AvlAllocator::AvlAllocator(CephContext* cct,
   cct(cct)
 {}
 
+AvlAllocator::~AvlAllocator()
+{
+  shutdown();
+}
+
 int64_t AvlAllocator::allocate(
   uint64_t want,
   uint64_t unit,
index a855d975da611ed1011b352826aaa9475b69224b..cb6ebbce5847890333f6c0fb0481b5e418a39ea2 100755 (executable)
@@ -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,
index 4f3c40f42168c8a23a0c6b2143f0fc591628ab8c..cfadee5306d9c8043508d0d210aa23f07649f1cb 100755 (executable)
@@ -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<uint32_t, PExtentVector> 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"));