libhfuzz/instrument: try to use THP for mappings
@@ -89,27 +89,16 @@ static void initializeLibcFunctions(void) {
}
static void* initialzeTryMapHugeTLB(int fd, size_t sz) {
- int mflags = 0;
-
-#if defined(_HF_ARCH_LINUX)
- /*
- * Try to map the local structure using HugeTLB. It'll be way fatser later to clean it with
- * { ftruncate(fd, 0); ftruncate(fd, size); }
- */
- mflags = files_getTmpMapFlags(MAP_SHARED | MAP_HUGE_2MB, /* nocore= */ true);
+ int mflags = files_getTmpMapFlags(MAP_SHARED, /* nocore= */ true);
void* ret = mmap(NULL, sz, PROT_READ | PROT_WRITE, mflags, fd, 0);
-#if defined(__x86_64__) || defined(__i386__)
- if (ret == MAP_FAILED) {
- PLOG_W("mmap(sz=%zu fd=%d flags=MAP_SHARED|MAP_HUGE_2MB) failed", sz, fd);
- }
-#endif /* defined(__x86_64__) || defined(__i386__) */
- if (ret != MAP_FAILED) {
- return ret;
+
+#if defined(MADV_HUGEPAGE)
+ if (madvise(ret, sz, MADV_HUGEPAGE) == -1) {
+ PLOG_W("madvise(addr=%p, sz=%zu, MADV_HUGEPAGE) failed", ret, sz);
}
-#endif /* defined(_HF_ARCH_LINUX) */
+#endif /* defined(MADV_HUGEPAGE) */
- mflags = files_getTmpMapFlags(MAP_SHARED, /* nocore= */ true);
- return mmap(NULL, sz, PROT_READ | PROT_WRITE, mflags, fd, 0);
+ return ret;
}
static void initializeCmpFeedback(void) {
