| 4973 | } |
| 4974 | |
| 4975 | int64_t FileExpertSource::commit_exchanges() { |
| 4976 | int64_t n = 0; |
| 4977 | fs_hold_staged(true); // #2134: both experts' bytes move (in's place takes out's bytes, out leaves its buffer) |
| 4978 | for (const Exchange& x : staged_) |
| 4979 | if (!soft_in_.empty()) soft_in_[x.out] = SIZE_MAX; |
| 4980 | for (const Exchange& x : staged_) { |
| 4981 | const uint8_t* src = override_[x.out]; |
| 4982 | if (exchange_storage_.active()) { |
| 4983 | if (!exchange_storage_.commit(x.in, x.out, (size_t)x.q, src, (size_t)x.bytes)) { |
| 4984 | // Admitting the GPU swap after a failed RAM ownership update would lose an expert. |
| 4985 | std::fprintf(stderr, "FileExpertSource: invalid exchange rotation commit; refusing corrupt residency\n"); |
| 4986 | std::abort(); |
| 4987 | } |
| 4988 | ++n; |
| 4989 | override_[x.out] = nullptr; |
| 4990 | continue; |
| 4991 | } |
| 4992 | const uint64_t at = complement_offsets_[x.in]; |
| 4993 | if (src != nullptr && at != kNoComplement && at <= complement_bytes_ && x.bytes <= complement_bytes_ - at && |
| 4994 | complement_host_ != nullptr) { |
| 4995 | std::memcpy((uint8_t*) complement_host_ + (size_t) at, src, (size_t) x.bytes); |
| 4996 | if (detail::exchange_cache_complement(complement_offsets_, x.in, x.out)) ++n; |
| 4997 | } |
| 4998 | override_[x.out] = nullptr; |
| 4999 | } |
| 5000 | fs_hold_staged(false); |
| 5001 | staged_.clear(); |
| 5002 | exchanges_ += n; |
| 5003 | return n; |
| 5004 | } |
| 5005 | |
| 5006 | bool FileExpertSource::replace_resident(int64_t layer, int64_t in, int64_t out) { |
| 5007 | if (!complement_ready_ || complement_host_ == nullptr || exchange_storage_.active() || !staged_.empty() || |