Search code examples
linuxposix

Is posix_fadvise synchronous or asynchronous on linux kernel >= 5?


I am interested in optimizing disk reads via posix_fadvise with POSIX_FADV_SEQUENTIAL option. Is the function call asynchronous, with pre-fetch to buffer done in background, or will I have to wait for the pre-fetch before return ?


Solution

  • posix_fadvise doesn't prefetch any data. It simply tells the kernel that you'd like to use a certain access pattern.

    With POSIX_FADV_SEQUENTIAL, the kernel will double the readahead size, as mentioned in the manual page. This is the only action performed synchronously by posix_fadvise; any readahead will occur as part of another operation and not as part of this call.