From f9f7b282fca0beb3536cfb8bd148c5bc6e3affe3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 23:59:19 +0000 Subject: [PATCH] Preserve frequency hash across remove/add cycles, handle counter wrap-around Co-authored-by: tgrabiec <283695+tgrabiec@users.noreply.github.com> Agent-Logs-Url: https://github.com/scylladb/scylladb/sessions/c799b7fa-d908-448a-9c0c-9cd231864f31 --- utils/lru.hh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/lru.hh b/utils/lru.hh index 28ae854f40..e5e68608be 100644 --- a/utils/lru.hh +++ b/utils/lru.hh @@ -158,7 +158,16 @@ private: } void assign_frequency_hash(evictable& e) noexcept { - e._frequency_hash = ++_next_hash; + // Only assign a new hash if the entry doesn't have one yet. + // Re-added entries (after remove()) keep their existing hash + // to preserve frequency tracking across remove/add cycles. + if (e._frequency_hash == 0) { + // Skip 0 on wrap-around to keep it as the "unassigned" sentinel. + if (++_next_hash == 0) { + ++_next_hash; + } + e._frequency_hash = _next_hash; + } } void record_access(const evictable& e) noexcept {