[commit: ghc] master: rts: Inform kernel that we won't need reserved address space (1d1b991)

git at git.haskell.org git at git.haskell.org
Tue Sep 26 16:00:23 UTC 2017


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/1d1b991ee15e0428be16d1bfad7087051e000bdc/ghc

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

commit 1d1b991ee15e0428be16d1bfad7087051e000bdc
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Tue Sep 26 10:09:06 2017 -0400

    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


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

1d1b991ee15e0428be16d1bfad7087051e000bdc
 rts/posix/OSMem.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 6ccd65a..ee727a5 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



More information about the ghc-commits mailing list