[host_memory] decrease latency of mapping on linux
All checks were successful
eden-license / license-header (pull_request) Successful in 18s
All checks were successful
eden-license / license-header (pull_request) Successful in 18s
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
c36cc0d3ee
commit
dc65e6fc15
1 changed files with 11 additions and 6 deletions
|
@ -606,12 +606,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue