Conversation
- Add full LRU-K implementation in LRU_K.cpp - Objects with < K accesses are evicted in FIFO order (infinite backward K-distance) - Objects with >= K accesses are sorted by K-th most recent access time - Default K=2, configurable via "k=N" parameter - Add LRU_K_init declaration to evictionAlgo.h - Register "lru-k" in cache_init.h simple_algos array - Add LRU_K.cpp to CMakeLists.txt build - Update test/common.h to enable LRU_K_init, remove dead code - Add test data and test function in test_evictionAlgo.c - All 28 tests pass including new cacheAlgo_LRU_K test Co-authored-by: 1a1a11a <8584783+1a1a11a@users.noreply.github.com> Agent-Logs-Url: https://github.com/1a1a11a/libCacheSim/sessions/ba5ad55c-e5e5-4bc1-a3d0-a355843709d2
There was a problem hiding this comment.
Pull request overview
Implements the LRU-K eviction policy in libCacheSim and wires it into the build, CLI dispatch, and eviction-algorithm test suite.
Changes:
- Added a full C++ implementation of LRU-K using a FIFO queue for objects with <K accesses and an ordered set for objects with ≥K accesses.
- Registered the new algorithm in the public eviction API header, cachesim algorithm dispatch, and CMake source lists.
- Extended the eviction algorithm tests to construct and validate
LRU_K.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
libCacheSim/cache/eviction/cpp/LRU_K.cpp |
New LRU-K eviction implementation (FIFO + ordered set + per-object access history). |
libCacheSim/include/libCacheSim/evictionAlgo.h |
Exposes LRU_K_init in the public eviction algorithm API. |
libCacheSim/bin/cachesim/cache_init.h |
Registers "lru-k" in the cachesim algorithm dispatch table. |
libCacheSim/cache/CMakeLists.txt |
Adds LRU_K.cpp to the C++ eviction sources list for compilation. |
test/common.h |
Wires LRU_K_init into create_test_cache() for the test harness. |
test/test_evictionAlgo.c |
Adds LRU_K truth data entry and registers a test_LRU_K test case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const char *k_str = strstr(cache_specific_params, "k="); | ||
| if (k_str != nullptr) { | ||
| int k_val = atoi(k_str + 2); | ||
| if (k_val >= 1) { | ||
| lruk->k = k_val; | ||
| } else { | ||
| WARN("LRU_K: invalid k value %d, using default k=2\n", k_val); | ||
| } |
There was a problem hiding this comment.
LRU_K_parse_params() uses atoi() but this file does not include <cstdlib>/<stdlib.h>. In C++ this can fail to compile due to atoi being undeclared (it isn’t provided by headers currently included via abstractRank.hpp). Include the proper header (or switch to std::strtol from <cstdlib> for more robust parsing).
| } else { | ||
| /* Objects with < K accesses go to the FIFO queue */ | ||
| lruk->fifo_queue.push_back(obj); | ||
| lruk->fifo_map[obj] = std::prev(lruk->fifo_queue.end()); | ||
| } |
There was a problem hiding this comment.
LRU_K_insert() uses std::prev(...) but <iterator> is not included. std::prev is declared in <iterator> (not guaranteed to be transitively included by <list>), so this can be a compile failure on some standard libraries/toolchains.
| } | ||
|
|
||
| lruk->history.erase(obj); | ||
| cache_remove_obj_base(cache, obj, true); |
There was a problem hiding this comment.
Should we use cache_evict_obj_base here?
| cache->remove = LRU_K_remove; | ||
|
|
||
| if (ccache_params.consider_obj_metadata) { | ||
| cache->obj_md_size = 8; |
There was a problem hiding this comment.
And for the size of metadata, should we consider the value of K here?
Adds a complete implementation of the LRU-K cache eviction algorithm (O'Neil, O'Neil, Weikum, 1993) — the stub file
eviction/cpp/LRU_K.cppexisted but was empty.Algorithm
LRU-K evicts the object with the largest backward K-distance:
Default
k=2, configurable via parameter string:Changes
eviction/cpp/LRU_K.cpp— Full implementation using two pools:std::listFIFO queue for objects with < K accesses,std::set<pair<int64_t, obj_id_t>>sorted by K-th access vtime for objects with ≥ K accesses. Per-object access history stored instd::unordered_map<cache_obj_t*, std::deque<int64_t>>within the eviction params struct.include/libCacheSim/evictionAlgo.h— AddedLRU_K_initdeclarationbin/cachesim/cache_init.h— Registered"lru-k"in thesimple_algosdispatch tablecache/CMakeLists.txt— AddedLRU_K.cpptoeviction_sources_cpptest/common.h— WiredLRU_K_initintocreate_test_cache; removed dead commented-out stub and pre-existing duplicateLFUbranchtest/test_evictionAlgo.c— AddedLRU_Kentry totest_data_truth[]and registeredtest_LRU_K; shifted subsequent array indices accordingly🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.