[compiler-rt] 4458e8c - Revert "[scudo] Check if MADV_DONTNEED zeroes memory"

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri May 28 01:54:56 PDT 2021


Author: Vitaly Buka
Date: 2021-05-28T01:53:42-07:00
New Revision: 4458e8c4b42f3ebd44f909ffc0836224b7141d2e

URL: https://github.com/llvm/llvm-project/commit/4458e8c4b42f3ebd44f909ffc0836224b7141d2e
DIFF: https://github.com/llvm/llvm-project/commit/4458e8c4b42f3ebd44f909ffc0836224b7141d2e.diff

LOG: Revert "[scudo] Check if MADV_DONTNEED zeroes memory"

This reverts commit d423509b8036c29bbf94dab192d12097555ce0f8.

We are going to use patched QEMU.

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp
index 75757cae2671..dedab61631bc 100644
--- a/compiler-rt/lib/scudo/standalone/linux.cpp
+++ b/compiler-rt/lib/scudo/standalone/linux.cpp
@@ -10,7 +10,6 @@
 
 #if SCUDO_LINUX
 
-#include "atomic_helpers.h"
 #include "common.h"
 #include "linux.h"
 #include "mutex.h"
@@ -90,41 +89,10 @@ void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
     dieOnMapUnmapError();
 }
 
-static bool madviseNotNeedFails() {
-  const uptr Size = getPageSizeCached();
-  char *P = reinterpret_cast<char *>(mmap(0, Size, PROT_READ | PROT_WRITE,
-                                          MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
-  if (!P)
-    dieOnMapUnmapError(errno == ENOMEM ? Size : 0);
-  *P = 1;
-  while (madvise(P, Size, MADV_DONTNEED) == -1 && errno == EAGAIN) {
-  }
-  const bool R = (*P != 0);
-  if (munmap(P, Size) != 0)
-    dieOnMapUnmapError();
-  return R;
-}
-
-static bool madviseNotNeedFailsCached() {
-  static atomic_u8 Cache;
-  enum State : u8 { Unknown = 0, Yes = 1, No = 2 };
-  State NeedsMemset = static_cast<State>(atomic_load_relaxed(&Cache));
-  if (NeedsMemset == Unknown) {
-    NeedsMemset = madviseNotNeedFails() ? Yes : No;
-    atomic_store_relaxed(&Cache, NeedsMemset);
-  }
-  return NeedsMemset == Yes;
-}
-
 void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
                       UNUSED MapPlatformData *Data) {
   void *Addr = reinterpret_cast<void *>(BaseAddress + Offset);
-  if (madviseNotNeedFailsCached()) {
-    // Workaround for QEMU-user ignoring MADV_DONTNEED.
-    // https://github.com/qemu/qemu/blob/b1cffefa1b163bce9aebc3416f562c1d3886eeaa/linux-user/syscall.c#L11941
-    // https://bugs.launchpad.net/qemu/+bug/1926521
-    memset(Addr, 0, Size);
-  }
+
   while (madvise(Addr, Size, MADV_DONTNEED) == -1 && errno == EAGAIN) {
   }
 }


        


More information about the llvm-commits mailing list