[compiler-rt] r320659 - [sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OS

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 16:04:30 PST 2017


Author: kuba.brecka
Date: Wed Dec 13 16:04:30 2017
New Revision: 320659

URL: http://llvm.org/viewvc/llvm-project?rev=320659&view=rev
Log:
[sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OS

MADV_DONTNEED on Linux actually mark the pages as free to be overwritten with zeroes, but on Darwin and BSD, it's just an advisory flag (the OS cannot discard the content). We should use MADV_FREE on Darwin and BSD.

Differential Revision: https://reviews.llvm.org/D40666


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h?rev=320659&r1=320658&r2=320659&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform.h Wed Dec 13 16:04:30 2017
@@ -282,5 +282,10 @@
 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0
 #endif
 
+#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
+# define SANITIZER_MADVISE_DONTNEED MADV_FREE
+#else
+# define SANITIZER_MADVISE_DONTNEED MADV_DONTNEED
+#endif
 
 #endif // SANITIZER_PLATFORM_H

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=320659&r1=320658&r2=320659&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Wed Dec 13 16:04:30 2017
@@ -62,7 +62,8 @@ void ReleaseMemoryPagesToOS(uptr beg, up
   uptr beg_aligned = RoundUpTo(beg, page_size);
   uptr end_aligned = RoundDownTo(end, page_size);
   if (beg_aligned < end_aligned)
-    madvise((void*)beg_aligned, end_aligned - beg_aligned, MADV_DONTNEED);
+    madvise((void *)beg_aligned, end_aligned - beg_aligned,
+            SANITIZER_MADVISE_DONTNEED);
 }
 
 void NoHugePagesInRegion(uptr addr, uptr size) {




More information about the llvm-commits mailing list