[lld] [lld][MachO] Follow-up to use madvise() for threaded file page-in. (PR #157917)

John Holdsworth via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 00:18:37 PDT 2025


================
@@ -349,13 +352,19 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
       return;
 #ifndef NDEBUG
     totalBytes += buff.size();
-    numDeferedFilesTouched += 1;
+    numDeferedFilesAdvised += 1;
 #endif
 
+#if _WIN32
+    static const size_t pageSize = Process::getPageSizeEstimate();
     // Reference all file's mmap'd pages to load them into memory.
     for (const char *page = buff.data(), *end = page + buff.size(); page < end;
          page += pageSize)
       LLVM_ATTRIBUTE_UNUSED volatile char t = *page;
+#else
+    // Advise that mmap'd files should be loaded into memory.
+    madvise((void *)buff.data(), buff.size(), MADV_WILLNEED);
----------------
johnno1962 wrote:

This was part of commit "Response to review.".
> There is similar code in MemoryBuffer::dontNeedIfMmap(). Maybe we can add a new function there?
It's going to be difficult to come up with the final design until some benchmarking has been done on windows of `PrefetchVirtualMemory`. As it takes a vector of memory regions moving it into another method on MemoryBuffer isn't a good fit. More likely it should replace new code like this in Driver.cpp:
```
  for (const auto &file : deferred)
    preloadDeferredFile(file);


https://github.com/llvm/llvm-project/pull/157917


More information about the llvm-commits mailing list