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/BlueFS: fix reclaim_blocks #12725

Merged
merged 2 commits into from Jan 9, 2017
Merged
Show file tree
Hide file tree
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
23 changes: 10 additions & 13 deletions src/os/bluestore/BlueFS.cc
Expand Up @@ -170,7 +170,7 @@ void BlueFS::add_block_extent(unsigned id, uint64_t offset, uint64_t length)
}

int BlueFS::reclaim_blocks(unsigned id, uint64_t want,
uint64_t *offset, uint32_t *length)
AllocExtentVector *extents)
{
std::unique_lock<std::mutex> l(lock);
dout(1) << __func__ << " bdev " << id
Expand All @@ -180,30 +180,27 @@ int BlueFS::reclaim_blocks(unsigned id, uint64_t want,
int r = alloc[id]->reserve(want);
assert(r == 0); // caller shouldn't ask for more than they can get
int count = 0;
uint64_t alloc_len = 0;;
AllocExtentVector extents = AllocExtentVector(want / cct->_conf->bluefs_alloc_size);

uint64_t got = 0;
r = alloc[id]->allocate(want, cct->_conf->bluefs_alloc_size, 0,
&extents, &count, &alloc_len);
extents, &count, &got);

*length = alloc_len;
assert(r >= 0);
if (*length < want)
alloc[id]->unreserve(want - *length);
if (got < want)
alloc[id]->unreserve(want - got);

for (int i = 0; i < count; i++) {
block_all[id].erase(extents[i].offset, extents[i].length);
block_total[id] -= extents[i].length;
log_t.op_alloc_rm(id, extents[i].offset, extents[i].length);
block_all[id].erase((*extents)[i].offset, (*extents)[i].length);
block_total[id] -= (*extents)[i].length;
log_t.op_alloc_rm(id, (*extents)[i].offset, (*extents)[i].length);
}

r = _flush_and_sync_log(l);
assert(r == 0);

if (logger)
logger->inc(l_bluefs_reclaim_bytes, *length);
logger->inc(l_bluefs_reclaim_bytes, got);
dout(1) << __func__ << " bdev " << id << " want 0x" << std::hex << want
<< " got 0x" << *offset << "~" << *length << std::dec << dendl;
<< " got " << *extents << dendl;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/os/bluestore/BlueFS.h
Expand Up @@ -389,7 +389,7 @@ class BlueFS {

/// reclaim block space
int reclaim_blocks(unsigned bdev, uint64_t want,
uint64_t *offset, uint32_t *length);
AllocExtentVector *extents);

void flush(FileWriter *h) {
std::lock_guard<std::mutex> l(lock);
Expand Down
15 changes: 7 additions & 8 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -3715,18 +3715,17 @@ int BlueStore::_balance_bluefs_freespace(vector<bluestore_pextent_t> *extents)
<< " (" << pretty_si_t(reclaim) << ")" << dendl;

while (reclaim > 0) {
uint64_t offset = 0;
uint32_t length = 0;

// NOTE: this will block and do IO.
AllocExtentVector extents;
int r = bluefs->reclaim_blocks(bluefs_shared_bdev, reclaim,
&offset, &length);
&extents);
assert(r >= 0);

bluefs_extents.erase(offset, length);
bluefs_extents_reclaiming.insert(offset, length);

reclaim -= length;
for (auto e : extents) {
bluefs_extents.erase(e.offset, e.length);
bluefs_extents_reclaiming.insert(e.offset, e.length);
reclaim -= e.length;
}
}

ret = 1;
Expand Down
6 changes: 5 additions & 1 deletion src/os/bluestore/bluestore_types.h
Expand Up @@ -80,6 +80,10 @@ class AllocExtent {
}
};

inline static ostream& operator<<(ostream& out, const AllocExtent& e) {
return out << "0x" << std::hex << e.offset << "~" << e.length << std::dec;
}

class ExtentList {
AllocExtentVector *m_extents;
int64_t m_num_extents;
Expand Down Expand Up @@ -125,7 +129,7 @@ class ExtentList {


/// pextent: physical extent
struct bluestore_pextent_t : public AllocExtent{
struct bluestore_pextent_t : public AllocExtent {
const static uint64_t INVALID_OFFSET = ~0ull;

bluestore_pextent_t() : AllocExtent() {}
Expand Down