@@ -338,34 +338,37 @@ class SerialBackgroundQueue {
338
338
// This code forces the page-ins on multiple threads so
339
339
// the process is not stalled waiting on disk buffer i/o.
340
340
void multiThreadedPageInBackground (DeferredFiles &deferred) {
341
- static const size_t largeArchive = 10 * 1024 * 1024 ;
342
- #ifndef NDEBUG
343
341
using namespace std ::chrono;
344
- std::atomic_int numDeferedFilesAdvised = 0 ;
342
+ static const size_t pageSize = Process::getPageSizeEstimate ();
343
+ static const size_t largeArchive = 10 * 1024 * 1024 ;
345
344
static std::atomic_uint64_t totalBytes = 0 ;
345
+ std::atomic_int numDeferedFilesAdvised = 0 ;
346
346
auto t0 = high_resolution_clock::now ();
347
- #endif
348
347
349
348
auto preloadDeferredFile = [&](const DeferredFile &deferredFile) {
350
349
const StringRef &buff = deferredFile.buffer .getBuffer ();
351
350
if (buff.size () > largeArchive)
352
351
return ;
353
- #ifndef NDEBUG
352
+ if (((uintptr_t )buff.data () & (pageSize - 1 )))
353
+ return ; // Not mmap()'d (not page aligned).
354
+
354
355
totalBytes += buff.size ();
355
356
numDeferedFilesAdvised += 1 ;
356
- #endif
357
357
358
358
#if _WIN32
359
- static const size_t pageSize = Process::getPageSizeEstimate ();
360
359
// Reference all file's mmap'd pages to load them into memory.
361
360
for (const char *page = buff.data (), *end = page + buff.size (); page < end;
362
361
page += pageSize)
363
362
LLVM_ATTRIBUTE_UNUSED volatile char t = *page;
364
363
#else
365
- // Advise that mmap'd files should be loaded into memory.
366
- madvise ((void *)buff.data (), buff.size (), MADV_WILLNEED);
364
+ if (madvise ((void *)buff.data (), buff.size (), MADV_WILLNEED) < 0 )
365
+ #ifndef NDEBUG
366
+ llvm::errs () << " madvise() error " << strerror (errno)
367
+ #endif
368
+ ;
367
369
#endif
368
370
};
371
+
369
372
#if LLVM_ENABLE_THREADS
370
373
{ // Create scope for waiting for the taskGroup
371
374
std::atomic_size_t index = 0 ;
@@ -380,14 +383,16 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
380
383
}
381
384
});
382
385
}
386
+ #else
387
+ for (const auto &file : deferred)
388
+ preloadDeferredFile (file);
383
389
#endif
384
- # ifndef NDEBUG
390
+
385
391
auto dt = high_resolution_clock::now () - t0;
386
392
if (Process::GetEnv (" LLD_MULTI_THREAD_PAGE" ))
387
393
llvm::dbgs () << " multiThreadedPageIn " << totalBytes << " /"
388
394
<< numDeferedFilesAdvised << " /" << deferred.size () << " /"
389
395
<< duration_cast<milliseconds>(dt).count () / 1000 . << " \n " ;
390
- #endif
391
396
}
392
397
393
398
static void multiThreadedPageIn (const DeferredFiles &deferred) {
0 commit comments