1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2001 David Gez <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 .\" 2.6.32 added MADV_HWPOISON, MADV_MERGEABLE, and MADV_UNMERGEABLE
30 .\" 2.6.33 added MADV_SOFT_OFFLINE
32 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
33 .\" Translated Thu Aug 16 2001 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
34 .\" Updated Tue 8 Oct 2002 by NAKANO Takeo
35 .\" Updated 2007-01-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.43
37 .TH MADVISE 2 2008-04-22 "Linux" "Linux Programmer's Manual"
39 .\"O madvise \- give advice about use of memory
41 madvise \- ¥á¥â¥êÍøÍѤ˴ؤ¹¤ë¥¢¥É¥Ð¥¤¥¹¤òÍ¿¤¨¤ë
44 .B #include <sys/mman.h>
46 .BI "int madvise(void *" addr ", size_t " length ", int " advice );
49 .\"O Feature Test Macro Requirements for glibc (see
50 .\"O .BR feature_test_macros (7)):
51 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
52 .RB ( feature_test_macros (7)
62 .\"O system call advises the kernel about how to handle paging input/output in
63 .\"O the address range beginning at address
68 .\"O It allows an application to tell the kernel how it expects to use
69 .\"O some mapped or shared memory areas, so that the kernel can choose
70 .\"O appropriate read-ahead and caching techniques.
71 .\"O This call does not influence the semantics of the application
72 .\"O (except in the case of
73 .\"O .BR MADV_DONTNEED ),
75 .\"O may influence its performance.
76 .\"O The kernel is free to ignore the advice.
78 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¥¢¥É¥ì¥¹
82 ¥Ð¥¤¥È¤Î¥á¥â¥ê¥Ö¥í¥Ã¥¯¤Î¥Ú¡¼¥¸¥ó¥°Æþ½ÐÎϤò¤É¤¦°·¤¨¤ÐÎɤ¤¤«¡¢
83 ¥«¡¼¥Í¥ë¤Ë¥¢¥É¥Ð¥¤¥¹¤¹¤ë¡£
85 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤«¤é¥«¡¼¥Í¥ë¤Ë¡¢
86 ¥Þ¥Ã¥×¤µ¤ì¤¿¥á¥â¥ê¤ä¶¦Í¥á¥â¥ê¤ò¤É¤Î¤è¤¦¤Ë°·¤Ã¤Æ¤Û¤·¤¤¤«ÅÁ¤¨¤ë¤³¤È¤¬¤Ç¤¡¢
87 ¥«¡¼¥Í¥ë¤Ï¤½¤ì¤Ë±þ¤¸¤ÆÀèÆɤߤ䥥ã¥Ã¥·¥å¤Ê¤É¤ÎŬÀڤʼêË¡¤òÁªÂò¤Ç¤¤ë¡£
88 ¤³¤Î¥³¡¼¥ë¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÎÆ°ºî¤½¤Î¤â¤Î¤Ë¤Ï±Æ¶Á¤·¤Ê¤¤
92 ¤Ê¤ª¤³¤Î¥¢¥É¥Ð¥¤¥¹¤ò¼õ¤±Æþ¤ì¤ë¤«¤É¤¦¤«¤Ï¥«¡¼¥Í¥ë¤ËǤ¤µ¤ì¤ë¡£
94 .\"O The advice is indicated in the
96 .\"O argument which can be
99 ¤Ë¤è¤Ã¤ÆÍ¿¤¨¤ë¡£°Ê²¼¤Î¤¤¤º¤ì¤«¤ò»ØÄê¤Ç¤¤ë¡£
102 .\"O No special treatment.
103 .\"O This is the default.
104 ÆÃÊ̤ʰ·¤¤¤Ï¹Ô¤ï¤Ê¤¤¡£¤³¤ì¤¬¥Ç¥Õ¥©¥ë¥È¤Ç¤¢¤ë¡£
107 .\"O Expect page references in random order.
108 .\"O (Hence, read ahead may be less useful than normally.)
109 ¥Ú¡¼¥¸»²¾È¤Ï¥é¥ó¥À¥à¤Ê½ç½ø¤Ç¹Ô¤ï¤ì¤½¤¦¤À¡£
110 (¤·¤¿¤¬¤Ã¤Æ¡¢ÀèÆɤߤϤ¢¤Þ¤ê¸ú²Ì¤¬¤Ê¤µ¤½¤¦¤À¡£)
113 .\"O Expect page references in sequential order.
114 .\"O (Hence, pages in the given range can be aggressively read ahead,
115 .\"O and may be freed soon after they are accessed.)
116 ¥Ú¡¼¥¸»²¾È¤Ï¥·¡¼¥±¥ó¥·¥ã¥ë¤Ê½ç½ø¤Ç¹Ô¤ï¤ì¤½¤¦¤À¡£
117 (¤·¤¿¤¬¤Ã¤ÆÍ¿¤¨¤¿ÈϰϤΥڡ¼¥¸¤ÏÀѶËŪ¤ËÀèÆɤߤ·¤Æ¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦¡£
118 ¤Þ¤¿¥¢¥¯¥»¥¹¤¬½ª¤ï¤Ã¤¿¤é®¤ä¤«¤Ë²òÊü¤·¤ÆÎɤ¤¡£)
121 .\"O Expect access in the near future.
122 .\"O (Hence, it might be a good idea to read some pages ahead.)
123 ¶á¤¤¾Íè¤Ë¥¢¥¯¥»¥¹¤µ¤ì¤½¤¦¤À¡£
124 (¤·¤¿¤¬¤Ã¤Æ¤³¤ì¤é¤Î¥Ú¡¼¥¸¤òº£¤Î¤¦¤Á¤ËÀèÆɤߤ·¤Æ¤ª¤¯¤È¤¤¤¤¤À¤í¤¦¡£)
127 .\"O Do not expect access in the near future.
128 .\"O (For the time being, the application is finished with the given range,
129 .\"O so the kernel can free resources associated with it.)
130 ¤·¤Ð¤é¤¯¥¢¥¯¥»¥¹¤Ï¤Ê¤µ¤½¤¦¤À¡£
131 (¸½»þÅÀ¤Ç¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÏÍ¿¤¨¤¿ÈϰϤνèÍý¤ò½ª¤¨¤Æ¤¤¤ë¡£
132 ¤·¤¿¤¬¤Ã¤Æ¥«¡¼¥Í¥ë¤Ï¤³¤ì¤Ë´ØÏ¢¤¹¤ë¥ê¥½¡¼¥¹¤ò²òÊü¤·¤ÆÎɤ¤¡£)
133 .\"O Subsequent accesses of pages in this range will succeed, but will result
134 .\"O either in reloading of the memory contents from the underlying mapped file
137 .\"O or zero-fill-on-demand pages for mappings
138 .\"O without an underlying file.
139 ¤³¤ì°Ê¹ß¤³¤ÎÈϰϤΥڡ¼¥¸¤Ø¤Î¥¢¥¯¥»¥¹¤¬¤¢¤ë¤È¡¢
140 À®¸ù¤Ï¤¹¤ë¤¬¡¢¥á¥â¥ê¤ÎÆâÍƤò¥Þ¥Ã¥×¸µ¤Î¥Õ¥¡¥¤¥ë¤«¤é¥í¡¼¥É¤·Ä¾¤¹¤³¤È¤Ë¤Ê¤ë
143 ¤Þ¤¿¤Ï¸µ¥Õ¥¡¥¤¥ë¤¬¤Ê¤¤¥Þ¥Ã¥×¥Ú¡¼¥¸¤Ç¤Ï
144 ¥¢¥¯¥»¥¹¤¬¤¢¤Ã¤¿¤È¤¤Ë 0 Ëä¤á¤¬¹Ô¤ï¤ì¤ë¤³¤È¤Ë¤Ê¤ë¡£
146 .\"O .BR MADV_REMOVE " (Since Linux 2.6.16)"
147 .BR MADV_REMOVE " (Linux 2.6.16 °Ê¹ß)"
148 .\"O Free up a given range of pages
149 .\"O and its associated backing store.
152 .\"O only shmfs/tmpfs supports this; other file systems return with the
155 »ØÄꤵ¤ì¤¿ÈϰϤΥڡ¼¥¸¤È´ØÏ¢¤¹¤ë¥Ð¥Ã¥¥ó¥°¥¹¥È¥¢¤ò²òÊü¤¹¤ë¡£
158 shmfs/tmpfs ¤À¤±¤¬¤³¤ì¤ËÂбþ¤·¤Æ¤¤¤ë¡£
159 ¾¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï
162 .\" Databases want to use this feature to drop a section of their
163 .\" bufferpool (shared memory segments) - without writing back to
164 .\" disk/swap space. This feature is also useful for supporting
165 .\" hot-plug memory on UML.
167 .\"O .BR MADV_DONTFORK " (Since Linux 2.6.16)"
168 .BR MADV_DONTFORK " (Linux 2.6.16 °Ê¹ß)"
169 .\" See http://lwn.net/Articles/171941/
170 .\"O Do not make the pages in this range available to the child after a
172 .\"O This is useful to prevent copy-on-write semantics from changing
173 .\"O the physical location of a page(s) if the parent writes to it after a
175 .\"O (Such page relocations cause problems for hardware that
176 .\"O DMAs into the page(s).)
178 ¤¬¹Ô¤ï¤ì¤¿¸å¡¢»ØÄꤵ¤ì¤¿ÈϰϤΥڡ¼¥¸¤ò»Ò¥×¥í¥»¥¹¤¬ÍøÍѤǤ¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£
179 ¤³¤Îµ¡Ç½¤Ï¡¢½ñ¤¹þ¤ß»þ¥³¥Ô¡¼ (copy-on-write) Êý¼°¤Ç¡¢
181 ¤Î¸å¤Ç¿Æ¥×¥í¥»¥¹¤¬¥Ú¡¼¥¸¤Ë½ñ¤¹þ¤ß¤ò¹Ô¤Ã¤¿¾ì¹ç¤Ë
182 ¥Ú¡¼¥¸¤ÎʪÍý°ÌÃÖ¤¬ÊѲ½¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤Î¤Ë͸ú¤Ç¤¢¤ë
183 (¥Ú¡¼¥¸¤ÎºÆÇÛÃ֤ϥϡ¼¥É¥¦¥§¥¢¤¬¤½¤Î¥Ú¡¼¥¸¤Ë DMA žÁ÷¤ò¹Ô¤¦¤è¤¦¤Ê¾ì¹ç¤Ë
184 ÌäÂê¤òµ¯¤³¤¹¤³¤È¤¬¤¢¤ë)¡£
185 .\" [PATCH] madvise MADV_DONTFORK/MADV_DOFORK
186 .\" Currently, copy-on-write may change the physical address of
187 .\" a page even if the user requested that the page is pinned in
188 .\" memory (either by mlock or by get_user_pages). This happens
189 .\" if the process forks meanwhile, and the parent writes to that
190 .\" page. As a result, the page is orphaned: in case of
191 .\" get_user_pages, the application will never see any data hardware
192 .\" DMA's into this page after the COW. In case of mlock'd memory,
193 .\" the parent is not getting the realtime/security benefits of mlock.
195 .\" In particular, this affects the Infiniband modules which do DMA from
196 .\" and into user pages all the time.
198 .\" This patch adds madvise options to control whether memory range is
199 .\" inherited across fork. Useful e.g. for when hardware is doing DMA
200 .\" from/into these pages. Could also be useful to an application
201 .\" wanting to speed up its forks by cutting large areas out of
204 .\" SEE ALSO: http://lwn.net/Articles/171941/
205 .\" "Tweaks to madvise() and posix_fadvise()", 14 Feb 2006
207 .\"O .BR MADV_DOFORK " (Since Linux 2.6.16)"
208 .BR MADV_DOFORK " (Linux 2.6.16 °Ê¹ß)"
209 .\"O Undo the effect of
210 .\"O .BR MADV_DONTFORK ,
211 .\"O restoring the default behavior, whereby a mapping is inherited across
214 ¤Î±Æ¶Á¤ò¼è¤ê¾Ã¤·¡¢¥Ç¥Õ¥©¥ë¥È¤ÎÆ°ºî¤ËÌ᤹¡£
217 ¤ÎÁ°¸å¤Ç¥Þ¥Ã¥Ô¥ó¥°¤Ï·Ñ¾µ¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤ë¡£
218 .\"O .SH "RETURN VALUE"
223 .\"O On error, it returns \-1 and
225 .\"O is set appropriately.
227 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤¹¡£
228 ¥¨¥é¡¼¤¬µ¯¤³¤ë¤È \-1 ¤òÊÖ¤·¡¢
230 ¤òŬÀÚ¤ÊÃͤËÀßÄꤹ¤ë¡£
235 .\"O A kernel resource was temporarily unavailable.
236 ²¿¤é¤«¤Î¥«¡¼¥Í¥ë¥ê¥½¡¼¥¹¤¬°ì»þŪ¤ËÍøÍѤǤ¤Ê¤«¤Ã¤¿¡£
239 .\"O The map exists, but the area maps something that isn't a file.
240 »ØÄꤷ¤¿¥Þ¥Ã¥×¤Ï¸ºß¤¹¤ë¤¬¡¢¥Õ¥¡¥¤¥ë¤Ç¤Ï¤Ê¤¤¤È¤³¤í¤ò¥Þ¥Ã¥×¤·¤Æ¤¤¤ë¡£
249 .\"O is not page-aligned,
251 .\"O is not a valid value, or the application is attempting
252 .\"O to release locked or shared pages (with
253 .\"O .BR MADV_DONTNEED ).
260 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¥í¥Ã¥¯¤µ¤ì¤¿¥Ú¡¼¥¸¤ä¶¦Í¥Ú¡¼¥¸¤ò
262 ¤Ç) ²òÊü¤·¤è¤¦¤È¤·¤Æ¤¤¤ë¡¢¤Ê¤É¡£
266 .\"O .BR MADV_WILLNEED )
267 .\"O Paging in this area would exceed the process's
268 .\"O maximum resident set size.
270 ¤Î¾ì¹ç) ¤³¤ÎÈϰϤΥڡ¼¥¸¥ó¥°¤ò¹Ô¤¦¤È¡¢
271 ¥×¥í¥»¥¹¤Î RSS (resident set size) ¤ÎºÇÂçÃͤò±Û¤¨¤Æ¤·¤Þ¤¦¡£
272 .\"nakano RSS ¤ÏÌõ¸ì¤¬¤¢¤ê¤Þ¤·¤¿¤Ã¤±?
276 .\"O .BR MADV_WILLNEED )
277 .\"O Not enough memory: paging in failed.
279 ¤Î¾ì¹ç) ¥á¥â¥ê¤¬Â¤ê¤º¡¢¥Ú¡¼¥¸¥ó¥°¤Ë¼ºÇÔ¤·¤¿¡£
282 .\"O Addresses in the specified range are not currently
283 .\"O mapped, or are outside the address space of the process.
284 »ØÄꤷ¤¿ÈϰϤΥ¢¥É¥ì¥¹¤¬¡¢¸½ºß¥Þ¥Ã¥×¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
285 ¤¢¤ë¤¤¤Ï¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤ÎÆâÉô¤Ë¤Ê¤¤¡£
286 .\"O .SH "CONFORMING TO"
289 .\"O POSIX.1-2001 describes
290 .\"O .BR posix_madvise (3)
291 .\"O .\" FIXME . Write a posix_fadvise(3) page.
293 .\"O .BR POSIX_MADV_NORMAL ,
295 .\"O with a behavior close to that described here.
296 .\"O There is a similar
297 .\"O .BR posix_fadvise (2)
298 .\"O for file access.
300 .BR posix_madvise (3)
301 .\" FIXME . Write a posix_fadvise(3) page.
304 ¤Ê¤É¤ÎÄê¿ô¤È¤È¤â¤Ëµ½Ò¤·¤Æ¤¤¤¿
305 (¤½¤ì¤¾¤ì¤Î¿¶¤ëÉñ¤¤¤Ï¤³¤³¤Ç½Ò¤Ù¤¿¤â¤Î¤Ë¶á¤¤)¡£
306 ¥Õ¥¡¥¤¥ë¥¢¥¯¥»¥¹¤ËÂФ·¤Æ¤â
307 .BR posix_fadvise (2)
308 ¤È¤¤¤¦Îà»÷¤Î´Ø¿ô¤¬Â¸ºß¤¹¤ë¡£
310 .\"O .BR MADV_REMOVE ,
311 .\"O .BR MADV_DONTFORK ,
314 .\"O are Linux-specific.
318 ¤Ï Linux ¸ÇͤǤ¢¤ë¡£
320 .\"O .SS "Linux Notes"
324 .\"O The current Linux implementation (2.4.0) views this system call
325 .\"O more as a command than as advice and hence may return an error
326 .\"O when it cannot do what it usually would do in response to this
328 .\"O (See the ERRORS description above.)
329 .\"O This is nonstandard behavior.
330 ¸½ºß¤Î Linux ¤Î¼ÂÁõ (2.4.0) ¤Ç¤Ï¡¢
331 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥¢¥É¥Ð¥¤¥¹¤È¤¤¤¦¤è¤ê¤ÏÌ¿Îá¤È¸«¤Æ¤¤¤ë¡£
332 ¤·¤¿¤¬¤Ã¤Æ¤³¤Î¥¢¥É¥Ð¥¤¥¹¤ËÂФ·¤ÆÄ̾ï¹Ô¤ï¤ì¤ëÆ°ºî¤¬ÉÔ²Äǽ¤Ê¾ì¹ç¤Ï¡¢
333 ¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë (¾åµ¤Î ¥¨¥é¡¼ ¤Îµ½Ò¤ò»²¾È)¡£
334 ¤³¤Î¿¶Éñ¤¤¤Ïɸ½à¤È¤Ï°Û¤Ê¤ë¡£
336 .\"O The Linux implementation requires that the address
338 .\"O be page-aligned, and allows
341 .\"O If there are some parts of the specified address range
342 .\"O that are not mapped, the Linux version of
344 .\"O ignores them and applies the call to the rest (but returns
346 .\"O from the system call, as it should).
349 ¤Î¥¢¥É¥ì¥¹¤Ï¥Ú¡¼¥¸¶³¦¤ÎÃͤǤʤ±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤Þ¤¿
351 ¤Ï 0 ¤Ç¤¢¤Ã¤Æ¤â¹½¤ï¤Ê¤¤¡£
354 ¤Ç¤Ï¡¢»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹ÈϰϤ˥ޥåפµ¤ì¤Æ¤¤¤Ê¤¤Éôʬ¤¬¤¢¤ë¤È¡¢
355 ¤³¤ì¤é¤ò̵»ë¤·¤Æ»Ä¤ê¤ÎÉôʬ¤Ë¥¢¥É¥Ð¥¤¥¹¤òŬÍѤ¹¤ë
356 (¤·¤«¤·¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÂФ·¤Æ¤Ï¤Á¤ã¤ó¤È
362 .\"O .\" .BR madvise ()
363 .\"O .\" function first appeared in 4.4BSD.
365 .\" ´Ø¿ô¤Ï 4.4BSD ¤ÇºÇ½é¤ËÅо줷¤¿¡£