[Git][ghc/ghc][master] rts: Allow ExecPage to allocate anywhere in address space

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Nov 27 16:42:34 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
a104508d by Ben Gamari at 2024-11-27T11:42:03-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/a104508d2ea5bbc61c4a756dca42fc043b329709

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a104508d2ea5bbc61c4a756dca42fc043b329709
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/20241127/d181afd5/attachment-0001.html>


More information about the ghc-commits mailing list