]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/os/bluestore/StupidAllocator.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / os / bluestore / StupidAllocator.cc
index 2660657d9e93480baa07dfb1d48118e47d72648f..533f279d7801d65a47080650fd19999da16c9231 100644 (file)
 
 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);
+  bdev_block_size = cct->_conf->bdev_block_size;
 }
 
 StupidAllocator::~StupidAllocator()
@@ -25,7 +27,8 @@ StupidAllocator::~StupidAllocator()
 
 unsigned StupidAllocator::_choose_bin(uint64_t orig_len)
 {
-  uint64_t len = orig_len / cct->_conf->bdev_block_size;
+  ceph_assert(bdev_block_size > 0);
+  uint64_t len = orig_len / bdev_block_size;
   int bin = std::min((int)cbits(len), (int)free.size() - 1);
   ldout(cct, 30) << __func__ << " len 0x" << std::hex << orig_len
                 << std::dec << " -> " << bin << dendl;
@@ -257,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();
     }