summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-09-11 22:30:12 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-09-11 22:30:12 -0700
commit10aa054a5162fb703db1f6ef745c74dc819da700 (patch)
tree5acee43612ad240c39c36bbd654e9ec49e41a7df
parent670db7e80ddc9c26c43a4f66907a5996ce207c4d (diff)
downloadceph-10aa054a5162fb703db1f6ef745c74dc819da700.tar.gz
rgw: don't call list::size() in ObjectCachewip-6286
Fixes: #6286 Use an external counter instead of calling list::size() Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/rgw/rgw_cache.cc5
-rw-r--r--src/rgw/rgw_cache.h3
2 files changed, 6 insertions, 2 deletions
diff --git a/src/rgw/rgw_cache.cc b/src/rgw/rgw_cache.cc
index 5b96eb45b08..d0afdcd389c 100644
--- a/src/rgw/rgw_cache.cc
+++ b/src/rgw/rgw_cache.cc
@@ -107,7 +107,7 @@ void ObjectCache::remove(string& name)
void ObjectCache::touch_lru(string& name, std::list<string>::iterator& lru_iter)
{
- while (lru.size() > (size_t)cct->_conf->rgw_cache_lru_size) {
+ while (lru_size > (size_t)cct->_conf->rgw_cache_lru_size) {
list<string>::iterator iter = lru.begin();
if ((*iter).compare(name) == 0) {
/*
@@ -121,10 +121,12 @@ void ObjectCache::touch_lru(string& name, std::list<string>::iterator& lru_iter)
if (map_iter != cache_map.end())
cache_map.erase(map_iter);
lru.pop_front();
+ lru_size--;
}
if (lru_iter == lru.end()) {
lru.push_back(name);
+ lru_size++;
lru_iter--;
ldout(cct, 10) << "adding " << name << " to cache LRU end" << dendl;
} else {
@@ -142,6 +144,7 @@ void ObjectCache::remove_lru(string& name, std::list<string>::iterator& lru_iter
return;
lru.erase(lru_iter);
+ lru_size--;
lru_iter = lru.end();
}
diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h
index 601fcdfc963..3f17883f215 100644
--- a/src/rgw/rgw_cache.h
+++ b/src/rgw/rgw_cache.h
@@ -131,13 +131,14 @@ struct ObjectCacheEntry {
class ObjectCache {
std::map<string, ObjectCacheEntry> cache_map;
std::list<string> lru;
+ uint32_t lru_size;
Mutex lock;
CephContext *cct;
void touch_lru(string& name, std::list<string>::iterator& lru_iter);
void remove_lru(string& name, std::list<string>::iterator& lru_iter);
public:
- ObjectCache() : lock("ObjectCache"), cct(NULL) { }
+ ObjectCache() : lru_size(0), lock("ObjectCache"), cct(NULL) { }
int get(std::string& name, ObjectCacheInfo& bl, uint32_t mask);
void put(std::string& name, ObjectCacheInfo& bl);
void remove(std::string& name);