Skip to content

Commit

Permalink
fix mrc range issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhao-ye committed Dec 13, 2024
1 parent c797563 commit d85e8a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/gcache/ghost_kv_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class SampledGhostKvCache {
ghost_cache.unsafe_for_each_mru([&](Handle_t h) {
curr_size += h->kv_size;
++curr_count;
if ((curr_count - ghost_cache.min_size) % ghost_cache.tick == 0) {
if (curr_count >= ghost_cache.min_size &&
(curr_count - ghost_cache.min_size) % ghost_cache.tick == 0) {
curve.emplace_back(curr_count << SampleShift, curr_size << SampleShift,
ghost_cache.get_stat_shifted(curr_count));
}
Expand Down
24 changes: 14 additions & 10 deletions tests/test_ghost_kv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>

#include "gcache/ghost_kv_cache.h"
Expand Down Expand Up @@ -68,19 +67,24 @@ void bench1() {
std::cout << '|';
sampled_ghost_kv_cache.get_stat(s).print(std::cout, 8);
std::cout << '|';
auto [count, size, cache_stat] = curve[s / tick - 1];
assert(count == s);
if (cache_stat.hit_cnt == 0) {
std::cout << " NAN";
} else {
std::cout << std::setw(5) << std::fixed << std::setprecision(1)
<< cache_stat.get_hit_rate() * 100 << '%';
auto idx = s / tick - 1;
if (idx < curve.size()) {
auto [count, size, cache_stat] = curve[idx];
assert(count == s);
if (cache_stat.hit_cnt == 0) {
std::cout << " NAN";
} else {
std::cout << std::setw(5) << std::fixed << std::setprecision(1)
<< cache_stat.get_hit_rate() * 100 << '%';
}
std::cout << " @" << std::setw(7) << std::fixed << size / 1024 / 1024
<< 'M' << std::setw(5) << std::fixed << size / count;
}
std::cout << " @" << std::setw(7) << std::fixed << size / 1024 / 1024 << 'M'
<< std::setw(5) << std::fixed << size / count << std::endl;
std::cout << std::endl;
}
std::cout << "=============================================================="
<< "======================\n";
std::cout << std::endl;
}

int main() { bench1(); }

0 comments on commit d85e8a0

Please sign in to comment.