]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: write out general allocator parameters on allocator dump.
authorIgor Fedotov <ifedotov@suse.com>
Thu, 3 Dec 2020 18:48:55 +0000 (21:48 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Fri, 4 Dec 2020 12:19:38 +0000 (15:19 +0300)
This includes allocator type, name, size, allocation unit which enables
allocator dump replay implementation.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/os/bluestore/Allocator.cc
src/os/bluestore/Allocator.h
src/os/bluestore/AvlAllocator.cc
src/os/bluestore/AvlAllocator.h
src/os/bluestore/BitmapAllocator.cc
src/os/bluestore/BitmapAllocator.h
src/os/bluestore/HybridAllocator.h
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h

index eaabccfe56536419f48dd936a2dd78499dc7b720..91a001b5c9749ca07256d16457db2e03dddf1a7f 100644 (file)
@@ -69,7 +69,13 @@ public:
           bufferlist& out) override {
     int r = 0;
     if (command == "bluestore allocator dump " + name) {
-      f->open_array_section("free_regions");
+      f->open_object_section("allocator_dump");
+      f->dump_unsigned("capacity", alloc->get_capacity());
+      f->dump_unsigned("alloc_unit", alloc->get_block_size());
+      f->dump_string("alloc_type", alloc->get_type());
+      f->dump_string("alloc_name", name);
+
+      f->open_array_section("extents");
       auto iterated_allocation = [&](size_t off, size_t len) {
         ceph_assert(len > 0);
         f->open_object_section("free");
@@ -83,6 +89,7 @@ public:
       };
       alloc->dump(iterated_allocation);
       f->close_section();
+      f->close_section();
     } else if (command == "bluestore allocator score " + name) {
       f->open_object_section("fragmentation_score");
       f->dump_float("fragmentation_rating", alloc->get_fragmentation_score());
@@ -99,7 +106,10 @@ public:
   }
 
 };
-Allocator::Allocator(const std::string& name)
+Allocator::Allocator(const std::string& name,
+                     int64_t _capacity,
+                     int64_t _block_size)
+  : capacity(_capacity), block_size(_block_size)
 {
   asok_hook = new SocketHook(this, name);
 }
