]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/os/bluestore/StupidAllocator.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / os / bluestore / StupidAllocator.cc
index c7224ea8c4e86b9836fd03c2e576197d0a8ee48b..13f38d692e9fa9838d68c1d66e3b5d78c82a0a1b 100644 (file)
@@ -25,23 +25,23 @@ unsigned StupidAllocator::_choose_bin(uint64_t orig_len)
 {
   uint64_t len = orig_len / cct->_conf->bdev_block_size;
   int bin = std::min((int)cbits(len), (int)free.size() - 1);
-  dout(30) << __func__ << " len 0x" << std::hex << orig_len << std::dec
-          << " -> " << bin << dendl;
+  ldout(cct, 30) << __func__ << " len 0x" << std::hex << orig_len
+                << std::dec << " -> " << bin << dendl;
   return bin;
 }
 
 void StupidAllocator::_insert_free(uint64_t off, uint64_t len)
 {
   unsigned bin = _choose_bin(len);
-  dout(30) << __func__ << " 0x" << std::hex << off << "~" << len << std::dec
-          << " in bin " << bin << dendl;
+  ldout(cct, 30) << __func__ << " 0x" << std::hex << off << "~" << len
+                << std::dec << " in bin " << bin << dendl;
   while (true) {
     free[bin].insert(off, len, &off, &len);
     unsigned newbin = _choose_bin(len);
     if (newbin == bin)
       break;
-    dout(30) << __func__ << " promoting 0x" << std::hex << off << "~" << len
-            << std::dec << " to bin " << newbin << dendl;
+    ldout(cct, 30) << __func__ << " promoting 0x" << std::hex << off << "~" << len
+                  << std::dec << " to bin " << newbin << dendl;
     free[bin].erase(off, len);
     bin = newbin;
   }
@@ -65,12 +65,12 @@ int64_t StupidAllocator::allocate_int(
   uint64_t want_size, uint64_t alloc_unit, int64_t hint,
   uint64_t *offset, uint32_t *length)
 {
-  std::lock_guard<std::mutex> l(lock);
-  dout(10) << __func__ << " want_size 0x" << std::hex << want_size
-          << " alloc_unit 0x" << alloc_unit
-          << " hint 0x" << hint << std::dec
-          << dendl;
-  uint64_t want = MAX(alloc_unit, want_size);
+  std::lock_guard l(lock);
+  ldout(cct, 10) << __func__ << " want_size 0x" << std::hex << want_size
+                << " alloc_unit 0x" << alloc_unit
+                << " hint 0x" << hint << std::dec
+                << dendl;
+  uint64_t want = std::max(alloc_unit, want_size);
   int bin = _choose_bin(want);
   int orig_bin = bin;
 
@@ -136,27 +136,28 @@ int64_t StupidAllocator::allocate_int(
   if (skew)
     skew = alloc_unit - skew;
   *offset = p.get_start() + skew;
-  *length = MIN(MAX(alloc_unit, want_size), P2ALIGN((p.get_len() - skew), alloc_unit));
+  *length = std::min(std::max(alloc_unit, want_size), p2align((p.get_len() - skew), alloc_unit));
   if (cct->_conf->bluestore_debug_small_allocations) {
     uint64_t max =
       alloc_unit * (rand() % cct->_conf->bluestore_debug_small_allocations);
     if (max && *length > max) {
-      dout(10) << __func__ << " shortening allocation of 0x" << std::hex
-              << *length << " -> 0x"
-              << max << " due to debug_small_allocations" << std::dec << dendl;
+      ldout(cct, 10) << __func__ << " shortening allocation of 0x" << std::hex
+                    << *length << " -> 0x"
+                    << max << " due to debug_small_allocations" << std::dec
+                    << dendl;
       *length = max;
     }
   }
-  dout(30) << __func__ << " got 0x" << std::hex << *offset << "~" << *length
-          << " from bin " << std::dec << bin << dendl;
+  ldout(cct, 30) << __func__ << " got 0x" << std::hex << *offset << "~" << *length
+                << " from bin " << std::dec << bin << dendl;
 
   free[bin].erase(*offset, *length);
   uint64_t off, len;
   if (*offset && free[bin].contains(*offset - skew - 1, &off, &len)) {
     int newbin = _choose_bin(len);
     if (newbin != bin) {
-      dout(30) << __func__ << " demoting 0x" << std::hex << off << "~" << len
-              << std::dec << " to bin " << newbin << dendl;
+      ldout(cct, 30) << __func__ << " demoting 0x" << std::hex << off << "~" << len
+                    << std::dec << " to bin " << newbin << dendl;
       free[bin].erase(off, len);
       _insert_free(off, len);
     }
@@ -164,15 +165,15 @@ int64_t StupidAllocator::allocate_int(
   if (free[bin].contains(*offset + *length, &off, &len)) {
     int newbin = _choose_bin(len);
     if (newbin != bin) {
-      dout(30) << __func__ << " demoting 0x" << std::hex << off << "~" << len
-              << std::dec << " to bin " << newbin << dendl;
+      ldout(cct, 30) << __func__ << " demoting 0x" << std::hex << off << "~" << len
+                    << std::dec << " to bin " << newbin << dendl;
       free[bin].erase(off, len);
       _insert_free(off, len);
     }
   }
 
   num_free -= *length;
-  assert(num_free >= 0);
+  ceph_assert(num_free >= 0);
   last_alloc = *offset + *length;
   return 0;
 }
@@ -194,7 +195,7 @@ int64_t StupidAllocator::allocate(
   }
 
   while (allocated_size < want_size) {
-    res = allocate_int(MIN(max_alloc_size, (want_size - allocated_size)),
+    res = allocate_int(std::min(max_alloc_size, (want_size - allocated_size)),
        alloc_unit, hint, &offset, &length);
     if (res != 0) {
       /*
@@ -228,7 +229,7 @@ int64_t StupidAllocator::allocate(
 void StupidAllocator::release(
   const interval_set<uint64_t>& release_set)
 {
-  std::lock_guard<std::mutex> l(lock);
+  std::lock_guard l(lock);
   for (interval_set<uint64_t>::const_iterator p = release_set.begin();
        p != release_set.end();
        ++p) {
@@ -243,26 +244,26 @@ void StupidAllocator::release(
 
 uint64_t StupidAllocator::get_free()
 {
-  std::lock_guard<std::mutex> l(lock);
+  std::lock_guard l(lock);
   return num_free;
 }
 
 double StupidAllocator::get_fragmentation(uint64_t alloc_unit)
 {
-  assert(alloc_unit);
+  ceph_assert(alloc_unit);
   double res;
   uint64_t max_intervals = 0;
   uint64_t intervals = 0;
   {
-    std::lock_guard<std::mutex> l(lock);
-    max_intervals = num_free / alloc_unit;
+    std::lock_guard l(lock);
+    max_intervals = p2roundup<uint64_t>(num_free, alloc_unit) / alloc_unit;
     for (unsigned bin = 0; bin < free.size(); ++bin) {
       intervals += free[bin].num_intervals();
     }
   }
   ldout(cct, 30) << __func__ << " " << intervals << "/" << max_intervals 
                  << dendl;
-  assert(intervals <= max_intervals);
+  ceph_assert(intervals <= max_intervals);
   if (!intervals || max_intervals <= 1) {
     return 0.0;
   }
@@ -274,41 +275,41 @@ double StupidAllocator::get_fragmentation(uint64_t alloc_unit)
 
 void StupidAllocator::dump()
 {
-  std::lock_guard<std::mutex> l(lock);
+  std::lock_guard l(lock);
   for (unsigned bin = 0; bin < free.size(); ++bin) {
-    dout(0) << __func__ << " free bin " << bin << ": "
-           << free[bin].num_intervals() << " extents" << dendl;
+    ldout(cct, 0) << __func__ << " free bin " << bin << ": "
+                 << free[bin].num_intervals() << " extents" << dendl;
     for (auto p = free[bin].begin();
         p != free[bin].end();
         ++p) {
-      dout(0) << __func__ << "  0x" << std::hex << p.get_start() << "~"
-             << p.get_len() << std::dec << dendl;
+      ldout(cct, 0) << __func__ << "  0x" << std::hex << p.get_start() << "~"
+                   << p.get_len() << std::dec << dendl;
     }
   }
 }
 
 void StupidAllocator::init_add_free(uint64_t offset, uint64_t length)
 {
-  std::lock_guard<std::mutex> l(lock);
-  dout(10) << __func__ << " 0x" << std::hex << offset << "~" << length
-          << std::dec << dendl;
+  std::lock_guard l(lock);
+  ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
+                << std::dec << dendl;
   _insert_free(offset, length);
   num_free += length;
 }
 
 void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length)
 {
-  std::lock_guard<std::mutex> l(lock);
-  dout(10) << __func__ << " 0x" << std::hex << offset << "~" << length
-          << std::dec << dendl;
+  std::lock_guard l(lock);
+  ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
+                << std::dec << dendl;
   interval_set_t rm;
   rm.insert(offset, length);
   for (unsigned i = 0; i < free.size() && !rm.empty(); ++i) {
     interval_set_t overlap;
     overlap.intersection_of(rm, free[i]);
     if (!overlap.empty()) {
-      dout(20) << __func__ << " bin " << i << " rm 0x" << std::hex << overlap
-              << std::dec << dendl;
+      ldout(cct, 20) << __func__ << " bin " << i << " rm 0x" << std::hex << overlap
+                    << std::dec << dendl;
       auto it = overlap.begin();
       auto it_end = overlap.end();
       while (it != it_end) {
@@ -332,14 +333,14 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length)
       rm.subtract(overlap);
     }
   }
-  assert(rm.empty());
+  ceph_assert(rm.empty());
   num_free -= length;
-  assert(num_free >= 0);
+  ceph_assert(num_free >= 0);
 }
 
 
 void StupidAllocator::shutdown()
 {
-  dout(1) << __func__ << dendl;
+  ldout(cct, 1) << __func__ << dendl;
 }