summaryrefslogtreecommitdiffstats
path: root/src/common/shared_cache.hpp
diff options
context:
space:
mode:
authorNing Yao <zay11022@gmail.com>2015-12-13 06:40:23 +0100
committerNing Yao <zay11022@gmail.com>2015-12-13 16:54:48 +0100
commitc3a383c341719dec7072bd14cbda27e5dc006e46 (patch)
tree56909d8094bc31e09d132e47d116a39b1fe5bf55 /src/common/shared_cache.hpp
parentMerge pull request #6905 from H3C/wip-bugfix-mount1 (diff)
downloadceph-c3a383c341719dec7072bd14cbda27e5dc006e46.tar.xz
ceph-c3a383c341719dec7072bd14cbda27e5dc006e46.zip
common: improve cache, replace to unordered map with initializing hash bucket size
Based on the PR https://github.com/ceph/ceph/pull/4441 Signed-off-by: Ning Yao <zay11022@gmail.com>
Diffstat (limited to 'src/common/shared_cache.hpp')
-rw-r--r--src/common/shared_cache.hpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp
index c55119c02b7..bba61a3336c 100644
--- a/src/common/shared_cache.hpp
+++ b/src/common/shared_cache.hpp
@@ -21,8 +21,9 @@
#include <utility>
#include "common/Mutex.h"
#include "common/Cond.h"
+#include "include/unordered_map.h"
-template <class K, class V, class C = std::less<K> >
+template <class K, class V, class C = std::less<K>, class H = std::hash<K> >
class SharedLRU {
CephContext *cct;
typedef ceph::shared_ptr<V> VPtr;
@@ -34,7 +35,7 @@ class SharedLRU {
public:
int waiting;
private:
- map<K, typename list<pair<K, VPtr> >::iterator, C> contents;
+ ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H> contents;
list<pair<K, VPtr> > lru;
map<K, pair<WeakVPtr, V*>, C> weak_refs;
@@ -47,7 +48,7 @@ private:
}
void lru_remove(const K& key) {
- typename map<K, typename list<pair<K, VPtr> >::iterator, C>::iterator i =
+ typename ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H>::iterator i =
contents.find(key);
if (i == contents.end())
return;
@@ -57,7 +58,7 @@ private:
}
void lru_add(const K& key, const VPtr& val, list<VPtr> *to_release) {
- typename map<K, typename list<pair<K, VPtr> >::iterator, C>::iterator i =
+ typename ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H>::iterator i =
contents.find(key);
if (i != contents.end()) {
lru.splice(lru.begin(), lru, i->second);
@@ -92,7 +93,9 @@ private:
public:
SharedLRU(CephContext *cct = NULL, size_t max_size = 20)
: cct(cct), lock("SharedLRU::lock"), max_size(max_size),
- size(0), waiting(0) {}
+ size(0), waiting(0) {
+ contents.rehash(max_size);
+ }
~SharedLRU() {
contents.clear();