diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2018-06-02 21:22:52 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-06-02 23:21:01 -0400 |
commit | 26273774661bd0780b1ae8f0755ea135a0ceaf92 (patch) | |
tree | 18f7ae9018d6b7c13eacdd04513ba65a24562f16 /rts | |
parent | 21e9d4f5f67dca22fbe3495f637347c5a8f7b52c (diff) | |
download | haskell-26273774661bd0780b1ae8f0755ea135a0ceaf92.tar.gz |
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
Diffstat (limited to 'rts')
-rw-r--r-- | rts/posix/OSMem.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 9ae9a4bd36..479ae9dee1 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) { |