Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions extension/data_loader/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifndef _WIN32

#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

Expand Down Expand Up @@ -53,6 +54,24 @@ ET_INLINE void madvise_pages_willneed_sequential(void* addr, size_t len) {
::madvise(addr, len, MADV_SEQUENTIAL);
}

/**
* On Apple platforms, schedule kernel read-ahead on the file descriptor itself
* via fcntl(F_RDADVISE). This is more aggressive than madvise for cold starts:
* it brings pages into the unified buffer cache so first-touch faults are
* serviced from RAM instead of storage. No-op on non-Apple POSIX platforms.
*/
ET_INLINE void fcntl_rdadvise_apple(int fd, size_t file_size) {
#if defined(__APPLE__)
struct radvisory advice;
advice.ra_offset = 0;
advice.ra_count = static_cast<int>(file_size);
::fcntl(fd, F_RDADVISE, &advice);
#else
(void)fd;
(void)file_size;
#endif
}

#else

#define NOMINMAX
Expand Down Expand Up @@ -99,4 +118,12 @@ ET_INLINE void madvise_pages_willneed_sequential(void* addr, size_t len) {
(void)len;
}

/**
* No-op on Windows: F_RDADVISE is an Apple-specific fcntl command.
*/
ET_INLINE void fcntl_rdadvise_apple(int fd, size_t file_size) {
(void)fd;
(void)file_size;
}

#endif
1 change: 1 addition & 0 deletions extension/data_loader/mmap_data_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ Result<FreeableBuffer> MmapDataLoader::load(

if (mlock_config_ == MlockConfig::UseMadvise) {
madvise_pages_willneed_sequential(pages, map_size);
fcntl_rdadvise_apple(fd_, file_size_);
}

// The requested data is at an offset into the mapped pages.
Expand Down
Loading