]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/os/bluestore/StupidAllocator.cc
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / os / bluestore / StupidAllocator.cc
index 550024e67e77dc8d199a473e4cc578d87a2c7af9..8f74a499ed3127e167d1cccf48e064f68876465d 100644 (file)
@@ -52,20 +52,6 @@ void StupidAllocator::_insert_free(uint64_t off, uint64_t len)
   }
 }
 
-/// return the effective length of the extent if we align to alloc_unit
-uint64_t StupidAllocator::_aligned_len(
-  StupidAllocator::interval_set_t::iterator p,
-  uint64_t alloc_unit)
-{
-  uint64_t skew = p.get_start() % alloc_unit;
-  if (skew)
-    skew = alloc_unit - skew;
-  if (skew > p.get_len())
-    return 0;
-  else
-    return p.get_len() - skew;
-}
-
 int64_t StupidAllocator::allocate_int(
   uint64_t want_size, uint64_t alloc_unit, int64_t hint,
   uint64_t *offset, uint32_t *length)
@@ -89,7 +75,7 @@ int64_t StupidAllocator::allocate_int(
     for (bin = orig_bin; bin < (int)free.size(); ++bin) {
       p = free[bin].lower_bound(hint);
       while (p != free[bin].end()) {
-       if (_aligned_len(p, alloc_unit) >= want_size) {
+       if (p.get_len() >= want_size) {
          goto found;
        }
        ++p;
@@ -102,7 +88,7 @@ int64_t StupidAllocator::allocate_int(
     p = free[bin].begin();
     auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
     while (p != end) {
-      if (_aligned_len(p, alloc_unit) >= want_size) {
+      if (p.get_len() >= want_size) {
        goto found;
       }
       ++p;
@@ -114,7 +100,7 @@ int64_t StupidAllocator::allocate_int(
     for (bin = orig_bin; bin >= 0; --bin) {
       p = free[bin].lower_bound(hint);
       while (p != free[bin].end()) {
-       if (_aligned_len(p, alloc_unit) >= alloc_unit) {
+       if (p.get_len() >= alloc_unit) {
          goto found;
        }
        ++p;
@@ -127,7 +113,7 @@ int64_t StupidAllocator::allocate_int(
     p = free[bin].begin();
     auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
     while (p != end) {
-      if (_aligned_len(p, alloc_unit) >= alloc_unit) {
+      if (p.get_len() >= alloc_unit) {
        goto found;
       }
       ++p;
@@ -137,11 +123,9 @@ int64_t StupidAllocator::allocate_int(
   return -ENOSPC;
 
  found:
-  uint64_t skew = p.get_start() % alloc_unit;
-  if (skew)
-    skew = alloc_unit - skew;
-  *offset = p.get_start() + skew;
-  *length = std::min(std::max(alloc_unit, want_size), p2align((p.get_len() - skew), alloc_unit));
+  *offset = p.get_start();
+  *length = std::min(std::max(alloc_unit, want_size), p2align(p.get_len(), alloc_unit));
+
   if (cct->_conf->bluestore_debug_small_allocations) {
     uint64_t max =
       alloc_unit * (rand() % cct->_conf->bluestore_debug_small_allocations);
@@ -158,7 +142,7 @@ int64_t StupidAllocator::allocate_int(
 
   free[bin].erase(*offset, *length);
   uint64_t off, len;
-  if (*offset && free[bin].contains(*offset - skew - 1, &off, &len)) {
+  if (*offset && free[bin].contains(*offset - 1, &off, &len)) {
     int newbin = _choose_bin(len);
     if (newbin != bin) {
       ldout(cct, 30) << __func__ << " demoting 0x" << std::hex << off << "~" << len