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");
};
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());
}
};
-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);
}
{
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") {
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
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
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(
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(
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,
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 << "/"
{
}
+ 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;
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,
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);
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();
}
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 =
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,