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