[Git][ghc/ghc][wip/hugepages] fixup! rts: Implement support for 2MB hugepages
Teo Camarasu (@teo)
gitlab at gitlab.haskell.org
Mon Aug 5 15:12:02 UTC 2024
Teo Camarasu pushed to branch wip/hugepages at Glasgow Haskell Compiler / GHC
Commits:
4a3fff1b by Teo Camarasu at 2024-08-05T16:11:55+01:00
fixup! rts: Implement support for 2MB hugepages
- - - - -
2 changed files:
- rts/RtsFlags.c
- rts/posix/OSMem.c
Changes:
=====================================
rts/RtsFlags.c
=====================================
@@ -556,8 +556,10 @@ usage_text[] = {
#endif
" -xq The allocation limit given to a thread after it receives",
" an AllocationLimitExceeded exception. (default: 100k)",
+#if defined(HUGEPAGE_FLAGS)
" -xH Try to use hugepages to allocate memory.",
"",
+#endif
#if defined(USE_LARGE_ADDRESS_SPACE)
" -xr The size of virtual memory address space reserved by the",
" two step allocator (default: 1T)",
@@ -1861,7 +1863,11 @@ error = true;
case 'H':
OPTION_UNSAFE;
+#if defined(HUGEPAGE_FLAGS)
RtsFlags.GcFlags.hugepages = true;
+#else
+ errorBelch("Program not compiled with hugepages support.");
+#endif
break;
default:
=====================================
rts/posix/OSMem.c
=====================================
@@ -60,7 +60,6 @@
# endif
#endif
-
#if !defined(darwin_HOST_OS)
# undef RESERVE_FLAGS
# if defined(MAP_GUARD)
@@ -74,8 +73,10 @@
# endif
#endif
+#if defined(HUGEPAGE_FLAGS)
static int huge_tried = 0;
static int huge_failed = 0;
+#endif
static void *next_request = 0;
@@ -239,8 +240,10 @@ my_mmap (void *addr, W_ size, int operation)
} else if (operation == MEM_COMMIT) {
flags = MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE;
#if defined(HUGEPAGE_FLAGS)
- if ( RtsFlags.GcFlags.hugepages &&
- (size & (HUGEPAGE_SIZE - 1)) == 0) {
+ if ( RtsFlags.GcFlags.hugepages ) {
+ // When hugepages are enabled we only free entire hugepages.
+ // This is enforced in `alloc_mega_group`.
+ ASSERT((size & (HUGEPAGE_SIZE - 1)) == 0);
huge_tried += 1;
flags |= HUGEPAGE_FLAGS;
}
@@ -693,7 +696,9 @@ void osDecommitMemory(void *at, W_ size)
sysErrorBelch("unable to make released memory unaccessible");
#endif
if(RtsFlags.GcFlags.hugepages) {
+ // Check that the memory is aligned to a hugepage,
ASSERT( ((HUGEPAGE_SIZE - 1) & (uintptr_t)at) == 0);
+ // and that it is a multiple of the hugepage size.
ASSERT( ((HUGEPAGE_SIZE - 1) & size) == 0);
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a3fff1be01356b69c44175a0b8722101593ccdf
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4a3fff1be01356b69c44175a0b8722101593ccdf
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240805/ecafac3e/attachment-0001.html>
More information about the ghc-commits
mailing list