diff options
Diffstat (limited to 'src/gc/unix/gcenv.unix.cpp')
-rw-r--r-- | src/gc/unix/gcenv.unix.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp index 45489c69a7..5fc63f47d3 100644 --- a/src/gc/unix/gcenv.unix.cpp +++ b/src/gc/unix/gcenv.unix.cpp @@ -36,13 +36,13 @@ static_assert(sizeof(uint64_t) == 8, "unsigned long isn't 8 bytes"); #error "A GC-private implementation of GCToOSInterface should only be used with FEATURE_STANDALONE_GC" #endif // FEATURE_STANDALONE_GC -#ifdef HAVE_SYS_TIME_H +#if HAVE_SYS_TIME_H #include <sys/time.h> #else #error "sys/time.h required by GC PAL for the time being" #endif // HAVE_SYS_TIME_ -#ifdef HAVE_SYS_MMAN_H +#if HAVE_SYS_MMAN_H #include <sys/mman.h> #else #error "sys/mman.h required by GC PAL" @@ -56,18 +56,7 @@ static_assert(sizeof(uint64_t) == 8, "unsigned long isn't 8 bytes"); #include <sched.h> // sched_yield #include <errno.h> #include <unistd.h> // sysconf - -// The number of milliseconds in a second. -static const int tccSecondsToMilliSeconds = 1000; - -// The number of microseconds in a second. -static const int tccSecondsToMicroSeconds = 1000000; - -// The number of microseconds in a millisecond. -static const int tccMilliSecondsToMicroSeconds = 1000; - -// The number of nanoseconds in a millisecond. -static const int tccMilliSecondsToNanoSeconds = 1000000; +#include "globals.h" // The cachced number of logical CPUs observed. static uint32_t g_logicalCpuCount = 0; @@ -117,6 +106,14 @@ bool GCToOSInterface::Initialize() return false; } +#if HAVE_MACH_ABSOLUTE_TIME + kern_return_t machRet; + if ((machRet = mach_timebase_info(&g_TimebaseInfo)) != KERN_SUCCESS) + { + return false; + } +#endif // HAVE_MACH_ABSOLUTE_TIME + return true; } @@ -348,8 +345,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 |