summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-09-26 10:09:06 -0400
committerBen Gamari <ben@smart-cactus.org>2017-09-26 11:59:53 -0400
commit1d1b991ee15e0428be16d1bfad7087051e000bdc (patch)
treea93d8d4852e611666953a09beb5745e4f302710b
parent62464071455ea0472903ef1d94833e5eefb8f74e (diff)
downloadhaskell-1d1b991ee15e0428be16d1bfad7087051e000bdc.tar.gz
rts: Inform kernel that we won't need reserved address space
Trac #14192 points out that currently GHC's two-step allocator results in extremely large coredumps. It seems like WebKit may have encountered similar issues and their apparent solution uses madvise(MADV_DONTNEED) while reserving address space to inform the kernel that the address space we just requested needs no backing. Perhaps this is used by the core dump logic to trim out uncommitted pages. Test Plan: Validate, try core-dumping a compiled executable Reviewers: austin, erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie GHC Trac Issues: #14192, #14193 Differential Revision: https://phabricator.haskell.org/D3929
-rw-r--r--rts/posix/OSMem.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 6ccd65ab16..ee727a56c4 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -191,6 +191,19 @@ my_mmap (void *addr, W_ size, int operation)
errno = ENOMEM;
}
}
+
+ if (operation & MEM_COMMIT) {
+ madvise(ret, size, MADV_WILLNEED);
+#if defined(MADV_DODUMP)
+ madvise(ret, size, MADV_DODUMP);
+#endif
+ } else {
+ madvise(ret, size, MADV_DONTNEED);
+#if defined(MADV_DONTDUMP)
+ madvise(ret, size, MADV_DONTDUMP);
+#endif
+ }
+
#else
ret = mmap(addr, size, prot, flags | MAP_ANON | MAP_PRIVATE, -1, 0);
#endif