From 0c7eb37d1b4abd3bcbec9df2bbedbd4c68adf734 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 7 Oct 2026 16:35:32 +0400 Subject: [PATCH] Foresight swap: slots copied in but never used again become reusable once landed (they leaked as 'loading') --- src/core/expert_source.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cpp index 1f7f6651..04fa1cec 100644 --- a/src/core/expert_source.cpp +++ b/src/core/expert_source.cpp @@ -4181,7 +4181,13 @@ void ForesightSwap::note_miss(ExpertSource* src, int64_t layer, int32_t expert) uint64_t best_ref = ~0ull; for (int s = 0; s < slots; ++s) { // an empty slot, else the one used longest ago that no window can still read Slot& sl = slot[(size_t) (layer * slots + s)]; - if (sl.loading) continue; + if (sl.loading) { // copied in but never asked for since: landed long ago -> an ordinary candidate + if (sl.last_ref + (uint64_t) depth > now || !sl.issued.load(std::memory_order_acquire)) continue; + const cudaError_t q = cudaEventQuery((cudaEvent_t) sl.ev); + if (q != cudaSuccess) { if (q != cudaErrorNotReady) cudaGetLastError(); continue; } + sl.loading = false; + sl.ready = true; + } if (sl.expert < 0) { best = s; break; } if (sl.last_ref + (uint64_t) depth > now) continue; if (sl.last_ref < best_ref) { best_ref = sl.last_ref; best = s; }