[PATCH] D119856: [Support] Use posix_madvise() if available
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 15 09:17:35 PST 2022
nikic created this revision.
nikic added reviewers: joerg, ro, MaskRay.
Herald added subscribers: dexonsmith, hiraditya, fedor.sergeev, krytarowski.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is a followup to D119695 <https://reviews.llvm.org/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.
https://reviews.llvm.org/D119856
Files:
llvm/lib/Support/Unix/Path.inc
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -118,12 +118,6 @@
#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::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
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119856.408909.patch
Type: text/x-patch
Size: 1039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220215/46148f5a/attachment.bin>
More information about the llvm-commits
mailing list