Skip to content

Commit

Permalink
os/bluestore: fix the allocate in bluefs
Browse files Browse the repository at this point in the history
when bluefs succeed to reserve but failed to alloc in db space,

it will cause a assert, just because of the space fragmentation.

in this situation, it could not use slow device space,

and it would happen in stupid or avl allocator.

Signed-off-by: tangwenjun <tang.wenjun3@zte.com.cn>
  • Loading branch information
tangwenjun3 committed Nov 20, 2017
1 parent 035a588 commit 4550cfd
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/os/bluestore/BlueFS.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1927,10 +1927,24 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,

uint64_t left = ROUND_UP_TO(len, min_alloc_size);
int r = -ENOSPC;
int64_t alloc_len = 0;
AllocExtentVector extents;

if (alloc[id]) {
r = alloc[id]->reserve(left);
}
if (r < 0) {

if (r == 0) {
uint64_t hint = 0;
if (!node->extents.empty() && node->extents.back().bdev == id) {
hint = node->extents.back().end();
}
extents.reserve(4); // 4 should be (more than) enough for most allocations
alloc_len = alloc[id]->allocate(left, min_alloc_size, hint, &extents);
}
if (r < 0 || (alloc_len < (int64_t)left)) {
if (r == 0)
alloc[id]->unreserve(left);
if (id != BDEV_SLOW) {
if (bdev[id]) {
dout(1) << __func__ << " failed to allocate 0x" << std::hex << left
Expand All @@ -1948,24 +1962,8 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,
else
derr << __func__ << " failed to allocate 0x" << std::hex << left
<< " on bdev " << (int)id << ", dne" << std::dec << dendl;
return r;
}

uint64_t hint = 0;
if (!node->extents.empty() && node->extents.back().bdev == id) {
hint = node->extents.back().end();
}

AllocExtentVector extents;
extents.reserve(4); // 4 should be (more than) enough for most allocations
int64_t alloc_len = alloc[id]->allocate(left, min_alloc_size, hint,
&extents);
if (alloc_len < (int64_t)left) {
derr << __func__ << " allocate failed on 0x" << std::hex << left
<< " min_alloc_size 0x" << min_alloc_size
<< " hint 0x" << hint << std::dec << dendl;
alloc[id]->dump();
assert(0 == "allocate failed... wtf");
if (alloc[id])
alloc[id]->dump();
return -ENOSPC;
}

Expand Down

0 comments on commit 4550cfd

Please sign in to comment.