|MADVISE(3C)||Standard C Library Functions||MADVISE(3C)|
madvise — provide
advice to VM system
size_t len, int advice);
function advises the kernel that a region of user mapped memory in the range
[addr, addr +
len) will be accessed following a type of pattern. The
kernel uses this information to optimize the procedure for manipulating and
maintaining the resources associated with the specified mapping range. In
general (and true to the name of the function), the advice is merely
advisory, and the only user-visible ramifications are in terms of
performance, not semantics. Note that
an exception to this; see below for details.
Values for advice are defined in
#define MADV_NORMAL 0x0 /* No further special treatment */ #define MADV_RANDOM 0x1 /* Expect random page references */ #define MADV_SEQUENTIAL 0x2 /* Expect sequential page references */ #define MADV_WILLNEED 0x3 /* Will need these pages */ #define MADV_DONTNEED 0x4 /* Don't need these pages */ #define MADV_FREE 0x5 /* Contents can be freed */ #define MADV_ACCESS_DEFAULT 0x6 /* default access */ #define MADV_ACCESS_LWP 0x7 /* next LWP to access heavily */ #define MADV_ACCESS_MANY 0x8 /* many processes to access heavily */ #define MADV_PURGE 0x9 /* contents will be purged */
MADV_NORMALis in effect when an address of a mapped file is accessed, the system tries to read in as much data from the file as reasonable, in anticipation of other accesses within a certain locality.
MADV_DONTNEEDare similar to other systems, they differ significantly from the semantics on Linux, where
MADV_DONTNEEDwill actually synchronously purge the address range, and subsequent faults will load from either backing store or be zero-filled on demand. If the peculiar Linux semantics are desired,
MADV_PURGEshould be used in lieu of
MADV_FREEcall. References made to the address range will not make the system read from backing store (swap space) until the page is modified again.
This value cannot be used on mappings that have underlying file objects.
MADV_FREE, which gives the system more flexibility and results in better performance when pages are, in fact, reused by the caller. Indeed,
MADV_PURGEonly exists to provide an equivalent to the unfortunate
MADV_DONTNEEDsemantics found in Linux, upon which some programs have (regrettably) come to depend. In de novo applications,
MADV_PURGEshould be avoided;
MADV_FREEshould always be preferred.
function should be used by applications with specific knowledge of their
access patterns over a memory object, such as a mapped file, to increase
MS_INVALIDATEoption is specified.
madvise() function could return prior to this condition being detected, in which case errno will not be set to
|February 17, 2023||OmniOS|