MADVISE(2) | System Calls Manual | MADVISE(2) |
madvise
,
posix_madvise
— give advice
about use of memory
Standard C Library (libc, -lc)
#include
<sys/mman.h>
int
madvise
(void
*addr, size_t len,
int behav);
int
posix_madvise
(void
*addr, size_t len,
int behav);
The
madvise
()
system call allows a process that has knowledge of its memory behavior to
describe it to the system. The posix_madvise
()
interface is identical, except it returns an error number on error and does
not modify errno, and is provided for standards
conformance.
The known behaviors are:
MADV_NORMAL
MADV_RANDOM
MADV_SEQUENTIAL
MADV_WILLNEED
MADV_DONTNEED
MADV_FREE
MADV_FREE
call. References made to that address
space range will not make the VM system page the information back in from
backing store until the page is modified again.MADV_NOSYNC
This feature is typically used when you want to use a file-backed shared memory area to communicate between processes (IPC) and do not particularly need the data being stored in that area to be physically written to disk. With this feature you get the equivalent performance with mmap that you would expect to get with SysV shared memory calls, but in a more controllable and less restrictive manner. However, note that this feature is not portable across UNIX platforms (though some may do the right thing by default). For more information see the MAP_NOSYNC section of mmap(2)
MADV_AUTOSYNC
MADV_NOCORE
MADV_CORE
MADV_PROTECT
Portable programs that call the
posix_madvise
()
interface should use the aliases POSIX_MADV_NORMAL
,
POSIX_MADV_SEQUENTIAL
,
POSIX_MADV_RANDOM
,
POSIX_MADV_WILLNEED
, and
POSIX_MADV_DONTNEED
rather than the flags described
above.
The madvise
() function returns the
value 0 if successful; otherwise the value -1 is returned and
the global variable errno is set to indicate the
error.
The madvise
() system call will fail
if:
EINVAL
]ENOMEM
]EPERM
]MADV_PROTECT
was specified and the process does not have superuser privileges.mincore(2), mprotect(2), msync(2), munmap(2), posix_fadvise(2)
The posix_madvise
() interface conforms to
IEEE Std 1003.1-2001 (“POSIX.1”).
The madvise
() system call first appeared
in 4.4BSD.
July 12, 2015 | Debian |