From 99992383964182f12fed2d9dea125186a3c28c10 Mon Sep 17 00:00:00 2001 From: Andreas Peters Date: Fri, 20 Mar 2015 10:21:26 +0100 Subject: [PATCH] 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 --- src/erasure-code/isa/ErasureCodeIsaTableCache.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/erasure-code/isa/ErasureCodeIsaTableCache.cc b/src/erasure-code/isa/ErasureCodeIsaTableCache.cc index 003ff2224a4b..fa834ab9f8ef 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; } -- 2.47.3