1 .\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .TH posix_madvise 3 (date) "Linux man-pages (unreleased)"
7 posix_madvise \- give advice about patterns of memory usage
10 .RI ( libc ", " \-lc )
13 .B #include <sys/mman.h>
15 .BI "int posix_madvise(void " addr [. len "], size_t " len ", int " advice );
19 Feature Test Macro Requirements for glibc (see
20 .BR feature_test_macros (7)):
25 _POSIX_C_SOURCE >= 200112L
30 function allows an application to advise the system about its expected
31 patterns of usage of memory in the address range starting at
36 The system is free to use this advice in order to improve the performance
37 of memory accesses (or to ignore the advice altogether), but calling
39 shall not affect the semantics of access to memory in the specified range.
43 argument is one of the following:
46 The application has no special advice regarding its memory usage patterns
47 for the specified address range.
48 This is the default behavior.
50 .B POSIX_MADV_SEQUENTIAL
51 The application expects to access the specified address range sequentially,
52 running from lower addresses to higher addresses.
53 Hence, pages in this region can be aggressively read ahead,
54 and may be freed soon after they are accessed.
57 The application expects to access the specified address range randomly.
58 Thus, read ahead may be less useful than normally.
60 .B POSIX_MADV_WILLNEED
61 The application expects to access the specified address range
63 Thus, read ahead may be beneficial.
65 .B POSIX_MADV_DONTNEED
66 The application expects that it will not access the specified address range
72 On failure, it returns a positive error number.
77 is not a multiple of the system page size or
86 Addresses in the specified range are partially or completely outside
87 the caller's address space.
91 was added in glibc 2.2.
95 POSIX.1 permits an implementation to generate an error if
100 as 0 is permitted (as a successful no-op).
102 In glibc, this function is implemented using
104 However, since glibc 2.6,
105 .B POSIX_MADV_DONTNEED
106 is treated as a no-op, because the corresponding
110 has destructive semantics.
113 .BR posix_fadvise (2)