madvise Subroutine

Purpose

Advises the system of expected paging behavior.

Library

Standard C Library (libc.a).

Syntax

#include <sys/types.h>
#include <sys/mman.h>

int madvise( addr,  len behav)
caddr_t addr;
size_t len;
int behav;

Description

The madvise subroutine permits a process to advise the system about its expected future behavior in referencing a mapped file region or anonymous memory region.

The madvise subroutine has no functionality and is supported for compatibility only.

Parameters

Item Description
addr Specifies the starting address of the memory region. Must be a multiple of the page size returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter.
len Specifies the length, in bytes, of the memory region. If the len value is not a multiple of page size as returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter, the length of the region will be rounded up to the next multiple of the page size.
behav Specifies the future behavior of the memory region. The following values for the behav parameter are defined in the /usr/include/sys/mman.h file:
Value
Paging Behavior Message
MADV_NORMAL
The system provides no further special treatment for the memory region.
MADV_RANDOM
The system expects random page references to that memory region.
MADV_SEQUENTIAL
The system expects sequential page references to that memory region.
MADV_WILLNEED
The system expects the process will need these pages.
MADV_DONTNEED
The system expects the process does not need these pages.
MADV_SPACEAVAIL
The system will ensure that memory resources are reserved.

Return Values

When successful, the madvise subroutine returns 0. Otherwise, it returns -1 and sets the errno global variable to indicate the error.

Error Codes

If the madvise subroutine is unsuccessful, the errno global variable can be set to one of the following values:

Item Description
EINVAL The behav parameter is invalid.
ENOSPC The behav parameter specifies MADV_SPACEAVAIL and resources cannot be reserved.