posix_madvise()

Updated: April 19, 2023

Provide advisory information about the expected use of memory

Synopsis:

#include <sys/mman.h>

int posix_madvise( void *addr,
                   size_t len,
                   int advice );

Arguments:

addr
The address of the data the application is providing advice about.
len
The length of the data, in bytes.
advice
The advice to be applied to the memory range; one of the following:
  • POSIX_MADV_DISCARD_NP (QNX Neutrino extension; QNX Neutrino 7.0 or later) — discard the backing store for lazy private mappings (similar to madvise(MADV_DONTNEED) in Linux). The “NP” in the flag name stands for “non-POSIX.”
  • POSIX_MADV_DONTNEED — the application expects that it won't access the data in the near future.
  • POSIX_MADV_NORMAL — the application has no advice to give on its behavior with respect to the specified range. This is the default characteristic if no advice is given for a range of memory.
  • POSIX_MADV_RANDOM — the application expects to access the data in a random order.
  • POSIX_MADV_SEQUENTIAL — the application expects to access the data sequentially from lower addresses to higher addresses.
  • POSIX_MADV_WILLNEED — the application expects to access the data in the near future.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The posix_madvise() function advises the memory manager how the application expects to use the data in the memory starting at address addr, and continuing for len bytes. The memory manager may use this information to optimize handling of the data.

Returns:

EOK
Success.
EINVAL
The value of advice is invalid.
ENOMEM
Addresses in the specified range are partly or completely outside the range allowed for the address space of the calling process.

Classification:

POSIX 1003.1 ADV

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes