CPUBackend: Enable Transparent Huge Pages on JIT buffers

If/When this works, the amount of iTLB misses drop dramatically, which
reduces L2 TLB pressure, which just improves performance for our CPU
cores that have itty-bitty L1 iTLB entry counts.

We can't use `mmap(MAP_HUGETLB)` directly for terrible reasons, so we
are required to lean on madvise instead.
This commit is contained in:
Ryan Houdek committed 2026-03-06 11:51:17 -08:00
1 parent 9eb639e891
commit bed5f293dc
2 files changed
+8

No files matched your search

@@ -363,6 +363,9 @@ namespace CPU {
FEXCore::Allocator::VirtualName("FEXMemJIT", reinterpret_cast<void*>(Ptr), Size);
// Huge-pages reduce the amount of iTLB misses dramatically when it works.
FEXCore::Allocator::VirtualTHP(reinterpret_cast<void*>(Ptr), Size);
LookupCache = fextl::make_unique<GuestToHostMap>();
}
@@ -83,6 +83,7 @@ inline bool VirtualProtect(void* Ptr, size_t Size, ProtectOptions options) {
}
inline void VirtualName(const char*, void*, size_t) {}
inline void VirtualTHP(void* Ptr, size_t Size) {}
#else
using MMAP_Hook = void* (*)(void*, size_t, int, int, int, off_t);
@@ -123,6 +124,10 @@ inline bool VirtualProtect(void* Ptr, size_t Size, ProtectOptions options) {
return ::mprotect(Ptr, Size, prot) == 0;
}
inline void VirtualTHP(void* Ptr, size_t Size) {
::madvise(Ptr, Size, MADV_HUGEPAGE);
}
#endif
// Memory allocation routines to be defined externally.