use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::thread;
use super::Shared;
pub(super) fn run(shared: &Arc<Shared>) {
loop {
if shared.eviction_stop.load(Ordering::Acquire) {
break;
}
thread::park_timeout(shared.cfg.eviction_interval);
if shared.eviction_stop.load(Ordering::Acquire) {
break;
}
let evicted = run_scan(shared);
shared.evictions.fetch_add(evicted, Ordering::Relaxed);
#[cfg(feature = "tracing")]
if evicted > 0 {
tracing::debug!(
target: "holt::checkpoint::eviction",
evicted = evicted,
"eviction scan complete",
);
}
}
}
fn run_scan(shared: &Arc<Shared>) -> u64 {
let now = shared.bm.clock_tick();
let threshold = shared.cfg.eviction_idle_ticks;
let snapshot = shared.bm.snapshot_entries();
let mut evicted = 0u64;
for (guid, entry) in snapshot {
let last = entry.last_touched();
if now.saturating_sub(last) < threshold {
continue;
}
drop(entry);
if shared.bm.try_evict_cold(guid) {
evicted += 1;
}
}
evicted
}