[PATCH] D40666: [sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OS

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 12:06:44 PST 2017


kubamracek created this revision.
kubamracek added a project: Sanitizers.
Herald added subscribers: Sanitizers, krytarowski, emaste.

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


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D40666

Files:
  lib/sanitizer_common/sanitizer_posix_libcdep.cc


Index: lib/sanitizer_common/sanitizer_posix_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_posix_libcdep.cc
+++ lib/sanitizer_common/sanitizer_posix_libcdep.cc
@@ -61,8 +61,10 @@
   uptr page_size = GetPageSizeCached();
   uptr beg_aligned = RoundUpTo(beg, page_size);
   uptr end_aligned = RoundDownTo(end, page_size);
+  const int madvise_flag =
+      (SANITIZER_FREEBSD || SANITIZER_MAC) ? MADV_FREE : MADV_DONTNEED;
   if (beg_aligned < end_aligned)
-    madvise((void*)beg_aligned, end_aligned - beg_aligned, MADV_DONTNEED);
+    madvise((void*)beg_aligned, end_aligned - beg_aligned, madvise_flag);
 }
 
 void NoHugePagesInRegion(uptr addr, uptr size) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40666.124986.patch
Type: text/x-patch
Size: 728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/fe7f528f/attachment.bin>


More information about the llvm-commits mailing list