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-19 12:13:09 -0700
commitbe2907ef85a31c2be8be7446fe71f5d2e1410ec0 (patch)
treec3ad1646a26f996abf6b400b25f34ae76462e566
parentbbfbb097e2f9efbf4f7ec997c70befa20c79d27c (diff)
downloadceph-be2907ef85a31c2be8be7446fe71f5d2e1410ec0.tar.gz
rgw: don't call list::size() in ObjectCache
Fixes: #6286 Use an external counter instead of calling list::size() Reviewed-by: Sage Weil <sage@inktank.com> Signed-off-by: Yehuda Sadeh <yehuda@inktank.com> (cherry picked from commit 31e3a51e933429d286104fe077e98ea883437ad6)
-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 97a5e47d0f7..84f1f135263 100644
--- a/src/rgw/rgw_cache.cc
+++ b/src/rgw/rgw_cache.cc
@@ -104,7 +104,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) {
/*
@@ -118,10 +118,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 {
@@ -139,6 +141,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 4de16384f1a..e5f62b1f860 100644
--- a/src/rgw/rgw_cache.h
+++ b/src/rgw/rgw_cache.h
@@ -126,13 +126,14 @@ struct ObjectCacheEntry {
class ObjectCache {
std::map<string, ObjectCacheEntry> cache_map;
std::list<string> lru;
+ unsigned long 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);