1posix_madvise(3) Library Functions Manual posix_madvise(3)
2
3
4
6 posix_madvise - give advice about patterns of memory usage
7
9 Standard C library (libc, -lc)
10
12 #include <sys/mman.h>
13
14 int posix_madvise(void addr[.len], size_t len, int advice);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 posix_madvise():
19 _POSIX_C_SOURCE >= 200112L
20
22 The posix_madvise() function allows an application to advise the system
23 about its expected patterns of usage of memory in the address range
24 starting at addr and continuing for len bytes. The system is free to
25 use this advice in order to improve the performance of memory accesses
26 (or to ignore the advice altogether), but calling posix_madvise() shall
27 not affect the semantics of access to memory in the specified range.
28
29 The advice argument is one of the following:
30
31 POSIX_MADV_NORMAL
32 The application has no special advice regarding its memory usage
33 patterns for the specified address range. This is the default
34 behavior.
35
36 POSIX_MADV_SEQUENTIAL
37 The application expects to access the specified address range
38 sequentially, running from lower addresses to higher addresses.
39 Hence, pages in this region can be aggressively read ahead, and
40 may be freed soon after they are accessed.
41
42 POSIX_MADV_RANDOM
43 The application expects to access the specified address range
44 randomly. Thus, read ahead may be less useful than normally.
45
46 POSIX_MADV_WILLNEED
47 The application expects to access the specified address range in
48 the near future. Thus, read ahead may be beneficial.
49
50 POSIX_MADV_DONTNEED
51 The application expects that it will not access the specified
52 address range in the near future.
53
55 On success, posix_madvise() returns 0. On failure, it returns a posi‐
56 tive error number.
57
59 EINVAL addr is not a multiple of the system page size or len is nega‐
60 tive.
61
62 EINVAL advice is invalid.
63
64 ENOMEM Addresses in the specified range are partially or completely
65 outside the caller's address space.
66
68 POSIX.1 permits an implementation to generate an error if len is 0. On
69 Linux, specifying len as 0 is permitted (as a successful no-op).
70
71 In glibc, this function is implemented using madvise(2). However,
72 since glibc 2.6, POSIX_MADV_DONTNEED is treated as a no-op, because the
73 corresponding madvise(2) value, MADV_DONTNEED, has destructive seman‐
74 tics.
75
77 POSIX.1-2008.
78
80 glibc 2.2. POSIX.1-2001.
81
83 madvise(2), posix_fadvise(2)
84
85
86
87Linux man-pages 6.04 2023-03-30 posix_madvise(3)