Skip to content

Commit

Permalink
os/bluestore: add release(PExtentVector) helper to Allocator class to
Browse files Browse the repository at this point in the history
free PExtentVector explicitly.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 328ea72)
  • Loading branch information
ifed01 committed Mar 15, 2019
1 parent d8d6cdb commit 4773293
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/os/bluestore/Allocator.cc
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/os/bluestore/Allocator.h
Expand Up @@ -41,6 +41,7 @@ class Allocator {
/* 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;

Expand Down
31 changes: 29 additions & 2 deletions src/os/bluestore/BitMapAllocator.cc
Expand Up @@ -90,16 +90,43 @@ 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
<< " alloc_unit " << alloc_unit
<< " 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(
Expand Down
6 changes: 1 addition & 5 deletions src/os/bluestore/BlueFS.cc
Expand Up @@ -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]) {
Expand Down
6 changes: 1 addition & 5 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -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;
Expand Down

0 comments on commit 4773293

Please sign in to comment.