[Git][ghc/ghc][wip/T15503] rts: Allow ExecPage to allocate anywhere in address space
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Tue Nov 19 19:07:54 UTC 2024
Ben Gamari pushed to branch wip/T15503 at Glasgow Haskell Compiler / GHC
Commits:
81861b88 by Ben Gamari at 2024-11-19T14:07:46-05:00
rts: Allow ExecPage to allocate anywhere in address space
Currently the ExecPage facility has two users:
* GHCi, for constructing info tables, and
* the adjustor allocation path
Despite neither of these have any spatial locality constraints ExecPage
was using the linker's `mmapAnonForLinker`, which tries hard to ensure
that mappings end up nearby the executable image. This makes adjustor
allocation needlessly subject to fragmentation concerns.
We now instead return less constrained mappings, improving the
robustness of the mechanism.
Addresses #25503.
- - - - -
3 changed files:
- rts/ExecPage.c
- rts/linker/MMap.c
- rts/linker/MMap.h
Changes:
=====================================
rts/ExecPage.c
=====================================
@@ -10,7 +10,7 @@
#include "linker/MMap.h"
ExecPage *allocateExecPage(void) {
- ExecPage *page = (ExecPage *) mmapAnonForLinker(getPageSize());
+ ExecPage *page = (ExecPage *) mmapAnon(getPageSize());
return page;
}
=====================================
rts/linker/MMap.c
=====================================
@@ -207,6 +207,12 @@ memoryAccessToProt(MemoryAccess access)
}
}
+void *
+mmapAnon (size_t bytes)
+{
+ return VirtualAlloc(NULL, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+}
+
//
// Returns NULL on failure.
//
@@ -410,6 +416,15 @@ mmapForLinker (size_t bytes, MemoryAccess access, uint32_t flags, int fd, int of
return result;
}
+/*
+ * Map read/write pages anywhere in memory. Returns NULL on failure.
+ */
+void *
+mmapAnon (size_t bytes)
+{
+ return mmapAnywhere(bytes, MEM_READ_WRITE_THEN_READ_EXECUTE, MAP_ANONYMOUS, -1, 0);
+}
+
/*
* Map read/write pages in low memory. Returns NULL on failure.
*/
=====================================
rts/linker/MMap.h
=====================================
@@ -64,7 +64,11 @@ typedef enum {
extern void *mmap_32bit_base;
-// Map read/write anonymous memory.
+// Map read/write anonymous memory anywhere in memory.
+void *mmapAnon(size_t bytes);
+
+// Map read/write anonymous memory, enforcing the constraint of
+// placing the mapping within 4GB of the executable image.
void *mmapAnonForLinker (size_t bytes);
// Change protection of previous mapping memory.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/81861b88ad635521e91b55d54106b4ccdd494b15
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/81861b88ad635521e91b55d54106b4ccdd494b15
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/20241119/9cdaeff7/attachment-0001.html>
More information about the ghc-commits
mailing list