#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_NORMALIndicates 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_SEQUENTIALSpecifies 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_NOREUSESpecifies that the application expects to access the specified data once and then not reuse it thereafter.
POSIX_FADV_DONTNEEDSpecifies that the application expects that it will not access the specified data in the near future.
POSIX_FADV_WILLNEEDSpecifies that the application expects to access the specified data in the near future.
POSIX_FADV_RANDOMSpecifies 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:
EINVALadvice is not valid.
EBADFfd is not opened to anything.
ESPIPEThe passed file is not a VFS inode.