Via the posix_fadvise(2) API

Can we do better? Yes, indeed: Linux provides the posix_fadvise(2) system call, allowing an application process to give hints to the kernel on it's pattern of access to file data, via a parameter called advice. Relevant to our example, we can pass advice as the value POSIX_FADV_SEQUENTIAL, POSIX_FADV_WILLNEED, to inform the kernel that we expect to read file data sequentially and that we expect we shall require access to the file's data in the near future. This advice causes the kernel to initiate an aggressive read-ahead of the file's data in sequential order (lower-to-higher file offsets) into the kernel page cache. This will greatly help increase performance.

The signature of the posix_fadvise(2) system call ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.