[commit: ghc] master: rts: Query system rlimit for maximum address-space size (2627377)

git at git.haskell.org git at git.haskell.org
Sun Jun 3 03:22:20 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/26273774661bd0780b1ae8f0755ea135a0ceaf92/ghc

>---------------------------------------------------------------

commit 26273774661bd0780b1ae8f0755ea135a0ceaf92
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Jun 2 21:22:52 2018 -0400

    rts: Query system rlimit for maximum address-space size
    
    When we attempt to reserve the heap, we query the system's rlimit to
    establish the starting point for our search over sizes.
    
    Test Plan: Validate
    
    Reviewers: erikd, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #14492
    
    Differential Revision: https://phabricator.haskell.org/D4754


>---------------------------------------------------------------

26273774661bd0780b1ae8f0755ea135a0ceaf92
 rts/posix/OSMem.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 9ae9a4b..479ae9d 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -36,6 +36,10 @@
 #if defined(HAVE_NUMAIF_H)
 #include <numaif.h>
 #endif
+#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SYS_TIME_H)
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
 
 #include <errno.h>
 
@@ -502,6 +506,13 @@ void *osReserveHeapMemory(void *startAddressPtr, W_ *len)
             (void*)startAddress, (void*)minimumAddress);
     }
 
+#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SYS_TIME_H)
+    struct rlimit limit;
+    if (!getrlimit(RLIMIT_AS, &limit) && *len > limit.rlim_cur) {
+        *len = limit.rlim_cur;
+    }
+#endif
+
     attempt = 0;
     while (1) {
         if (*len < MBLOCK_SIZE) {



More information about the ghc-commits mailing list