Skip to content

Commit dc9ac78

Browse files
committed
Switch to use madvise() to page-in files.
1 parent 6241cb3 commit dc9ac78

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lld/MachO/Driver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include "llvm/TextAPI/Architecture.h"
5454
#include "llvm/TextAPI/PackedVersion.h"
5555

56+
#include <sys/mman.h>
57+
5658
using namespace llvm;
5759
using namespace llvm::MachO;
5860
using namespace llvm::object;
@@ -338,7 +340,7 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
338340
static const size_t largeArchive = 10 * 1024 * 1024;
339341
#ifndef NDEBUG
340342
using namespace std::chrono;
341-
std::atomic_int numDeferedFilesTouched = 0;
343+
std::atomic_int numDeferedFilesAdvised = 0;
342344
static std::atomic_uint64_t totalBytes = 0;
343345
auto t0 = high_resolution_clock::now();
344346
#endif
@@ -349,13 +351,18 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
349351
return;
350352
#ifndef NDEBUG
351353
totalBytes += buff.size();
352-
numDeferedFilesTouched += 1;
354+
numDeferedFilesAdvised += 1;
353355
#endif
354356

357+
#if _WIN32
355358
// Reference all file's mmap'd pages to load them into memory.
356359
for (const char *page = buff.data(), *end = page + buff.size(); page < end;
357360
page += pageSize)
358361
LLVM_ATTRIBUTE_UNUSED volatile char t = *page;
362+
#else
363+
// Advise that mmap'd files should be loaded into memory.
364+
madvise((void *)buff.data(), buff.size(), MADV_WILLNEED);
365+
#endif
359366
};
360367
#if LLVM_ENABLE_THREADS
361368
{ // Create scope for waiting for the taskGroup
@@ -376,7 +383,7 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
376383
auto dt = high_resolution_clock::now() - t0;
377384
if (Process::GetEnv("LLD_MULTI_THREAD_PAGE"))
378385
llvm::dbgs() << "multiThreadedPageIn " << totalBytes << "/"
379-
<< numDeferedFilesTouched << "/" << deferred.size() << "/"
386+
<< numDeferedFilesAdvised << "/" << deferred.size() << "/"
380387
<< duration_cast<milliseconds>(dt).count() / 1000. << "\n";
381388
#endif
382389
}

0 commit comments

Comments
 (0)