Last-Modified: Sat, 16 Nov 2024 12:26:03 GMT
Expires: Tue, 14 Nov 2034 12:26:03 GMT
ETag: "31cdb5bb3a3145af908462db9f98df97fa6c59aa"

<html><head><title>/etc/snippets/text-mode/</title></head>
<body>
<h2>/etc/snippets/text-mode/</h2>
<ul>
<li><a href='/guix/plain/etc/snippets/?id=86f18e4e6d10011522cc6159d45d535a17516622'>../</a></li>
  <li><a href='/guix/plain/etc/snippets/text-mode/guix-commit-message-add-package?id=86f18e4e6d10011522cc6159d45d535a17516622'>guix-commit-message-add-package</a></li>
  <li><a href='/guix/plain/etc/snippets/text-mode/guix-commit-message-rename-package?id=86f18e4e6d10011522cc6159d45d535a17516622'>guix-commit-message-rename-package</a></li>
  <li><a href='/guix/plain/etc/snippets/text-mode/guix-commit-message-update-package?id=86f18e4e6d10011522cc6159d45d535a17516622'>guix-commit-message-update-package</a></li>
  <li><a href='/guix/plain/etc/snippets/text-mode/guix-commit-message-use-https-home-page?id=86f18e4e6d10011522cc6159d45d535a17516622'>guix-commit-message-use-https-home-page</a></li>
 </ul>
</body></html>
rm.submit();'>
<option value='koszko' selected='selected'>koszko</option>
<option value='koszko-scripts'>koszko-scripts</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Wojtek's customized Guix</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a class='active' href='/guix/about/'>about</a><a href='/guix/'>summary</a><a href='/guix/refs/?id=06b1d6954aa6cf7123745136df41bc949b591f1c'>refs</a><a href='/guix/log/'>log</a><a href='/guix/tree/?id=06b1d6954aa6cf7123745136df41bc949b591f1c'>tree</a><a href='/guix/commit/?id=06b1d6954aa6cf7123745136df41bc949b591f1c'>commit</a><a href='/guix/diff/?id=06b1d6954aa6cf7123745136df41bc949b591f1c'>diff</a></td><td class='form'><form class='right' method='get' action='/guix/log/'>
<input type='hidden' name='id' value='06b1d6954aa6cf7123745136df41bc949b591f1c'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='content'><div id='summary'><pre>
ghc runtime by default (otherwise depending on a &quot;configure&quot; 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 &quot;I don&apos;t need this range or the data in it any more&quot;. 
Kernel promises to fail later accesses to it.

MADV_DONTNEED - Means &quot;I don&apos;t need this range right now - and I don&apos;t
need the data in it anymore&quot;. 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&apos;t work, it falls back to
MADV_DONTNEED.

The end result is that ghc programs free their memory with Linux &lt; 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 &gt;= 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 &lt; 0) {
+        if (errno == EINVAL) {
+            // Perhaps the system doesn&apos;t support MADV_FREE; fall-through and
+            // try MADV_DONTNEED.
+        } else {
+            sysErrorBelch(&quot;unable to decommit memory&quot;);
+        }
+    } else {
+        return;
+    }
 #endif
+
+    r = madvise(at, size, MADV_DONTNEED);
     if(r &lt; 0)
         sysErrorBelch(&quot;unable to decommit memory&quot;);
 }
</pre>
</div></div> <!-- class=content -->
                         <div class=footer>generated by
                             <a href="https://git.zx2c4.com/cgit/about/">
                                 cgit
                             </a>
                         </div>
                        </div> <!-- id=cgit -->
</body>
</html>
