]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: don't call list::size() in ObjectCache
authorYehuda Sadeh <yehuda@inktank.com>
Thu, 12 Sep 2013 05:30:12 +0000 (22:30 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Thu, 12 Sep 2013 05:51:32 +0000 (22:51 -0700)
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>
src/rgw/rgw_cache.cc
src/rgw/rgw_cache.h

index 5b96eb45b0886bc63e689d7fbde39ef165e8be23..d0afdcd389cd3e9b61243e02a4924b9773dc3701 100644 (file)
@@ -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();
 }
 
index 601fcdfc9632757aa6bf4f0ac7ede044dd0eaafe..68720d0e6ac35ef8175d06892046f00fe9a5df79 100644 (file)
@@ -131,13 +131,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);