]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: make ErasureCodeIsaTableCache drop entries according to LRU 4114/head
authorAndreas Peters <Andreas.Joachim.Peters@cern.ch>
Fri, 20 Mar 2015 09:21:26 +0000 (10:21 +0100)
committerAndreas Peters <Andreas.Joachim.Peters@cern.ch>
Fri, 20 Mar 2015 09:56:46 +0000 (10:56 +0100)
There was a bug in the arguments used by the splice function to move elements from the LRU list to the head of the list.
To simplify the implementation the direction of the LRU list has been changed e.g. newest entries are pushed in front.

Signed-off-by: Andreas-Joachim Peters <andreas.joachim.peters@cern.ch>
src/erasure-code/isa/ErasureCodeIsaTableCache.cc

index 003ff2224a4b9e51a36a233ef7f15705ea02c66e..fa834ab9f8efeb1667f2a15c8fe43c3c50e143ce 100644 (file)
@@ -260,7 +260,7 @@ ErasureCodeIsaTableCache::getDecodingTableFromCache(std::string &signature,
     memcpy(table, (*decode_tbls_map)[signature].second.c_str(), k * (m + k)*32);
     // find item in LRU queue and push back
     dout(12) << "[ cache size   ] = " << decode_tbls_lru->size() << dendl;
-    decode_tbls_lru->splice((*decode_tbls_map)[signature].first, *decode_tbls_lru, decode_tbls_lru->end());
+    decode_tbls_lru->splice( (decode_tbls_lru->begin()), *decode_tbls_lru, (*decode_tbls_map)[signature].first);
     found = true;
   }
 
@@ -298,26 +298,26 @@ ErasureCodeIsaTableCache::putDecodingTableToCache(std::string &signature,
   if ((int) decode_tbls_lru->size() >= ErasureCodeIsaTableCache::decoding_tables_lru_length) {
     dout(12) << "[ shrink lru   ] = " << signature << dendl;
     // reuse old buffer
-    cachetable = (*decode_tbls_map)[decode_tbls_lru->front()].second;
+    cachetable = (*decode_tbls_map)[decode_tbls_lru->back()].second;
+
     if ((int) cachetable.length() != (k * (m + k)*32)) {
       // we need to replace this with a different size buffer
       cachetable = buffer::create(k * (m + k)*32);
-      (*decode_tbls_map)[signature] = std::make_pair(decode_tbls_lru->begin(), cachetable);
     }
 
     // remove from map
-    decode_tbls_map->erase(decode_tbls_lru->front());
+    decode_tbls_map->erase(decode_tbls_lru->back());
     // remove from lru
-    decode_tbls_lru->pop_front();
+    decode_tbls_lru->pop_back();
+    // add to the head of lru
+    decode_tbls_lru->push_front(signature);
     // add the new to the map
     (*decode_tbls_map)[signature] = std::make_pair(decode_tbls_lru->begin(), cachetable);
-    // add to the end of lru
-    decode_tbls_lru->push_back(signature);
   } else {
     dout(12) << "[ store table  ] = " << signature << dendl;
     // allocate a new buffer
     cachetable = buffer::create(k * (m + k)*32);
-    decode_tbls_lru->push_back(signature);
+    decode_tbls_lru->push_front(signature);
     (*decode_tbls_map)[signature] = std::make_pair(decode_tbls_lru->begin(), cachetable);
     dout(12) << "[ cache size   ] = " << decode_tbls_lru->size() << dendl;
   }