1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2001 David Gómez <davidge@jazzfree.com>
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Based on comments from mm/filemap.c. Last modified on 10-06-2001
26 .\" Modified, 25 Feb 2002, Michael Kerrisk, <mtk.manpages@gmail.com>
27 .\" Added notes on MADV_DONTNEED
29 .TH MADVISE 2 2007-07-26 "Linux" "Linux Programmer's Manual"
31 madvise \- give advice about use of memory
34 .B #include <sys/mman.h>
36 .BI "int madvise(void *" start ", size_t " length ", int " advice );
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
48 system call advises the kernel about how to handle paging input/output in
49 the address range beginning at address
54 It allows an application to tell the kernel how it expects to use
55 some mapped or shared memory areas, so that the kernel can choose
56 appropriate read-ahead and caching techniques.
57 This call does not influence the semantics of the application
58 (except in the case of
61 may influence its performance.
62 The kernel is free to ignore the advice.
64 The advice is indicated in the
66 parameter which can be
73 Expect page references in random order.
74 (Hence, read ahead may be less useful than normally.)
77 Expect page references in sequential order.
78 (Hence, pages in the given range can be aggressively read ahead,
79 and may be freed soon after they are accessed.)
82 Expect access in the near future.
83 (Hence, it might be a good idea to read some pages ahead.)
86 Do not expect access in the near future.
87 (For the time being, the application is finished with the given range,
88 so the kernel can free resources associated with it.)
89 Subsequent accesses of pages in this range will succeed, but will result
90 either in re-loading of the memory contents from the underlying mapped file
93 or zero-fill-on-demand pages for mappings
94 without an underlying file.
96 .BR MADV_REMOVE " (Since Linux 2.6.16)"
97 Free up a given range of pages
98 and its associated backing store.
101 only shmfs/tmpfs supports this; other filesystems return with the
104 .\" Databases want to use this feature to drop a section of their
105 .\" bufferpool (shared memory segments) - without writing back to
106 .\" disk/swap space. This feature is also useful for supporting
107 .\" hot-plug memory on UML.
109 .BR MADV_DONTFORK " (Since Linux 2.6.16)"
110 .\" See http://lwn.net/Articles/171941/
111 Do not make the pages in this range available to the child after a
113 This is useful to prevent copy-on-write semantics from changing
114 the physical location of a page(s) if the parent writes to it after a
116 (Such page relocations cause problems for hardware that
117 DMAs into the page(s).)
118 .\" [PATCH] madvise MADV_DONTFORK/MADV_DOFORK
119 .\" Currently, copy-on-write may change the physical address of
120 .\" a page even if the user requested that the page is pinned in
121 .\" memory (either by mlock or by get_user_pages). This happens
122 .\" if the process forks meanwhile, and the parent writes to that
123 .\" page. As a result, the page is orphaned: in case of
124 .\" get_user_pages, the application will never see any data hardware
125 .\" DMA's into this page after the COW. In case of mlock'd memory,
126 .\" the parent is not getting the realtime/security benefits of mlock.
128 .\" In particular, this affects the Infiniband modules which do DMA from
129 .\" and into user pages all the time.
131 .\" This patch adds madvise options to control whether memory range is
132 .\" inherited across fork. Useful e.g. for when hardware is doing DMA
133 .\" from/into these pages. Could also be useful to an application
134 .\" wanting to speed up its forks by cutting large areas out of
137 .BR MADV_DOFORK " (Since Linux 2.6.16)"
140 restoring the default behavior, whereby a mapping is inherited across
146 On error, it returns \-1 and
148 is set appropriately.
152 A kernel resource was temporarily unavailable.
155 The map exists, but the area maps something that isn't a file.
166 is not a valid value, or the application is attempting
167 to release locked or shared pages (with
173 Paging in this area would exceed the process's
174 maximum resident set size.
179 Not enough memory: paging in failed.
182 Addresses in the specified range are not currently
183 mapped, or are outside the address space of the process.
186 POSIX.1-2001 describes
187 .BR posix_madvise (3)
189 .BR POSIX_MADV_NORMAL ,
191 with a behavior close to that described here.
193 .BR posix_fadvise (2)
204 The current Linux implementation (2.4.0) views this system call
205 more as a command than as advice and hence may return an error
206 when it cannot do what it usually would do in response to this
208 (See the ERRORS description above.)
209 This is nonstandard behavior.
211 The Linux implementation requires that the address
213 be page-aligned, and allows
216 If there are some parts of the specified address range
217 that are not mapped, the Linux version of
219 ignores them and applies the call to the rest (but returns
221 from the system call, as it should).
225 .\" function first appeared in 4.4BSD.