From: Igor Fedotov Date: Thu, 3 Dec 2020 18:48:55 +0000 (+0300) Subject: os/bluestore: write out general allocator parameters on allocator dump. X-Git-Tag: v16.1.0~340^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=87bd5314f634789917556856f15943c027962b50;p=ceph.git os/bluestore: write out general allocator parameters on allocator dump. This includes allocator type, name, size, allocation unit which enables allocator dump replay implementation. Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/Allocator.cc b/src/os/bluestore/Allocator.cc index eaabccfe5653..91a001b5c974 100644 --- a/src/os/bluestore/Allocator.cc +++ b/src/os/bluestore/Allocator.cc @@ -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") { diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index 2104c2cc1139..d44dfa9e6803 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -20,25 +20,32 @@ 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 diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index 3a1f66f7f2bc..27031e6c6bec 100644 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -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( diff --git a/src/os/bluestore/AvlAllocator.h b/src/os/bluestore/AvlAllocator.h index bcc3f8b051b1..426db78ad39e 100644 --- a/src/os/bluestore/AvlAllocator.h +++ b/src/os/bluestore/AvlAllocator.h @@ -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, diff --git a/src/os/bluestore/BitmapAllocator.cc b/src/os/bluestore/BitmapAllocator.cc index c24a333aae31..a744eb17bfea 100644 --- a/src/os/bluestore/BitmapAllocator.cc +++ b/src/os/bluestore/BitmapAllocator.cc @@ -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 << "/" diff --git a/src/os/bluestore/BitmapAllocator.h b/src/os/bluestore/BitmapAllocator.h index 51ebaa4208c8..5c768a4ac2fb 100644 --- a/src/os/bluestore/BitmapAllocator.h +++ b/src/os/bluestore/BitmapAllocator.h @@ -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; diff --git a/src/os/bluestore/HybridAllocator.h b/src/os/bluestore/HybridAllocator.h index e8246cf4dfcb..92e8b9e80b18 100644 --- a/src/os/bluestore/HybridAllocator.h +++ b/src/os/bluestore/HybridAllocator.h @@ -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, diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 0f4726d76774..533f279d7801 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -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(num_free, block_size) / block_size; + max_intervals = p2roundup(num_free, + get_block_size()) / get_block_size(); for (unsigned bin = 0; bin < free.size(); ++bin) { intervals += free[bin].num_intervals(); } diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index 0bf189779c8c..bd99a7c835fc 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -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 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,