]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: add release(PExtentVector) helper to Allocator class to
authorIgor Fedotov <ifedotov@suse.com>
Mon, 7 May 2018 13:58:43 +0000 (16:58 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Fri, 15 Mar 2019 14:05:03 +0000 (17:05 +0300)
free PExtentVector explicitly.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 328ea72a84edef4a6c4e0558dff52d0e85f05122)

src/os/bluestore/Allocator.cc
src/os/bluestore/Allocator.h
src/os/bluestore/BitMapAllocator.cc
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueStore.cc

index 8a4101eae2d817859debb0137ac1623cfd3fbe4e..059e088e1822b672ed0a8a1b3854e30af1258c87 100644 (file)
@@ -20,3 +20,12 @@ Allocator *Allocator::create(CephContext* cct, string type,
             << type << dendl;
   return nullptr;
 }
+
+void Allocator::release(const PExtentVector& release_vec)
+{
+  interval_set<uint64_t> release_set;
+  for (auto e : release_vec) {
+    release_set.insert(e.offset, e.length);
+  }
+  release(release_set);
+}
index 6594d8aeb6029f6d16874f6d0d8fcceb743b81dc..8d821116d68e407110ed6cbe569ef6d52df6bd9f 100644 (file)
@@ -41,6 +41,7 @@ public:
   /* Bulk release. Implementations may override this method to handle the whole
    * set at once. This could save e.g. unnecessary mutex dance. */
   virtual void release(const interval_set<uint64_t>& release_set) = 0;
+  void release(const PExtentVector& release_set);
 
   virtual void dump() = 0;
 
index 4ef5e61cdd2ddcc7fd87f838888ccead95834b25..f9601939f53718bdbae2e67001c2fcaebc9a7a39 100644 (file)
@@ -90,7 +90,19 @@ int64_t BitMapAllocator::allocate(
 
   assert(!max_alloc_size || max_alloc_size >= alloc_unit);
 
-  //FIXME: reproduce reserve/unreserve
+  {
+    int nblks = want_size / m_block_size; // apply floor
+    assert(!(want_size % m_block_size));
+    dout(10) << __func__ << " instance " << (uint64_t) this
+           << " num_used " << m_bit_alloc->get_used_blocks()
+           << " total " << m_bit_alloc->total_blocks()
+           << dendl;
+
+    if (!m_bit_alloc->reserve_blocks(nblks)) {
+      return -ENOSPC;
+    }
+  }
+
 
   dout(10) << __func__ <<" instance "<< (uint64_t) this
      << " want_size " << want_size
@@ -98,8 +110,23 @@ int64_t BitMapAllocator::allocate(
      << " hint " << hint
      << dendl;
   hint = hint % m_total_size; // make hint error-tolerant
-  return allocate_dis(want_size, alloc_unit / m_block_size,
+  auto res = allocate_dis(want_size, alloc_unit / m_block_size,
                       max_alloc_size, hint / m_block_size, extents);
+
+  if (res < want_size) {
+    auto unused = want_size - res;
+    int nblks = unused / m_block_size;
+    assert(!(unused % m_block_size));
+
+    dout(10) << __func__ << " instance " << (uint64_t) this
+            << " unused " << nblks
+            << " num used " << m_bit_alloc->get_used_blocks()
+            << " total " << m_bit_alloc->total_blocks()
+            << dendl;
+
+    m_bit_alloc->unreserve_blocks(nblks);
+  }
+  return res;
 }
 
 int64_t BitMapAllocator::allocate_dis(
index 2f49174574912fc869b459c4add91c9a7409b9a6..a608b0311105f003cdbe7f98594534920ce69ebf 100644 (file)
@@ -2002,11 +2002,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,
   }
   if (alloc_len < (int64_t)left) {
     if (alloc_len != 0) {
-      interval_set<uint64_t> to_release;
-      for (auto& p : extents) {
-        to_release.insert(p.offset, p.length);
-      }
-      alloc[id]->release(to_release);
+      alloc[id]->release(extents);
     }
     if (id != BDEV_SLOW) {
       if (bdev[id]) {
index cd4016a1666909738af78ab565b19ae4d94cfe21..94fa4362dd58fa65c809cecba5436b793e068220 100644 (file)
@@ -6629,11 +6629,7 @@ int BlueStore::_fsck(bool deep, bool repair)
              derr << __func__ << " allocate failed on 0x" << std::hex << e->length
                    << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl;
              if (alloc_len > 0) {
-               interval_set<uint64_t> release_set;
-               for (auto e : exts) {
-                 release_set.insert(e.offset, e.length);
-               }
-               alloc->release(release_set);
+               alloc->release(exts);
              }
              bypass_rest = true;
              break;