From: Andreas Peters Date: Fri, 20 Mar 2015 09:21:26 +0000 (+0100) Subject: erasure-code: make ErasureCodeIsaTableCache drop entries according to LRU X-Git-Tag: v9.0.0~135^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F4114%2Fhead;p=ceph.git erasure-code: make ErasureCodeIsaTableCache drop entries according to LRU 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 --- diff --git a/src/erasure-code/isa/ErasureCodeIsaTableCache.cc b/src/erasure-code/isa/ErasureCodeIsaTableCache.cc index 003ff2224a4..fa834ab9f8e 100644 --- a/src/erasure-code/isa/ErasureCodeIsaTableCache.cc +++ b/src/erasure-code/isa/ErasureCodeIsaTableCache.cc @@ -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; }