[commit: ghc] master: fix osReserveHeapMemory block alignment (e175aaf)

git at git.haskell.org git at git.haskell.org
Wed Jul 18 22:39:31 UTC 2018


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

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

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

commit e175aaf6918bb2b497b83618dc4c270a0d231a1c
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date:   Wed Jul 18 23:36:58 2018 +0100

    fix osReserveHeapMemory block alignment
    
    Before the change osReserveHeapMemory() attempted
    to allocate chunks of memory via osTryReserveHeapMemory()
    not multiple of MBLOCK_SIZE in the following fallback code:
    
    ```
        if (at == NULL) {
            *len -= *len / 8;
    ```
    
    and caused assertion failure:
    
    ```
    $ make fulltest TEST=T11607 WAY=threaded1
    T11607: internal error: ASSERTION FAILED: file rts/posix/OSMem.c, line 457
        (GHC version 8.7.20180716 for riscv64_unknown_linux)
    
    ```
    
    The change applies alignment mask before each MBLOCK allocation attempt
    and fixes WAY=threaded1 test failures on qemu-riscv64.
    
    Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
    
    Test Plan: run 'make fulltest WAY=threaded1'
    
    Reviewers: simonmar, bgamari, erikd
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, thomie, carter
    
    Differential Revision: https://phabricator.haskell.org/D4982


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

e175aaf6918bb2b497b83618dc4c270a0d231a1c
 rts/posix/OSMem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index e63e798..4063ad3 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -441,6 +441,8 @@ osTryReserveHeapMemory (W_ len, void *hint)
     void *base, *top;
     void *start, *end;
 
+    ASSERT((len & ~MBLOCK_MASK) == len);
+
     /* 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 */
@@ -517,6 +519,8 @@ void *osReserveHeapMemory(void *startAddressPtr, W_ *len)
 
     attempt = 0;
     while (1) {
+        *len &= ~MBLOCK_MASK;
+
         if (*len < MBLOCK_SIZE) {
             // Give up if the system won't even give us 16 blocks worth of heap
             barf("osReserveHeapMemory: Failed to allocate heap storage");



More information about the ghc-commits mailing list