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: use std::unordered_map for SharedBlob lookup #11394

Merged
merged 1 commit into from Oct 11, 2016
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
5 changes: 0 additions & 5 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -2187,11 +2187,6 @@ BlueStore::Collection::Collection(BlueStore *ns, Cache *c, coll_t cid)
cid(cid),
lock("BlueStore::Collection::lock", true, false),
exists(true),
// size the shared blob hash table as a ratio of the onode cache size.
shared_blob_set(MAX(16,
g_conf->bluestore_onode_cache_size /
store->cache_shards.size() *
g_conf->bluestore_shared_blob_hash_table_size_ratio)),
onode_map(c)
{
}
Expand Down
33 changes: 10 additions & 23 deletions src/os/bluestore/BlueStore.h
Expand Up @@ -318,7 +318,7 @@ class BlueStore : public ObjectStore,
struct SharedBlobSet;

/// in-memory shared blob state (incl cached buffers)
struct SharedBlob : public boost::intrusive::unordered_set_base_hook<> {
struct SharedBlob {
std::atomic_int nref = {0}; ///< reference count

// these are defined/set if the shared_blob is 'loaded'
Expand Down Expand Up @@ -357,53 +357,40 @@ class BlueStore : public ObjectStore,

/// a lookup table of SharedBlobs
struct SharedBlobSet {
typedef boost::intrusive::unordered_set<SharedBlob>::bucket_type bucket_type;
typedef boost::intrusive::unordered_set<SharedBlob>::bucket_traits bucket_traits;

std::mutex lock; ///< protect lookup, insertion, removal
int num_buckets;
vector<bucket_type> buckets;
boost::intrusive::unordered_set<SharedBlob> uset;

SharedBlob dummy; ///< for lookups

explicit SharedBlobSet(unsigned n)
: num_buckets(n),
buckets(n),
uset(bucket_traits(buckets.data(), num_buckets)),
dummy(0, string(), nullptr) {
assert(n > 0);
}
// we use a bare pointer because we don't want to affect the ref
// count
std::unordered_map<uint64_t,SharedBlob*> sb_map;

SharedBlobRef lookup(uint64_t sbid) {
std::lock_guard<std::mutex> l(lock);
dummy.sbid = sbid;
auto p = uset.find(dummy);
if (p == uset.end()) {
auto p = sb_map.find(sbid);
if (p == sb_map.end()) {
return nullptr;
}
return &*p;
return p->second;
}

void add(SharedBlob *sb) {
std::lock_guard<std::mutex> l(lock);
uset.insert(*sb);
sb_map[sb->sbid] = sb;
sb->parent_set = this;
}

bool remove(SharedBlob *sb) {
std::lock_guard<std::mutex> l(lock);
if (sb->nref == 0) {
assert(sb->parent_set == this);
uset.erase(*sb);
sb_map.erase(sb->sbid);
return true;
}
return false;
}

bool empty() {
std::lock_guard<std::mutex> l(lock);
return uset.empty();
return sb_map.empty();
}
};

Expand Down
1 change: 1 addition & 0 deletions src/test/objectstore/test_bluestore_types.cc
Expand Up @@ -34,6 +34,7 @@ TEST(bluestore, sizeof) {
P(std::atomic_int);
P(BlueStore::SharedBlobRef);
P(boost::intrusive::set_base_hook<>);
P(boost::intrusive::unordered_set_base_hook<>);
P(bufferlist);
cout << "map<uint64_t,uint64_t>\t" << sizeof(map<uint64_t,uint64_t>) << std::endl;
cout << "map<char,char>\t" << sizeof(map<char,char>) << std::endl;
Expand Down