[llvm] b66b324 - [Support] Use posix_madvise() if available

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 00:36:50 PST 2022


Author: Nikita Popov
Date: 2022-02-16T09:36:41+01:00
New Revision: b66b3247f598448aab50d8ae67729dd2312f3067

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

LOG: [Support] Use posix_madvise() if available

This is a followup to D119695 using the suggestion by joerg. Rather
than manually declaring madvise() on __sun__, this uses
posix_madvise() if available, which does get declared properly on
Illumos.

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

Added: 
    

Modified: 
    llvm/lib/Support/Unix/Path.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index d53a09f0579cf..c30c3a6e365e6 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -118,12 +118,6 @@ typedef uint_t uint;
 #define STATVFS_F_FLAG(vfs) (vfs).f_flags
 #endif
 
-#if defined(__sun__) && defined(__svr4__)
-// The madvise() declaration on Illumos cannot be made visible if _XOPEN_SOURCE
-// is defined. This declaration is also compatible with Solaris 11.4.
-extern "C" int madvise(void *, size_t, int);
-#endif
-
 using namespace llvm;
 
 namespace llvm {
@@ -880,12 +874,14 @@ void mapped_file_region::unmapImpl() {
 
 void mapped_file_region::dontNeedImpl() {
   assert(Mode == mapped_file_region::readonly);
+  if (!Mapping)
+      return;
 #if defined(__MVS__) || defined(_AIX)
   // If we don't have madvise, or it isn't beneficial, treat this as a no-op.
-  return;
+#elif defined(POSIX_MADV_DONTNEED)
+  ::posix_madvise(Mapping, Size, POSIX_MADV_DONTNEED);
 #else
-  if (Mapping)
-    ::madvise(Mapping, Size, MADV_DONTNEED);
+  ::madvise(Mapping, Size, MADV_DONTNEED);
 #endif
 }
 


        


More information about the llvm-commits mailing list