9.80 fadvise

#define POSIX_FADV_NORMAL     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_NOREUSE    3
#define POSIX_FADV_DONTNEED   4
#define POSIX_FADV_WILLNEED   5
#define POSIX_FADV_RANDOM     6

int fadvise(int fd, off_t offset, off_t len, int advice);

This syscall is used for advising the kernel on how access will be done for the passed file for the passed range, in order to prepare caches ahead of time to optimize system resource use and performance. This can only be used with filesystem inodes.

Advising for a file does not make any operation illegal or behave weirdly, they are just used in order to cater to the passed information.

Advice is indicated on advice, and can take the following values:

POSIX_FADV_NORMAL

Indicates that the application has no advice to give about its access pattern for the specified data. If no advice is given for an open file, this is the default assumption.

POSIX_FADV_SEQUENTIAL

Specifies that the application has no advice to give on its behavior with respect to the specified data. It is the default characteristic if no advice is given for an open file.

POSIX_FADV_NOREUSE

Specifies that the application expects to access the specified data once and then not reuse it thereafter.

POSIX_FADV_DONTNEED

Specifies that the application expects that it will not access the specified data in the near future.

POSIX_FADV_WILLNEED

Specifies that the application expects to access the specified data in the near future.

POSIX_FADV_RANDOM

Specifies that the application expects to access the specified data in a random order.

The syscall returns 0 on success or -1 on failure, with the following errno:

EINVAL

advice is not valid.

EBADF

fd is not opened to anything.

ESPIPE

The passed file is not a VFS inode.