summaryrefslogtreecommitdiff
path: root/src/gc/unix
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2017-04-14 05:13:48 -0700
committerGitHub <noreply@github.com>2017-04-14 05:13:48 -0700
commitedd23a10bc574058a42c62dc829973dc48449837 (patch)
tree62fe24ff8f046bca695ba3a8cc089a95d31fb321 /src/gc/unix
parentd09465f3c9ae99c3842ff22edb7f92695dd7c7ca (diff)
downloadcoreclr-edd23a10bc574058a42c62dc829973dc48449837.tar.gz
coreclr-edd23a10bc574058a42c62dc829973dc48449837.tar.bz2
coreclr-edd23a10bc574058a42c62dc829973dc48449837.zip
Implement MEM_RESET handling in VirtualAlloc on Unix (#10939)
Diffstat (limited to 'src/gc/unix')
-rw-r--r--src/gc/unix/gcenv.unix.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp
index 45489c69a7..cad83a342b 100644
--- a/src/gc/unix/gcenv.unix.cpp
+++ b/src/gc/unix/gcenv.unix.cpp
@@ -348,8 +348,20 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size)
// true if it has succeeded, false if it has failed
bool GCToOSInterface::VirtualReset(void * address, size_t size, bool unlock)
{
- // TODO(CoreCLR#1259) pipe to madvise?
- return false;
+ int st;
+#if HAVE_MADV_FREE
+ // Try to use MADV_FREE if supported. It tells the kernel that the application doesn't
+ // need the pages in the range. Freeing the pages can be delayed until a memory pressure
+ // occurs.
+ st = madvise(address, size, MADV_FREE);
+ if (st != 0)
+#endif
+ {
+ // In case the MADV_FREE is not supported, use MADV_DONTNEED
+ st = madvise(address, size, MADV_DONTNEED);
+ }
+
+ return (st == 0);
}
// Check if the OS supports write watching