Skip to content

Commit 5bf890e

Browse files
authored
[Fix] TwoQ crashes when the LRU cache is empty (#295)
* [Fix] pkgconf should be installed explicitly on macos * [Fix] TwoQ crashes when the LRU cache is empty When `TwoQ_evict` is called while Ain is within the size limit, the function will try to do eviction on Am. But when Am is empty, an assertion failure will be encountered. This commit fix the issue by checking whether the Am is able to evict elements.
1 parent 938827d commit 5bf890e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

libCacheSim/cache/eviction/TwoQ.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,19 @@ static void TwoQ_evict(cache_t *cache, const request_t *req) {
259259
cache_t *Aout = params->Aout;
260260
cache_t *Am = params->Am;
261261

262-
if (Ain->get_occupied_byte(Ain) > params->Ain_cache_size) {
262+
if (Am->get_occupied_byte(Am) > 0 &&
263+
Ain->get_occupied_byte(Ain) <= params->Ain_cache_size) {
264+
// evict from Am
265+
Am->evict(Am, req);
266+
} else {
263267
// evict from Ain cache
264268
cache_obj_t *obj = Ain->to_evict(Ain, req);
265269
assert(obj != NULL);
266270
// need to copy the object before it is evicted
267271
copy_cache_obj_to_request(params->req_local, obj);
268272
Aout->get(Aout, params->req_local);
269273
Ain->evict(Ain, req);
270-
return;
271274
}
272-
273-
// evict from Am
274-
Am->evict(Am, req);
275275
}
276276

277277
/**

scripts/install_dependency.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ setup_macOS() {
124124
log_error "Homebrew is not installed. Please install Homebrew first."
125125
exit 1
126126
fi
127-
brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm
127+
brew install glib google-perftools argp-standalone xxhash llvm wget cmake ninja zstd xgboost lightgbm pkgconf
128128
}
129129

130130
# Install CMake

0 commit comments

Comments
 (0)