5353#include " llvm/TextAPI/Architecture.h"
5454#include " llvm/TextAPI/PackedVersion.h"
5555
56+ #if !_WIN32
57+ #include < sys/mman.h>
58+ #endif
59+
5660using namespace llvm ;
5761using namespace llvm ::MachO;
5862using namespace llvm ::object;
@@ -334,11 +338,10 @@ class SerialBackgroundQueue {
334338// This code forces the page-ins on multiple threads so
335339// the process is not stalled waiting on disk buffer i/o.
336340void multiThreadedPageInBackground (DeferredFiles &deferred) {
337- static const size_t pageSize = Process::getPageSizeEstimate ();
338341 static const size_t largeArchive = 10 * 1024 * 1024 ;
339342#ifndef NDEBUG
340343 using namespace std ::chrono;
341- std::atomic_int numDeferedFilesTouched = 0 ;
344+ std::atomic_int numDeferedFilesAdvised = 0 ;
342345 static std::atomic_uint64_t totalBytes = 0 ;
343346 auto t0 = high_resolution_clock::now ();
344347#endif
@@ -349,13 +352,19 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
349352 return ;
350353#ifndef NDEBUG
351354 totalBytes += buff.size ();
352- numDeferedFilesTouched += 1 ;
355+ numDeferedFilesAdvised += 1 ;
353356#endif
354357
358+ #if _WIN32
359+ static const size_t pageSize = Process::getPageSizeEstimate ();
355360 // Reference all file's mmap'd pages to load them into memory.
356361 for (const char *page = buff.data (), *end = page + buff.size (); page < end;
357362 page += pageSize)
358363 LLVM_ATTRIBUTE_UNUSED volatile char t = *page;
364+ #else
365+ // Advise that mmap'd files should be loaded into memory.
366+ madvise ((void *)buff.data (), buff.size (), MADV_WILLNEED);
367+ #endif
359368 };
360369#if LLVM_ENABLE_THREADS
361370 { // Create scope for waiting for the taskGroup
@@ -376,7 +385,7 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
376385 auto dt = high_resolution_clock::now () - t0;
377386 if (Process::GetEnv (" LLD_MULTI_THREAD_PAGE" ))
378387 llvm::dbgs () << " multiThreadedPageIn " << totalBytes << " /"
379- << numDeferedFilesTouched << " /" << deferred.size () << " /"
388+ << numDeferedFilesAdvised << " /" << deferred.size () << " /"
380389 << duration_cast<milliseconds>(dt).count () / 1000 . << " \n " ;
381390#endif
382391}
0 commit comments