From: Debian Haskell Group Date: Sat, 17 Dec 2016 02:44:45 +0000 (+0000) Subject: osdecommitmemory-compat X-Git-Tag: archive/raspbian/8.0.2-9+rpi1~1^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ea27ca07e55e4ef76ab7743e3627956298f7bbe5;p=ghc.git osdecommitmemory-compat Gbp-Pq: Name osdecommitmemory-compat.patch --- diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 2a3c294f..0a9690c0 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -506,11 +506,24 @@ void osDecommitMemory(void *at, W_ size) #ifdef MADV_FREE // Try MADV_FREE first, FreeBSD has both and MADV_DONTNEED - // just swaps memory out + // just swaps memory out. Linux >= 4.5 has both DONTNEED and FREE; either + // will work as they both allow the system to free anonymous pages. + // It is important that we try both methods as the kernel which we were + // built on may differ from the kernel we are now running on. r = madvise(at, size, MADV_FREE); -#else - r = madvise(at, size, MADV_DONTNEED); + if(r < 0) { + if (errno == EINVAL) { + // Perhaps the system doesn't support MADV_FREE; fall-through and + // try MADV_DONTNEED. + } else { + sysErrorBelch("unable to decommit memory"); + } + } else { + return; + } #endif + + r = madvise(at, size, MADV_DONTNEED); if(r < 0) sysErrorBelch("unable to decommit memory"); }