Merge commit 'cf1b0edf' into f-mac-rel

This commit is contained in:
Niko1221 committed 2026-10-13 09:21:10 +02:00
commit 0aef10aeae
122 files changed
+6885 -401

No files matched your search

+41 -3
View File
@@ -1734,7 +1734,7 @@ bool FileExpertSource::drop_mapping(std::string& why) {
// Linux's page cache has no such lock: only the tests close the GGUF views (STRATA_TEST_UNMAP_GGUF=1), to run the
// unmapped path the Windows file tier takes
const char* t = std::getenv("STRATA_TEST_UNMAP_GGUF");
if (t == nullptr || t[0] == '' || std::atoi(t) == 0 || role_ptr_.empty()) { why = "not Windows"; return false; }
if (t == nullptr || t[0] == '\0' || std::atoi(t) == 0 || role_ptr_.empty()) { why = "not Windows"; return false; }
if (direct_.empty()) { why = "the reads are not unbuffered"; return false; }
if (unmapped_) { why = "already closed"; return true; }
for (Map& m : maps_) {
@@ -3332,8 +3332,21 @@ bool FileExpertSource::soft_commit_exchanges() {
return true;
}
void FileExpertSource::fs_hold_staged(bool hold) {
ForesightSwap* fs = fs_swap_.load(std::memory_order_acquire);
if (fs == nullptr || n_expert_ <= 0) return;
for (const Exchange& x : staged_)
for (const size_t i : {x.in, x.out}) {
const int64_t layer = (int64_t) (i / (size_t) n_expert_);
const int32_t expert = (int32_t) (i % (size_t) n_expert_);
if (hold) fs->hold(layer, expert);
else fs->unhold(layer, expert);
}
}
int64_t FileExpertSource::commit_exchanges() {
int64_t n = 0;
fs_hold_staged(true); // #2134: both experts' bytes move (in's place takes out's bytes, out leaves its buffer)
for (const Exchange& x : staged_)
if (!soft_in_.empty()) soft_in_[x.out] = SIZE_MAX;
for (const Exchange& x : staged_) {
@@ -3356,12 +3369,14 @@ int64_t FileExpertSource::commit_exchanges() {
}
override_[x.out] = nullptr;
}
fs_hold_staged(false);
staged_.clear();
exchanges_ += n;
return n;
}
void FileExpertSource::commit_copies() {
fs_hold_staged(true); // #2134: held until commit_flip has pointed `out` at its new place
if (exchange_storage_.active()) return; // STRATA_EXCHANGE_ROTATE: ownership moves in commit_flip, nothing to copy
for (const Exchange& x : staged_) {
const uint8_t* src = override_.empty() ? nullptr : override_[x.out];
@@ -3374,6 +3389,7 @@ void FileExpertSource::commit_copies() {
int64_t FileExpertSource::commit_flip() {
int64_t n = 0;
fs_hold_staged(true); // (already held by commit_copies; idempotent)
for (const Exchange& x : staged_) {
const uint8_t* src = override_[x.out];
if (exchange_storage_.active()) { // STRATA_EXCHANGE_ROTATE: the same ownership transfer as commit_exchanges
@@ -3392,6 +3408,7 @@ int64_t FileExpertSource::commit_flip() {
++n;
override_[x.out] = nullptr;
}
fs_hold_staged(false);
staged_.clear();
exchanges_ += n;
return n;
@@ -4888,6 +4905,26 @@ bool ForesightSwap::take(int64_t layer, int32_t expert, unsigned long long& ptr)
return true;
}
void ForesightSwap::hold(int64_t layer, int32_t expert) {
if (layer < 0 || layer >= n_layers || expert < 0 || expert >= n_expert) return;
std::lock_guard<std::mutex> smu_lk(smu_);
const size_t key = (size_t) (layer * n_expert + expert);
const int s = where[key];
where[key] = kHeld;
if (s < 0) return;
Slot& sl = slot[(size_t) (layer * slots + s)];
sl.expert = kDropped; // `loading` and `last_ref` stay: a copy in flight and a window that read it are waited for
sl.ready = false;
++dropped;
}
void ForesightSwap::unhold(int64_t layer, int32_t expert) {
if (layer < 0 || layer >= n_layers || expert < 0 || expert >= n_expert) return;
std::lock_guard<std::mutex> smu_lk(smu_);
int16_t& w = where[(size_t) (layer * n_expert + expert)];
if (w == kHeld) w = -1;
}
void ForesightSwap::note_miss(ExpertSource* src, int64_t layer, int32_t expert) {
std::lock_guard<std::mutex> smu_lk(smu_);
request_locked(src, layer, expert, false);
@@ -4902,7 +4939,7 @@ void ForesightSwap::predict(ExpertSource* src, int64_t layer, int32_t expert) {
void ForesightSwap::request_locked(ExpertSource* src, int64_t layer, int32_t expert, bool predicted_copy) {
if (failed.load(std::memory_order_relaxed)) return;
const size_t key = (size_t) (layer * n_expert + expert);
if (where[key] >= 0) return; // already on its way
if (where[key] != -1) return; // already on its way, or held by an exchange (#2134)
const uint64_t now = completed.load(std::memory_order_acquire);
if (admit > 1 && !predicted_copy) {
if (now > miss_at[key] + 4) miss_cnt[key] = 0;
@@ -4927,7 +4964,7 @@ void ForesightSwap::request_locked(ExpertSource* src, int64_t layer, int32_t exp
sl.loading = false;
sl.ready = true;
}
if (sl.expert < 0) { best = s; break; }
if (sl.expert == -1) { best = s; break; } // never used (a dropped slot, kDropped, waits like a used one)
if (sl.last_ref + (uint64_t) depth > now) continue;
if (sl.last_ref < best_ref) { best_ref = sl.last_ref; best = s; }
}
@@ -4959,6 +4996,7 @@ std::string ForesightSwap::report() const {
(unsigned long long) hits, (unsigned long long) copies, (unsigned long long) predicted,
(unsigned long long) pending, (unsigned long long) busy, (unsigned long long) over_budget, verify ? "" : "");
std::string r = buf;
if (dropped > 0) r += ", " + std::to_string(dropped) + " dropped by exchanges";
if (verify) r += ", verified " + std::to_string(verify_ok) + " ok / " + std::to_string(verify_bad) + " BAD";
return r;
}