| 2303 | } |
| 2304 | |
| 2305 | int64_t FileExpertSource::commit_exchanges() { |
| 2306 | int64_t n = 0; |
| 2307 | for (const Exchange& x : staged_) { |
| 2308 | const uint8_t* src = override_[x.out]; |
| 2309 | if (exchange_storage_.active()) { |
| 2310 | if (!exchange_storage_.commit(x.in, x.out, (size_t)x.q, src, (size_t)x.bytes)) { |
| 2311 | // Admitting the GPU swap after a failed RAM ownership update would lose an expert. |
| 2312 | std::fprintf(stderr, "FileExpertSource: invalid exchange rotation commit; refusing corrupt residency\n"); |
| 2313 | std::abort(); |
| 2314 | } |
| 2315 | ++n; |
| 2316 | override_[x.out] = nullptr; |
| 2317 | continue; |
| 2318 | } |
| 2319 | const uint64_t at = complement_offsets_[x.in]; |
| 2320 | if (src != nullptr && at != kNoComplement && at <= complement_bytes_ && x.bytes <= complement_bytes_ - at && |
| 2321 | complement_host_ != nullptr) { |
| 2322 | std::memcpy((uint8_t*) complement_host_ + (size_t) at, src, (size_t) x.bytes); |
| 2323 | if (detail::exchange_cache_complement(complement_offsets_, x.in, x.out)) ++n; |
| 2324 | } |
| 2325 | override_[x.out] = nullptr; |
| 2326 | } |
| 2327 | staged_.clear(); |
| 2328 | exchanges_ += n; |
| 2329 | return n; |
| 2330 | } |
| 2331 | |
| 2332 | void FileExpertSource::commit_copies() { |
| 2333 | if (exchange_storage_.active()) return; // STRATA_EXCHANGE_ROTATE: ownership moves in commit_flip, nothing to copy |