]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/objectstore/Allocator_bench.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / objectstore / Allocator_bench.cc
old mode 100755 (executable)
new mode 100644 (file)
index bdd6480..0d04a85
@@ -8,7 +8,6 @@
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
 
-#include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "include/stringify.h"
@@ -22,7 +21,7 @@ typedef boost::mt11213b gen_type;
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_
 
-#if GTEST_HAS_PARAM_TEST
+using namespace std;
 
 class AllocTest : public ::testing::TestWithParam<const char*> {
 
@@ -31,7 +30,7 @@ public:
   AllocTest(): alloc(0) { }
   void init_alloc(int64_t size, uint64_t min_alloc_size) {
     std::cout << "Creating alloc type " << string(GetParam()) << " \n";
-    alloc.reset(Allocator::create(g_ceph_context, string(GetParam()), size,
+    alloc.reset(Allocator::create(g_ceph_context, GetParam(), size,
                                  min_alloc_size));
   }
 
@@ -43,7 +42,6 @@ public:
 };
 
 const uint64_t _1m = 1024 * 1024;
-const uint64_t _2m = 2 * 1024 * 1024;
 
 void dump_mempools()
 {
@@ -68,10 +66,10 @@ class AllocTracker
 
 public:
   AllocTracker(uint64_t capacity, uint64_t alloc_unit)
-    : u1(capacity, alloc_unit)
+    : u1(0, capacity)
   {
-    assert(alloc_unit >= 0x100);
-    assert(capacity <= (uint64_t(1) << 48)); // we use 5 octets (bytes 1 - 5) to store
+    ceph_assert(alloc_unit >= 0x100);
+    ceph_assert(capacity <= (uint64_t(1) << 48)); // we use 5 octets (bytes 1 - 5) to store
                                 // offset to save the required space.
                                 // This supports capacity up to 281 TB
 
@@ -89,9 +87,9 @@ public:
 
   bool push(uint64_t offs, uint32_t len)
   {
-    assert((len & 0xff) == 0);
-    assert((offs & 0xff) == 0);
-    assert((offs & 0xffff000000000000) == 0);
+    ceph_assert((len & 0xff) == 0);
+    ceph_assert((offs & 0xff) == 0);
+    ceph_assert((offs & 0xffff000000000000) == 0);
 
     if (head + 1 == tail)
       return false;
@@ -150,7 +148,8 @@ TEST_P(AllocTest, test_alloc_bench_seq)
   for (uint64_t i = 0; i < capacity; i += want_size)
   {
     tmp.clear();
-    EXPECT_EQ(want_size, alloc->allocate(want_size, alloc_unit, 0, 0, &tmp));
+    EXPECT_EQ(static_cast<int64_t>(want_size),
+             alloc->allocate(want_size, alloc_unit, 0, 0, &tmp));
     if (0 == (i % (1 * 1024 * _1m))) {
       std::cout << "alloc " << i / 1024 / 1024 << " mb of "
         << capacity / 1024 / 1024 << std::endl;
@@ -329,12 +328,41 @@ TEST_P(AllocTest, test_alloc_bench_10_300)
   doOverwriteTest(capacity, prefill, overwrite);
 }
 
-INSTANTIATE_TEST_CASE_P(
-  Allocator,
-  AllocTest,
-  ::testing::Values("stupid", "bitmap"));
+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, GetParam(),
+                                      capacity, alloc_size);
+  ASSERT_NE(alloc, nullptr);
+  alloc->init_add_free(0, capacity);
 
-#else
+  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;
+    tmp.clear();
+    alloc->allocate(alloc_size, alloc_size, 0, 0, &tmp);
+    all_allocs[rand()] = tmp;
+    tmp.clear();
 
-TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {}
-#endif
+    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", "btree", "hybrid"));