ghc runtime by default (otherwise depending on a "configure" option)
does memory allocation on their own by first mmapping a 1 TB range of
memory into the process and then parceling out chunks from it.
If one of the chunks is not needed, the kernel needs to be informed -
otherwise the system would quickly run out of available RAM.
ghc does that via madvise(2).
There are two options when doing this informing:
MADV_FREE - Means "I don't need this range or the data in it any more".
Kernel promises to fail later accesses to it.
MADV_DONTNEED - Means "I don't need this range right now - and I don't
need the data in it anymore". Kernel promises to make later accesses to
it succeed (if necessary by providing a new page initialized with zeroes).
MADV_FREE was introduced in Linux 4.5.
glibc 2.25 and later always define MADV_FREE.
Unpatched ghc 8.0.2 will use either MADV_FREE or MADV_DONTNEED, determined
at ghc compile time. Which of them will actually succeed is determined
by the Linux kernel at run time.
This patch makes ghc try MADV_FREE. If it doesn't work, it falls back to
MADV_DONTNEED.
The end result is that ghc programs free their memory with Linux < 4.5 again.
See https://git.haskell.org/ghc.git/commitdiff/6576bf83cdf4eac05eb88a24aa934a736c91e3da for more information.
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -541,11 +541,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");
}
67f623512a88ac20b879e00d442f85abe'>packages/aux-files/guile-launcher.c
Age | Commit message (Expand) | Author |
2020-10-05 | self: Use a 'guile' that doesn't complain about locales....Since commit ba48895899a117d6ace2209c3f54411a4a989133, selected UTF-8
locales are bundled. However, because 'guix-command' is itself a Guile
script, users would still see Guile's warning, particularly on foreign
distros:
$ LC_ALL=sdf guix foo
guile: warning: failed to install locale
hint: Consider installing the `glibc-utf8-locales' [...]
User commands would print that warning, but more importantly, each
invocation of 'guix substitute' would print it, even though
'guix-daemon.service' explicitly chooses "en_US.utf8", which is in
'glibc-utf8-locales'. This leads to confusion since users would keep
seeing this message unless/until they realize they also need to install
'glibc-utf8-locales' in root's profile.
This patch gets rid of "guile: warning: ..." for a guix-pulled 'guix'
command.
* guix/self.scm (specification->package): Add "gcc-toolchain".
(quiet-guile): New procedure.
(guix-command): Use it.
* gnu/packages/aux-files/guile-launcher.c: New file.
* Makefile.am (AUX_FILES): Add it.
| Ludovic Courtès |