posix_madvise Subroutine

Purpose

Provides advisory information to the system regarding future behavior of the application with respect to a given range of memory.

Syntax

 #include <sys/mman.h>
 int posix_madvise (void *addr, size_t len, int advice);

Description

This function advises the system on the expected future behavior of the application with regard to a given range of memory. The system can take this advice into account when performing operations on the data in memory specified by this function. The advice is given over the range covered by the offset parameter and continuing for the number of bytes specified by the addr parameter and continuing for the number of bytes specified by the len parameter.

The advice parameter must be one of the following:
  • POSIX_MADV_NORMAL
  • POSIX_MADV_SEQUENTIAL
  • POSIX_MADV_RANDOM
  • POSIX_MADV_WILLNEED
  • POSIX_MADV_DONTNEED

Parameters

Item Description
addr Defines the beginning of the range of memory to be advised
len Determines the length of the address range
advice Defines the advice to be given

Return Values

Upon successful completion, the posix_fadvise subroutine returns 0. Otherwise, one of the following error codes will be returned.

Error Codes

Item Description
EINVAL The value of the advice parameter is invalid
ENOMEM Addresses in the range specified by the addr parameter and the len parameter are partially or completely outside the range of the process's address space.