aboutsummaryrefslogtreecommitdiff
path: root/src/common/host_memory.cpp
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2025-09-17 02:31:44 +0200
committercrueter <crueter@eden-emu.dev>2025-09-17 02:31:44 +0200
commitcda69581119c967362c0170f094c66358b0b7925 (patch)
tree347cd7767f8ae9c770f7938b3b0c3e5561c7a864 /src/common/host_memory.cpp
parentdac2efc4c83b3db7d57f66b6bf18cfa86d2d12fe (diff)
[host_memory] decrease latency of mapping on linux (#232)
Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/232 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/common/host_memory.cpp')
-rw-r--r--src/common/host_memory.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index 1b7532b6b9..2e36d59569 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -598,12 +598,17 @@ public:
bool ClearBackingRegion(size_t physical_offset, size_t length) {
#ifdef __linux__
- // Set MADV_REMOVE on backing map to destroy it instantly.
- // This also deletes the area from the backing file.
- int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
- ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
-
- return true;
+ // Only incur syscall cost IF memset would be slower (theshold = 16MiB)
+ // TODO(lizzie): Smarter way to dynamically get this threshold (broadwell != raptor lake) for example
+ if (length >= 2097152UL * 8) {
+ // Set MADV_REMOVE on backing map to destroy it instantly.
+ // This also deletes the area from the backing file.
+ int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
+ ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
+ return true;
+ } else {
+ return false;
+ }
#else
return false;
#endif