1POSIX_MADVISE(3)           Linux Programmer's Manual          POSIX_MADVISE(3)
2
3
4

NAME

6       posix_madvise - give advice about patterns of memory usage
7

SYNOPSIS

9       #include <sys/mman.h>
10
11       int posix_madvise(void *addr, size_t len, int advice);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       posix_madvise():
16           _POSIX_C_SOURCE >= 200112L
17

DESCRIPTION

19       The posix_madvise() function allows an application to advise the system
20       about its expected patterns of usage of memory  in  the  address  range
21       starting  at  addr and continuing for len bytes.  The system is free to
22       use this advice in order to improve the performance of memory  accesses
23       (or to ignore the advice altogether), but calling posix_madvise() shall
24       not affect the semantics of access to memory in the specified range.
25
26       The advice argument is one of the following:
27
28       POSIX_MADV_NORMAL
29              The application has no special advice regarding its memory usage
30              patterns  for  the specified address range.  This is the default
31              behavior.
32
33       POSIX_MADV_SEQUENTIAL
34              The application expects to access the  specified  address  range
35              sequentially,  running from lower addresses to higher addresses.
36              Hence, pages in this region can be aggressively read ahead,  and
37              may be freed soon after they are accessed.
38
39       POSIX_MADV_RANDOM
40              The  application  expects  to access the specified address range
41              randomly.  Thus, read ahead may be less useful than normally.
42
43       POSIX_MADV_WILLNEED
44              The application expects to access the specified address range in
45              the near future.  Thus, read ahead may be beneficial.
46
47       POSIX_MADV_DONTNEED
48              The  application  expects  that it will not access the specified
49              address range in the near future.
50

RETURN VALUE

52       On success, posix_madvise() returns 0.  On failure, it returns a  posi‐
53       tive error number.
54

ERRORS

56       EINVAL addr  is  not a multiple of the system page size or len is nega‐
57              tive.
58
59       EINVAL advice is invalid.
60
61       ENOMEM Addresses in the specified range  are  partially  or  completely
62              outside the caller's address space.
63

VERSIONS

65       Support for posix_madvise() first appeared in glibc version 2.2.
66

CONFORMING TO

68       POSIX.1-2001.
69

NOTES

71       POSIX.1 permits an implementation to generate an error if len is 0.  On
72       Linux, specifying len as 0 is permitted (as a successful no-op).
73
74       In glibc, this function  is  implemented  using  madvise(2).   However,
75       since glibc 2.6, POSIX_MADV_DONTNEED is treated as a no-op, because the
76       corresponding madvise(2) value, MADV_DONTNEED, has  destructive  seman‐
77       tics.
78

SEE ALSO

80       madvise(2), posix_fadvise(2)
81

COLOPHON

83       This  page  is  part of release 4.16 of the Linux man-pages project.  A
84       description of the project, information about reporting bugs,  and  the
85       latest     version     of     this    page,    can    be    found    at
86       https://www.kernel.org/doc/man-pages/.
87
88
89
90Linux                             2017-09-15                  POSIX_MADVISE(3)
Impressum