[lld] [llvm] [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
Mon Oct 27 10:15:18 PDT 2025


================
@@ -331,59 +337,64 @@ class SerialBackgroundQueue {
   }
 };
 
+static SerialBackgroundWorkQueue pageInQueue;
+
 // Most input files have been mapped but not yet paged in.
 // This code forces the page-ins on multiple threads so
 // the process is not stalled waiting on disk buffer i/o.
 void multiThreadedPageInBackground(DeferredFiles &deferred) {
+  using namespace std::chrono;
   static const size_t pageSize = Process::getPageSizeEstimate();
   static const size_t largeArchive = 10 * 1024 * 1024;
-#ifndef NDEBUG
-  using namespace std::chrono;
-  std::atomic_int numDeferedFilesTouched = 0;
   static std::atomic_uint64_t totalBytes = 0;
+  std::atomic_int numDeferedFilesAdvised = 0;
   auto t0 = high_resolution_clock::now();
-#endif
 
   auto preloadDeferredFile = [&](const DeferredFile &deferredFile) {
     const StringRef &buff = deferredFile.buffer.getBuffer();
     if (buff.size() > largeArchive)
       return;
-#ifndef NDEBUG
+
     totalBytes += buff.size();
-    numDeferedFilesTouched += 1;
-#endif
+    numDeferedFilesAdvised += 1;
 
+#if _WIN32
     // 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) {
+    for (const char *page = buff.data(), *end = page + buff.size();
+         page < end && !pageInQueue.stopAllWork; page += pageSize) {
       [[maybe_unused]] volatile char t = *page;
       (void)t;
     }
+#else
+#define DEBUG_TYPE "lld-madvise"
+    auto aligned = llvm::alignAddr(buff.data(), Align(pageSize));
----------------
johnno1962 wrote:

This gives an error. 
/Users/johnholdsworth/D2/swift-source/llvm-project.lld2/lld/MachO/Driver.cpp:373:20: error: no matching function for call to 'alignDown'
  373 |     auto aligned = llvm::alignDown(buff.data(), Align(pageSize));
      |                    ^~~~~~~~~~~~~~~
/Users/johnholdsworth/D2/swift-source/llvm-project.lld2/llvm/include/llvm/Support/MathExtras.h:548:13: note: candidate template ignored: requirement 'std::is_integral_v<const char *>' was not satisfied [with U = const char *, V = Align, W = uint8_t]
  548 | constexpr T alignDown(U Value, V Align, W Skew = 0) {
      |             ^
1 error generated.


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


More information about the llvm-commits mailing list