Posix fadvise and madvise: Difference between revisions
Jump to navigation
Jump to search
(Created page with " posix_fadvice() gives a non-binding hint about how we expect to access a (portion of a) file, in case that helps its planning, mostly in terms of : how much readahead to do : whether to keep the results in the page cache The below is mostly selections from the man page: <syntaxhighlight lang="c"> int posix_fadvise(int fd, off_t offset, off_t len, int advice); </syntaxhighlight> : The advice applies to a (not necessarily existent) region :: starting at offset...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
posix_fadvice() gives a non-binding hint about how | posix_fadvice() gives a non-binding hint about how the calling applications expect to access a (portion of a) file, in case that helps the OS's planning, mostly in terms of | ||
: how much readahead to do | : how much readahead to do | ||
: whether to keep the results in the [[page cache]] | : whether to keep the results in the [[page cache]] | ||
Line 11: | Line 11: | ||
int posix_fadvise(int fd, off_t offset, off_t len, int advice); | int posix_fadvise(int fd, off_t offset, off_t len, int advice); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* The advice applies to a (not necessarily existent) region | |||
** starting at offset and extending | |||
** for len bytes (or until the end of the file if len is 0) | |||
* within the file referred to by fd | |||
Revision as of 13:43, 23 July 2023
posix_fadvice() gives a non-binding hint about how the calling applications expect to access a (portion of a) file, in case that helps the OS's planning, mostly in terms of
- how much readahead to do
- whether to keep the results in the page cache
The below is mostly selections from the man page:
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
- The advice applies to a (not necessarily existent) region
- starting at offset and extending
- for len bytes (or until the end of the file if len is 0)
- within the file referred to by fd
- POSIX_FADV_NORMAL - application has no advice (assumed default)
- on linux, allows readahead
- POSIX_FADV_SEQUENTIAL - "we expect to read this sequentially, if that helps"
- on linux, doubles the regular readahead
- POSIX_FADV_RANDOM - "we don't expect to read this sequentially"
- POSIX_FADV_NOREUSE - "we expect to read this just once"
- "In kernels before 2.6.18, POSIX_FADV_NOREUSE had the same semantics as POSIX_FADV_WILLNEED. This was probably a bug; since kernel 2.6.18, this flag is a no-op."
- POSIX_FADV_WILLNEED - "we expect to read the same data again soon"
- POSIX_FADV_DONTNEED - "we expect to not read this data again soon"
- should be called after you are done with the data, not before you read it
- the point would often be not pushing more useful pages out of the page cache -- for larger files you probably want to do this regularly while reading it.
See also: