diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-11 22:30:12 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-09-19 12:12:38 -0700 |
commit | 14f6b749f9a5281c1be9ce686d0990be60cec391 (patch) | |
tree | 7b5889a6a2e6b9331314b553a6d8a3a5f73afbad | |
parent | 131124d7ac75273ca04311d56f2d996fcb61c7e8 (diff) | |
download | ceph-14f6b749f9a5281c1be9ce686d0990be60cec391.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.cc | 5 | ||||
-rw-r--r-- | src/rgw/rgw_cache.h | 3 |
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 e4002f6af25..3fc66311f9f 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); |