summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-03-01 21:30:31 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-03-01 21:35:12 +0000
commita5b5bbfbff6c434ac16930617d1b77370edb905c (patch)
tree9dd2cbf312ec58d5cd2dae1dd3fcdb406e58928f
parentf02fb193bd59862840fa3946a20923298dac0745 (diff)
downloadhaskell-wip/hugepages.tar.gz
-rw-r--r--configure.ac2
-rw-r--r--rts/posix/OSMem.c12
2 files changed, 10 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index f3b176ad2d..7bbfa274e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -962,7 +962,7 @@ dnl off_t, because it will affect the result of that test.
AC_SYS_LARGEFILE
dnl ** check for specific header (.h) files that we are interested in
-AC_CHECK_HEADERS([ctype.h dirent.h dlfcn.h errno.h fcntl.h grp.h limits.h locale.h nlist.h pthread.h pwd.h signal.h sys/param.h sys/mman.h sys/resource.h sys/select.h sys/time.h sys/timeb.h sys/timerfd.h sys/timers.h sys/times.h sys/utsname.h sys/wait.h termios.h time.h utime.h windows.h winsock.h sched.h])
+AC_CHECK_HEADERS([ctype.h dirent.h dlfcn.h errno.h fcntl.h grp.h limits.h locale.h nlist.h pthread.h pwd.h signal.h sys/param.h sys/mman.h linux/mman.h sys/resource.h sys/select.h sys/time.h sys/timeb.h sys/timerfd.h sys/timers.h sys/times.h sys/utsname.h sys/wait.h termios.h time.h utime.h windows.h winsock.h sched.h])
dnl sys/cpuset.h needs sys/param.h to be included first on FreeBSD 9.1; #7708
AC_CHECK_HEADERS([sys/cpuset.h], [], [],
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 53ea69702d..43bba34365 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -60,10 +60,12 @@
# endif
#endif
+#if defined(HAVE_LINUX_MMAN_H)
+#include <linux/mman.h>
+
#define HUGEPAGE_SIZE (2*1024*1024)
-// This constant is from linux/mman.h
-#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT)
-#define HUGEPAGE_FLAGS MAP_HUGETLB
+#define HUGEPAGE_FLAGS (MAP_HUGETLB | MAP_HUGE_2MB)
+#endif
#if !defined(darwin_HOST_OS)
# undef RESERVE_FLAGS
@@ -242,16 +244,19 @@ my_mmap (void *addr, W_ size, int operation)
# endif
} else if (operation == MEM_COMMIT) {
flags = MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE;
+#if defined(HUGEPAGE_SIZE)
if ( RtsFlags.GcFlags.hugepages &&
(size & (HUGEPAGE_SIZE - 1)) == 0) {
huge_tried += 1;
flags |= HUGEPAGE_FLAGS;
}
+#endif /* defined(HUGEPAGE_SIZE) */
} else {
flags = MAP_ANON | MAP_PRIVATE;
}
ret = mmap(addr, size, prot, flags, -1, 0);
+#if defined(HUGEPAGE_SIZE)
// If the mmap failed, and we tried with HUGEPAGE_FLAGS
// then retry without.
if (ret == MAP_FAILED && flags & HUGEPAGE_FLAGS){
@@ -259,6 +264,7 @@ my_mmap (void *addr, W_ size, int operation)
flags &= ~HUGEPAGE_FLAGS;
ret = mmap(addr, size, prot, flags, -1, 0);
}
+#endif
# if defined(linux_HOST_OS)
if (ret == MAP_FAILED && errno == EPERM) {
// Linux may return EPERM if it tried to give us