[host_memory] decrease latency of mapping on linux (#232)
Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: #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>
This commit is contained in:
parent
dac2efc4c8
commit
cda6958111
1 changed files with 11 additions and 6 deletions
|
@ -598,12 +598,17 @@ public:
|
||||||
|
|
||||||
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
// Set MADV_REMOVE on backing map to destroy it instantly.
|
// Only incur syscall cost IF memset would be slower (theshold = 16MiB)
|
||||||
// This also deletes the area from the backing file.
|
// TODO(lizzie): Smarter way to dynamically get this threshold (broadwell != raptor lake) for example
|
||||||
int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
|
if (length >= 2097152UL * 8) {
|
||||||
ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
|
// Set MADV_REMOVE on backing map to destroy it instantly.
|
||||||
|
// This also deletes the area from the backing file.
|
||||||
return true;
|
int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
|
||||||
|
ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue