Skip to content

Commit

Permalink
os/bluestore: use map to tracking writing buffers
Browse files Browse the repository at this point in the history
By keeping the writing buffers ordered, the finish_write()
process does not need to traverse the whole writing list
each time it is called any more, which is good for performance.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
  • Loading branch information
xiexingguo committed Jul 14, 2016
1 parent 3325ab0 commit 4b5e2d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
34 changes: 21 additions & 13 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1016,24 +1016,32 @@ void BlueStore::BufferSpace::read(
void BlueStore::BufferSpace::finish_write(uint64_t seq)
{
std::lock_guard<std::mutex> l(cache->lock);
auto i = writing.begin();
while (i != writing.end()) {
Buffer *b = &*i;
dout(20) << __func__ << " " << *b << dendl;
assert(b->is_writing());
if (b->seq <= seq) {

auto i = writing_map.begin();
while (i != writing_map.end()) {
if (i->first > seq)
break;

auto l = i->second.begin();
while (l != i->second.end()) {
Buffer *b = &*l;
dout(20) << __func__ << " " << *b << dendl;
assert(b->is_writing());

if (b->flags & Buffer::FLAG_NOCACHE) {
++i;
_rm_buffer(b);
i->second.erase(l++);
buffer_map.erase(b->offset);
} else {
b->state = Buffer::STATE_CLEAN;
writing.erase(i++);
cache->_add_buffer(b, 1, nullptr);
b->state = Buffer::STATE_CLEAN;
i->second.erase(l++);
cache->_add_buffer(b, 1, nullptr);
}
} else {
++i;
}

assert(i->second.empty());
writing_map.erase(i++);
}

cache->_audit("finish_write end");
}

Expand Down
13 changes: 9 additions & 4 deletions src/os/bluestore/BlueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@ class BlueStore : public ObjectStore,

map<uint64_t,std::unique_ptr<Buffer>> buffer_map;
Cache *cache;
state_list_t writing;
map<uint64_t, state_list_t> writing_map;

BufferSpace(Cache *c) : cache(c) {}
~BufferSpace() {
assert(buffer_map.empty());
assert(writing.empty());
assert(writing_map.empty());
}

void _add_buffer(Buffer *b, int level, Buffer *near) {
cache->_audit("_add_buffer start");
buffer_map[b->offset].reset(b);
if (b->is_writing()) {
writing.push_back(*b);
writing_map[b->seq].push_back(*b);
} else {
cache->_add_buffer(b, level, near);
}
Expand All @@ -223,7 +223,12 @@ class BlueStore : public ObjectStore,
void _rm_buffer(map<uint64_t,std::unique_ptr<Buffer>>::iterator p) {
cache->_audit("_rm_buffer start");
if (p->second->is_writing()) {
writing.erase(writing.iterator_to(*p->second));
uint64_t seq = (*p->second.get()).seq;
auto it = writing_map.find(seq);
assert(it != writing_map.end());
it->second.erase(it->second.iterator_to(*p->second));
if (it->second.empty())
writing_map.erase(it);
} else {
cache->_rm_buffer(p->second.get());
}
Expand Down

0 comments on commit 4b5e2d6

Please sign in to comment.