summaryrefslogtreecommitdiff
path: root/rts/posix/OSMem.c
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2015-10-30 20:48:53 +0100
committerBen Gamari <ben@smart-cactus.org>2015-10-30 23:35:50 +0100
commitf5974c88451783d4c1fb69444b10d7053be142bf (patch)
treeebe7ad0175ff6e848241f8f4b45150431b32bfbb /rts/posix/OSMem.c
parent39b71e81ec1044518f065d0055676d713521e483 (diff)
downloadhaskell-f5974c88451783d4c1fb69444b10d7053be142bf.tar.gz
rts: Make MBLOCK_SPACE_SIZE dynamic
Previously this was introduced in D524 as a compile-time constant. Sadly, this isn't flexible enough to allow for environments where ulimits restrict the maximum address space size (see, for instance, Consequently, we are forced to make this dynamic. In principle this shouldn't be so terrible as we can place both the beginning and end addresses within the same cache line, likely incurring only one or so additional instruction in HEAP_ALLOCED. Test Plan: validate Reviewers: austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1353 GHC Trac Issues: #10877
Diffstat (limited to 'rts/posix/OSMem.c')
-rw-r--r--rts/posix/OSMem.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index aa3f3a132a..43c7831a37 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -377,22 +377,22 @@ void setExecutable (void *p, W_ len, rtsBool exec)
#ifdef USE_LARGE_ADDRESS_SPACE
static void *
-osTryReserveHeapMemory (void *hint)
+osTryReserveHeapMemory (W_ len, void *hint)
{
void *base, *top;
void *start, *end;
- /* We try to allocate MBLOCK_SPACE_SIZE + MBLOCK_SIZE,
+ /* We try to allocate len + MBLOCK_SIZE,
because we need memory which is MBLOCK_SIZE aligned,
and then we discard what we don't need */
- base = my_mmap(hint, MBLOCK_SPACE_SIZE + MBLOCK_SIZE, MEM_RESERVE);
- top = (void*)((W_)base + MBLOCK_SPACE_SIZE + MBLOCK_SIZE);
+ base = my_mmap(hint, len + MBLOCK_SIZE, MEM_RESERVE);
+ top = (void*)((W_)base + len + MBLOCK_SIZE);
if (((W_)base & MBLOCK_MASK) != 0) {
start = MBLOCK_ROUND_UP(base);
end = MBLOCK_ROUND_DOWN(top);
- ASSERT(((W_)end - (W_)start) == MBLOCK_SPACE_SIZE);
+ ASSERT(((W_)end - (W_)start) == len);
if (munmap(base, (W_)start-(W_)base) < 0) {
sysErrorBelch("unable to release slop before heap");
@@ -407,7 +407,7 @@ osTryReserveHeapMemory (void *hint)
return start;
}
-void *osReserveHeapMemory(void)
+void *osReserveHeapMemory(W_ len)
{
int attempt;
void *at;
@@ -425,8 +425,8 @@ void *osReserveHeapMemory(void)
attempt = 0;
do {
- at = osTryReserveHeapMemory((void*)((W_)8 * (1 << 30) +
- attempt * BLOCK_SIZE));
+ void *hint = (void*)((W_)8 * (1 << 30) + attempt * BLOCK_SIZE);
+ at = osTryReserveHeapMemory(len, hint);
} while ((W_)at < ((W_)8 * (1 << 30)));
return at;
@@ -467,7 +467,8 @@ void osReleaseHeapMemory(void)
{
int r;
- r = munmap((void*)mblock_address_space_begin, MBLOCK_SPACE_SIZE);
+ r = munmap((void*)mblock_address_space.begin,
+ mblock_address_space.end - mblock_address_space.begin);
if(r < 0)
sysErrorBelch("unable to release address space");
}