From: Igor Fedotov Date: Mon, 7 May 2018 13:58:43 +0000 (+0300) Subject: os/bluestore: add release(PExtentVector) helper to Allocator class to X-Git-Tag: v12.2.12~16^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1969f97ebef6035836c0374781606829152afca8;p=ceph.git os/bluestore: add release(PExtentVector) helper to Allocator class to free PExtentVector explicitly. Signed-off-by: Igor Fedotov (cherry picked from commit 328ea72a84edef4a6c4e0558dff52d0e85f05122) --- diff --git a/src/os/bluestore/Allocator.cc b/src/os/bluestore/Allocator.cc index 8a4101eae2d..059e088e182 100644 --- a/src/os/bluestore/Allocator.cc +++ b/src/os/bluestore/Allocator.cc @@ -20,3 +20,12 @@ Allocator *Allocator::create(CephContext* cct, string type, << type << dendl; return nullptr; } + +void Allocator::release(const PExtentVector& release_vec) +{ + interval_set release_set; + for (auto e : release_vec) { + release_set.insert(e.offset, e.length); + } + release(release_set); +} diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index 46a0a4ac4c9..ddf194f9148 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -43,6 +43,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& release_set) = 0; + void release(const PExtentVector& release_set); virtual void dump() = 0; diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index 9c7e9751674..823992216f3 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -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( diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index cb4dc11f024..916138351a7 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1872,11 +1872,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len, } if (alloc_len < (int64_t)left) { if (alloc_len != 0) { - interval_set 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]) {