diff options
| author | Takoroka <137927095+Takoroka@users.noreply.github.com> | 2026-11-01 13:25:46 -0500 |
|---|---|---|
| committer | Takoroka <137927095+Takoroka@users.noreply.github.com> | 2026-11-01 13:25:46 -0500 |
| commit | 9ee8d6f6a6900537eccf67e4c3a9bb16248dc6ab (patch) | |
| tree | 66082e3914f210cfdcb144c67e98a3aa16b5b5b4 /src/common/host_memory.cpp | |
| parent | f695266b80ba1e8a4a4f2f8421d65ed224068c7a (diff) | |
| parent | 86968cb5ce3195cb131eeb0ef68d2d8a4860f7df (diff) | |
Merge remote-tracking branch 'origin/fix/cold-hint-uploaded-memory' into test/linux-all-prs
Diffstat (limited to 'src/common/host_memory.cpp')
| -rw-r--r-- | src/common/host_memory.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 75a9da80e9..2c45dfd3a5 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -790,6 +790,27 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission #endif } +void HostMemory::HintCold(size_t physical_offset, size_t length, + std::optional<size_t> virtual_offset) const { + if (length == 0 || backing_base == nullptr) { + return; + } + const auto hint = [length](u8* address) { +#ifdef _WIN32 + // Unlocking pages that are not locked takes them out of the working set. + VirtualUnlock(address, length); +#elif defined(__linux__) && defined(MADV_PAGEOUT) + madvise(address, length, MADV_PAGEOUT); +#else + static_cast<void>(address); +#endif + }; + hint(backing_base + physical_offset); + if (virtual_offset && virtual_base != nullptr && *virtual_offset + length <= virtual_size) { + hint(virtual_base + *virtual_offset); + } +} + void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) { std::memset(backing_base + physical_offset, fill_value, length); } |
