Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/bluestore: fix the allocate in bluefs #19030

Merged
merged 1 commit into from
Nov 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 23 additions & 19 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1927,10 +1927,30 @@ 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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tangwenjun3 If reserve() is okay but we fail to allocate(), we should call unreserve() first before we switch to try other devices(e.g., slow), right? otherwise there is potential space leaks..

if (r == 0) {
interval_set<uint64_t> to_release;
alloc[id]->unreserve(left - alloc_len);
for (auto& p : extents) {
to_release.insert(p.offset, p.length);
}
alloc[id]->release(to_release);
}
if (id != BDEV_SLOW) {
if (bdev[id]) {
dout(1) << __func__ << " failed to allocate 0x" << std::hex << left
Expand All @@ -1948,24 +1968,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