@@ -119,7 +129,7 @@ Allocator *Allocator::create(CephContext* cct, string type,
 {
   Allocator* alloc = nullptr;
   if (type == "stupid") {
-    alloc = new StupidAllocator(cct, name, block_size);
+    alloc = new StupidAllocator(cct, name, size, block_size);
   } else if (type == "bitmap") {
     alloc = new BitmapAllocator(cct, size, block_size, name);
   } else if (type == "avl") {
index 2104c2cc1139e0e4193b71058e06df63fe212b90..d44dfa9e680367aacc1d7145e6d784fbeacf7dce 100644 (file)
 
 class Allocator {
 public:
-  explicit Allocator(const std::string& name);
+  explicit Allocator(const std::string& name,
+                     int64_t _capacity,
+                     int64_t _block_size);
   virtual ~Allocator();
 
+  /*
+  * returns allocator type name as per names in config
+  */
+  virtual const char* get_type() const = 0;
+
   /*
    * Allocate required number of blocks in n number of extents.
    * Min and Max number of extents are limited by:
    * a. alloc unit
    * b. max_alloc_size.
-   * as no extent can be lesser than alloc_unit and greater than max_alloc size.
+   * as no extent can be lesser than block_size and greater than max_alloc size.
    * Apart from that extents can vary between these lower and higher limits according
    * to free block search algorithm and availability of contiguous space.
    */
-  virtual int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
+  virtual int64_t allocate(uint64_t want_size, uint64_t block_size,
                           uint64_t max_alloc_size, int64_t hint,
                           PExtentVector *extents) = 0;
 
-  int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
+  int64_t allocate(uint64_t want_size, uint64_t block_size,
                   int64_t hint, PExtentVector *extents) {
-    return allocate(want_size, alloc_unit, want_size, hint, extents);
+    return allocate(want_size, block_size, want_size, hint, extents);
   }
 
   /* Bulk release. Implementations may override this method to handle the whole
@@ -64,11 +71,23 @@ public:
   static Allocator *create(CephContext* cct, std::string type, int64_t size,
                           int64_t block_size, const std::string& name = "");
 
+
   const string& get_name() const;
+  int64_t get_capacity() const
+  {
+    return capacity;
+  }
+  int64_t get_block_size() const
+  {
+    return block_size;
+  }
 
 private:
   class SocketHook;
   SocketHook* asok_hook = nullptr;
+
+  int64_t capacity = 0;
+  int64_t block_size = 0;
 };
 
 #endif
index 3a1f66f7f2bced35cfc4294afa5eeeaaa0ecee94..27031e6c6bec95d8ebd24ceb9f9bc6a827eb0e3c 100644 (file)
@@ -289,7 +289,7 @@ AvlAllocator::AvlAllocator(CephContext* cct,
                            int64_t block_size,
                            uint64_t max_mem,
                            const std::string& name) :
-  Allocator(name),
+  Allocator(name, device_size, block_size),
   num_total(device_size),
   block_size(block_size),
   range_size_alloc_threshold(
@@ -304,7 +304,7 @@ AvlAllocator::AvlAllocator(CephContext* cct,
                           int64_t device_size,
                           int64_t block_size,
                           const std::string& name) :
-  Allocator(name),
+  Allocator(name, device_size, block_size),
   num_total(device_size),
   block_size(block_size),
   range_size_alloc_threshold(
index bcc3f8b051b1c3ce552eaf0584fa8c0cc6327430..426db78ad39eaa21921a7ddfc41d633050643fee 100644 (file)
@@ -71,6 +71,10 @@ public:
   AvlAllocator(CephContext* cct, int64_t device_size, int64_t block_size,
               const std::string& name);
   ~AvlAllocator();
+  const char* get_type() const override
+  {
+    return "avl";
+  }
   int64_t allocate(
     uint64_t want,
     uint64_t unit,
index c24a333aae3168ef20200bf17b154851f2fb54a9..a744eb17bfea05b5b91eea715305d58cafbe8ec6 100644 (file)
@@ -12,7 +12,7 @@ BitmapAllocator::BitmapAllocator(CephContext* _cct,
                                         int64_t capacity,
                                         int64_t alloc_unit,
                                         const std::string& name) :
-    Allocator(name),
+    Allocator(name, capacity, alloc_unit),
     cct(_cct)
 {
   ldout(cct, 10) << __func__ << " 0x" << std::hex << capacity << "/"
index 51ebaa4208c84a49293a39845df80ec0ed25e678..5c768a4ac2fb1ede2d42c8175aa343df365b0268 100644 (file)
@@ -22,6 +22,10 @@ public:
   {
   }
 
+  const char* get_type() const override
+  {
+    return "bitmap";
+  }
   int64_t allocate(
     uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
     int64_t hint, PExtentVector *extents) override;
index e8246cf4dfcb25621bbccb43c8e9ab850b16ae20..92e8b9e80b18a380c0c24dca7995a87d02f64112 100644 (file)
@@ -16,6 +16,10 @@ public:
                  const std::string& name) :
       AvlAllocator(cct, device_size, _block_size, max_mem, name) {
   }
+  const char* get_type() const override
+  {
+    return "hybrid";
+  }
   int64_t allocate(
     uint64_t want,
     uint64_t unit,
index 0f4726d767746f0f1f12e663f72c18ebdee60b0b..533f279d7801d65a47080650fd19999da16c9231 100644 (file)
@@ -12,9 +12,9 @@
 
 StupidAllocator::StupidAllocator(CephContext* cct,
                                  const std::string& name,
+                                 int64_t _size,
                                  int64_t _block_size)
-  : Allocator(name), cct(cct), num_free(0),
-    block_size(_block_size),
+  : Allocator(name, _size, _block_size), cct(cct), num_free(0),
     free(10)
 {
   ceph_assert(cct != nullptr);
@@ -260,13 +260,14 @@ uint64_t StupidAllocator::get_free()
 
 double StupidAllocator::get_fragmentation()
 {
-  ceph_assert(block_size);
+  ceph_assert(get_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, block_size) / block_size;
+    max_intervals = p2roundup<uint64_t>(num_free,
+                                        get_block_size()) / get_block_size();
     for (unsigned bin = 0; bin < free.size(); ++bin) {
       intervals += free[bin].num_intervals();
     }
index 0bf189779c8cc0950148f932d22e420c1b5622c0..bd99a7c835fcddd9576f03d952a5047db36942e8 100644 (file)
@@ -18,7 +18,6 @@ class StupidAllocator : public Allocator {
   ceph::mutex lock = ceph::make_mutex("StupidAllocator::lock");
 
   int64_t num_free;     ///< total bytes in freelist
-  int64_t block_size;
   uint64_t bdev_block_size;
 
   template <typename K, typename V> using allocator_t =
@@ -38,8 +37,15 @@ class StupidAllocator : public Allocator {
     uint64_t alloc_unit);
 
 public:
-  StupidAllocator(CephContext* cct, const std::string& name, int64_t block_size);
+  StupidAllocator(CephContext* cct,
+                  const std::string& name,
+                  int64_t size,
+                  int64_t block_size);
   ~StupidAllocator() override;
+  const char* get_type() const override
+  {
+    return "stupid";
+  }
 
   int64_t allocate(
     uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,