]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: simplify Allocator::get_fragmentation() signature
authorIgor Fedotov <ifedotov@suse.com>
Mon, 19 Aug 2019 12:19:25 +0000 (15:19 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Sat, 25 Jul 2020 10:55:22 +0000 (13:55 +0300)
Remove alloc_unit parameter.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 3a96db924968b65afed5fc1355acbf185455c5c4)

src/os/bluestore/Allocator.cc
src/os/bluestore/Allocator.h
src/os/bluestore/BitmapAllocator.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h
src/test/objectstore/Allocator_test.cc

index 11b805a6fa22b17691e3a6030a8e3b190e71ecf6..507203f0e7f633fa567683eb05bb8dd1fd785449 100644 (file)
@@ -14,7 +14,9 @@ class Allocator::SocketHook : public AdminSocketHook {
 
   std::string name;
 public:
-  explicit SocketHook(Allocator *alloc, const std::string& _name) : alloc(alloc), name(_name)
+  explicit SocketHook(Allocator *alloc,
+                      const std::string& _name) :
+    alloc(alloc), name(_name)
   {
     AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
     if (name.empty()) {
@@ -103,7 +105,7 @@ Allocator *Allocator::create(CephContext* cct, string type,
 {
   Allocator* alloc = nullptr;
   if (type == "stupid") {
-    alloc = new StupidAllocator(cct, name);
+    alloc = new StupidAllocator(cct, name, block_size);
   } else if (type == "bitmap") {
     alloc = new BitmapAllocator(cct, size, block_size, name);
   } else if (type == "avl") {
index 61299bf58767ab62360b8f2dac9f09739bbc0975..9f679d584e1f83788b242669c27d1fa8fa3cc762 100644 (file)
@@ -52,7 +52,7 @@ public:
   virtual void init_rm_free(uint64_t offset, uint64_t length) = 0;
 
   virtual uint64_t get_free() = 0;
-  virtual double get_fragmentation(uint64_t alloc_unit)
+  virtual double get_fragmentation()
   {
     return 0.0;
   }
index ed7f122775fbb486e1a9531aa86b5dff6adf9a95..996663b49a2b0c58010a61f123253f820ea915cd 100755 (executable)
@@ -37,7 +37,7 @@ public:
 
   void dump() override;
   void dump(std::function<void(uint64_t offset, uint64_t length)> notify) override;
-  double get_fragmentation(uint64_t) override
+  double get_fragmentation() override
   {
     return _get_fragmentation();
   }
index f8c6eeea83789e9251f9a8d8a2b4d9332e3e6594..c8a502a448a3b70b7bbe6508c12fe9b4574af54e 100644 (file)
@@ -11259,7 +11259,7 @@ void BlueStore::_kv_finalize_thread()
       _reap_collections();
 
       logger->set(l_bluestore_fragmentation,
-         (uint64_t)(alloc->get_fragmentation(min_alloc_size) * 1000));
+         (uint64_t)(alloc->get_fragmentation() * 1000));
 
       log_latency("kv_final",
        l_bluestore_kv_final_lat,
index c80c855ad40e43b504590eab79e18baebb3bcaf5..f75f74468a9ffd6d701446681ac7a579fbcd4acd 100644 (file)
 #undef dout_prefix
 #define dout_prefix *_dout << "stupidalloc 0x" << this << " "
 
-StupidAllocator::StupidAllocator(CephContext* cct, const std::string& name)
+StupidAllocator::StupidAllocator(CephContext* cct,
+                                 const std::string& name,
+                                 int64_t _block_size)
   : Allocator(name), cct(cct), num_free(0),
     free(10),
-    last_alloc(0)
+    last_alloc(0),
+    block_size(_block_size)
 {
 }
 
@@ -253,15 +256,15 @@ uint64_t StupidAllocator::get_free()
   return num_free;
 }
 
-double StupidAllocator::get_fragmentation(uint64_t alloc_unit)
+double StupidAllocator::get_fragmentation()
 {
-  ceph_assert(alloc_unit);
+  ceph_assert(block_size);
   double res;
   uint64_t max_intervals = 0;
   uint64_t intervals = 0;
   {
     std::lock_guard l(lock);
-    max_intervals = p2roundup<uint64_t>(num_free, alloc_unit) / alloc_unit;
+    max_intervals = p2roundup<uint64_t>(num_free, block_size) / block_size;
     for (unsigned bin = 0; bin < free.size(); ++bin) {
       intervals += free[bin].num_intervals();
     }
index 23264757c3fd5f7e0d035d44f8b0604628cb6289..d9c4a4478b632cc5ee3524115a9c232232b76501 100644 (file)
@@ -18,6 +18,7 @@ class StupidAllocator : public Allocator {
   ceph::mutex lock = ceph::make_mutex("StupidAllocator::lock");
 
   int64_t num_free;     ///< total bytes in freelist
+  int64_t block_size;
 
   typedef mempool::bluestore_alloc::pool_allocator<
     pair<const uint64_t,uint64_t>> allocator_t;
@@ -35,7 +36,7 @@ class StupidAllocator : public Allocator {
     uint64_t alloc_unit);
 
 public:
-  StupidAllocator(CephContext* cct, const std::string& name = "");
+  StupidAllocator(CephContext* cct, const std::string& name, int64_t block_size);
   ~StupidAllocator() override;
 
   int64_t allocate(
@@ -50,7 +51,7 @@ public:
     const interval_set<uint64_t>& release_set) override;
 
   uint64_t get_free() override;
-  double get_fragmentation(uint64_t alloc_unit) override;
+  double get_fragmentation() override;
 
   void dump() override;
   void dump(std::function<void(uint64_t offset, uint64_t length)> notify) override;
index 73f95f5b56aacb912adb5b24595b76b004612fb3..4659e00e94ef89a16d0d3187c5a505246e42ed84 100644 (file)
@@ -242,7 +242,7 @@ TEST_P(AllocTest, test_alloc_fragmentation)
   alloc->init_add_free(0, capacity);
   bool bitmap_alloc = GetParam() == std::string("bitmap");
   
-  EXPECT_EQ(0.0, alloc->get_fragmentation(alloc_unit));
+  EXPECT_EQ(0.0, alloc->get_fragmentation());
 
   for (size_t i = 0; i < capacity / alloc_unit; ++i)
   {
@@ -254,7 +254,7 @@ TEST_P(AllocTest, test_alloc_fragmentation)
     // bitmap fragmentation calculation doesn't provide such constant
     // estimate
     if (!bitmap_alloc) {
-      EXPECT_EQ(0.0, alloc->get_fragmentation(alloc_unit));
+      EXPECT_EQ(0.0, alloc->get_fragmentation());
     }
   }
   EXPECT_EQ(-ENOSPC, alloc->allocate(want_size, alloc_unit, 0, 0, &tmp));
@@ -271,7 +271,7 @@ TEST_P(AllocTest, test_alloc_fragmentation)
     release_set.insert(allocated[i].offset, allocated[i].length);
     alloc->release(release_set);
   }
-  EXPECT_EQ(1.0, alloc->get_fragmentation(alloc_unit));
+  EXPECT_EQ(1.0, alloc->get_fragmentation());
   EXPECT_EQ(66u, uint64_t(alloc->get_fragmentation_score() * 100));
 
   for (size_t i = 1; i < allocated.size() / 2; i += 2)
@@ -282,10 +282,10 @@ TEST_P(AllocTest, test_alloc_fragmentation)
   }
   if (bitmap_alloc) {
     // fragmentation = one l1 slot is free + one l1 slot is partial
-    EXPECT_EQ(50U, uint64_t(alloc->get_fragmentation(alloc_unit) * 100));
+    EXPECT_EQ(50U, uint64_t(alloc->get_fragmentation() * 100));
   } else {
     // fragmentation approx = 257 intervals / 768 max intervals
-    EXPECT_EQ(33u, uint64_t(alloc->get_fragmentation(alloc_unit) * 100));
+    EXPECT_EQ(33u, uint64_t(alloc->get_fragmentation() * 100));
   }
   EXPECT_EQ(27u, uint64_t(alloc->get_fragmentation_score() * 100));
 
@@ -299,7 +299,7 @@ TEST_P(AllocTest, test_alloc_fragmentation)
   // extents that causes some minor fragmentation (minor bug or by-design behavior?).
   // Hence leaving just two 
   // digits after decimal point due to this.
-  EXPECT_EQ(0u, uint64_t(alloc->get_fragmentation(alloc_unit) * 100));
+  EXPECT_EQ(0u, uint64_t(alloc->get_fragmentation() * 100));
   if (bitmap_alloc) {
     EXPECT_EQ(0u, uint64_t(alloc->get_fragmentation_score() * 100));
   } else {
@@ -321,7 +321,7 @@ TEST_P(AllocTest, test_dump_fragmentation_score)
   init_alloc(capacity, alloc_unit);
   alloc->init_add_free(0, capacity);
 
-  EXPECT_EQ(0.0, alloc->get_fragmentation(alloc_unit));
+  EXPECT_EQ(0.0, alloc->get_fragmentation());
   EXPECT_EQ(0.0, alloc->get_fragmentation_score());
 
   uint64_t allocated_cnt = 0;