Foresight swap: an exchange holds the experts whose bytes it moves, so no slot is served with another expert's bytes (#2134)

With STRATA_FS_SLOTS > 0 and the resident RAM mode's adaptive exchanges, a slot copy issued
from an expert's RAM place (note_miss / the router look-ahead's predict) could land after an
exchange rewrote that place with the outgoing expert's bytes; take() then served expert Y's
bytes for expert X (FS_VERIFY: 19 BAD on clean v0.1.43, reported in #2134).

commit_exchanges, commit_copies and commit_flip now hold every staged expert (in and out) in
the swap space while their bytes move: its slot is dropped (never served again) and no copy
of it is issued until the commit is done (commit_copies holds until commit_flip, so the
asynchronous tier's half-done exchange is covered, and the rotation path too). Unlike the
patch in the issue, a dropped slot is not handed out at once: it waits the same `depth`
finished windows as any slot a window may still read, since a window planned before the
exchange can be reading it. "N dropped by exchanges" joins the swap space's report.

Foresight is opt-in; with STRATA_FS_SLOTS unset nothing here runs. Test:
file_expert_source_test --rotation-gpu (both commit paths, the depth rule, the bytes after).
Based on the analysis and patch in #2134.

Co-authored-by: radoslawsz <49882412+radoslawsz@users.noreply.github.com>
This commit is contained in:
Niko1221andradoslawsz committed 2026-10-13 00:31:31 +02:00
1 parent 6339e8610d
commit 277be72a7f
5 files changed
+156 -5

No files matched your search

+6 -3
View File
@@ -8326,12 +8326,15 @@ int main(int argc, char** argv) {
fs_swap.reset(strata::core::foresight_swap_from_env(g.n_layers, g.n_expert, card, devs));
drive.d.fs = fs_swap.get();
if (fs_swap && drive.d.lookahead != nullptr) lookahead.set_foresight(fs_swap.get());
src.set_foresight_swap(fs_swap.get()); // #2134: the exchanges hold the experts whose bytes they move
}
// the look-ahead thread must not touch the swap space once it is gone (declared after it: destroyed first)
// the look-ahead thread and the exchanges must not touch the swap space once it is gone (declared after it:
// destroyed first)
struct FsDetach {
strata::core::RouterLookahead* la;
~FsDetach() { la->set_foresight(nullptr); }
} fs_detach{&lookahead};
strata::core::FileExpertSource* src;
~FsDetach() { la->set_foresight(nullptr); src->set_foresight_swap(nullptr); }
} fs_detach{&lookahead, &src};
drive.d.pcie_num = std::max(0, std::min(256, (int) (o.pcie_frac * 256.0 + 0.5)));
const bool all_experts_resident = !host_res.empty() &&
std::all_of(host_res.begin(), host_res.end(), [](int32_t r) { return r >= 0; });