OSDN Git Service

(split) LDP: Update release pages based on LDP 3.54 release
[linuxjm/LDP_man-pages.git] / release / man2 / madvise.2
1 .\" Copyright (C) 2001 David Gómez <davidge@jazzfree.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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
28 .\" 2010-06-19, mtk, Added documentation of MADV_MERGEABLE and
29 .\"     MADV_UNMERGEABLE
30 .\" 2010-06-15, Andi Kleen, Add documentation of MADV_HWPOISON.
31 .\" 2010-06-19, Andi Kleen, Add documentation of MADV_SOFT_OFFLINE.
32 .\" 2011-09-18, Doug Goldstein <cardoe@cardoe.com>
33 .\"     Document MADV_HUGEPAGE and MADV_NOHUGEPAGE
34 .\"
35 .\"*******************************************************************
36 .\"
37 .\" This file was generated with po4a. Translate the source file.
38 .\"
39 .\"*******************************************************************
40 .\"
41 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
42 .\" Translated Thu Aug 16 2001 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
43 .\" Updated Tue 8 Oct 2002 by NAKANO Takeo
44 .\" Updated 2007-01-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.43
45 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
46 .\" Updated 2013-07-31, Akihiro MOTOKI <amotoki@gmail.com>
47 .\"
48 .TH MADVISE 2 2012\-04\-28 Linux "Linux Programmer's Manual"
49 .SH 名前
50 madvise \- メモリ利用に関するアドバイスを与える
51 .SH 書式
52 \fB#include <sys/mman.h>\fP
53 .sp
54 \fBint madvise(void *\fP\fIaddr\fP\fB, size_t \fP\fIlength\fP\fB, int \fP\fIadvice\fP\fB);\fP
55 .sp
56 .in -4n
57 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
58 .in
59 .sp
60 \fBmadvise\fP(): _BSD_SOURCE
61 .SH 説明
62 \fBmadvise\fP()  システムコールは、アドレス \fIaddr\fP からはじまる \fIlength\fP
63 バイトのメモリブロックのページング入出力をどう扱えば良いか、 カーネルにアドバイスする。 これを用いると、 アプリケーションからカーネルに、
64 マップされたメモリや共有メモリをどのように扱ってほしいか伝えることができ、 カーネルはそれに応じて先読みやキャッシュなどの適切な手法を選択できる。
65 このコールはアプリケーションの動作そのものには影響しない (\fBMADV_DONTNEED\fP の場合は別) が、 性能には影響しうる。
66 なおこのアドバイスを受け入れるかどうかはカーネルに任される。
67 .LP
68 アドバイスは引き数 \fIadvice\fP によって与える。以下のいずれかを指定できる。
69 .TP 
70 \fBMADV_NORMAL\fP
71 特別な扱いは行わない。これがデフォルトである。
72 .TP 
73 \fBMADV_RANDOM\fP
74 ページ参照はランダムな順序で行われそうだ。 (したがって、先読みはあまり効果がなさそうだ。)
75 .TP 
76 \fBMADV_SEQUENTIAL\fP
77 ページ参照はシーケンシャルな順序で行われそうだ。 (したがって与えた範囲のページは積極的に先読みしておくと良いだろう。
78 またアクセスが終わったら速やかに解放して良い。)
79 .TP 
80 \fBMADV_WILLNEED\fP
81 近い将来にアクセスされそうだ。 (したがってこれらのページを今のうちに先読みしておくといいだろう。)
82 .TP 
83 \fBMADV_DONTNEED\fP
84 しばらくアクセスはなさそうだ。 (現時点でアプリケーションは与えた範囲の処理を終えている。 したがってカーネルはこれに関連するリソースを解放して良い。)
85 これ以降この範囲のページへのアクセスがあると、 成功はするが、メモリの内容をマップ元のファイルからロードし直すことになる (\fBmmap\fP(2)
86 を見よ) か、 または元ファイルがないマップページでは アクセスがあったときに 0 埋めが行われることになる。
87 .TP 
88 \fBMADV_REMOVE\fP (Linux 2.6.16 以降)
89 .\" 2.6.18-rc5
90 .\" Databases want to use this feature to drop a section of their
91 .\" bufferpool (shared memory segments) - without writing back to
92 .\" disk/swap space.  This feature is also useful for supporting
93 .\" hot-plug memory on UML.
94 Free up a given range of pages and its associated backing store.  Currently,
95 only shmfs/tmpfs supports this; other filesystems return with the error
96 \fBENOSYS\fP.
97 .TP 
98 \fBMADV_DONTFORK\fP (Linux 2.6.16 以降)
99 .\" See http://lwn.net/Articles/171941/
100 .\" [PATCH] madvise MADV_DONTFORK/MADV_DOFORK
101 .\" Currently, copy-on-write may change the physical address of
102 .\" a page even if the user requested that the page is pinned in
103 .\" memory (either by mlock or by get_user_pages).  This happens
104 .\" if the process forks meanwhile, and the parent writes to that
105 .\" page.  As a result, the page is orphaned: in case of
106 .\" get_user_pages, the application will never see any data hardware
107 .\" DMA's into this page after the COW.  In case of mlock'd memory,
108 .\" the parent is not getting the realtime/security benefits of mlock.
109 .\"
110 .\" In particular, this affects the Infiniband modules which do DMA from
111 .\" and into user pages all the time.
112 .\"
113 .\" This patch adds madvise options to control whether memory range is
114 .\" inherited across fork. Useful e.g. for when hardware is doing DMA
115 .\" from/into these pages.  Could also be useful to an application
116 .\" wanting to speed up its forks by cutting large areas out of
117 .\" consideration.
118 .\"
119 .\" SEE ALSO: http://lwn.net/Articles/171941/
120 .\" "Tweaks to madvise() and posix_fadvise()", 14 Feb 2006
121 \fBfork\fP(2)  が行われた後、指定された範囲のページを子プロセスが利用できないようにする。 この機能は、書き込み時コピー
122 (copy\-on\-write) 方式で、 \fBfork\fP(2)  の後で親プロセスがページに書き込みを行った場合に
123 ページの物理位置が変化しないようにするのに有効である (ページの再配置はハードウェアがそのページに DMA 転送を行うような場合に
124 問題を起こすことがある)。
125 .TP 
126 \fBMADV_DOFORK\fP (Linux 2.6.16 以降)
127 \fBMADV_DONTFORK\fP の影響を取り消し、デフォルトの動作に戻す。 つまり、 \fBfork\fP(2)
128 の前後でマッピングは継承されるようになる。
129 .TP 
130 \fBMADV_HWPOISON\fP (Linux 2.6.32 以降)
131 Poison a page and handle it like a hardware memory corruption.  This
132 operation is available only for privileged (\fBCAP_SYS_ADMIN\fP)  processes.
133 This operation may result in the calling process receiving a \fBSIGBUS\fP and
134 the page being unmapped.  This feature is intended for testing of memory
135 error\-handling code; it is available only if the kernel was configured with
136 \fBCONFIG_MEMORY_FAILURE\fP.
137 .TP 
138 \fBMADV_SOFT_OFFLINE\fP (Linux 2.6.33 以降)
139 Soft offline the pages in the range specified by \fIaddr\fP and \fIlength\fP.  The
140 memory of each page in the specified range is preserved (i.e., when next
141 accessed, the same content will be visible, but in a new physical page
142 frame), and the original page is offlined (i.e., no longer used, and taken
143 out of normal memory management).  The effect of the \fBMADV_SOFT_OFFLINE\fP
144 operation is invisible to (i.e., does not change the semantics of)  the
145 calling process.  This feature is intended for testing of memory
146 error\-handling code; it is available only if the kernel was configured with
147 \fBCONFIG_MEMORY_FAILURE\fP.
148 .TP 
149 \fBMADV_MERGEABLE\fP (Linux 2.6.32 以降)
150 Enable Kernel Samepage Merging (KSM) for the pages in the range specified by
151 \fIaddr\fP and \fIlength\fP.  The kernel regularly scans those areas of user
152 memory that have been marked as mergeable, looking for pages with identical
153 content.  These are replaced by a single write\-protected page (which is
154 automatically copied if a process later wants to update the content of the
155 page).  KSM merges only private anonymous pages (see \fBmmap\fP(2)).  The KSM
156 feature is intended for applications that generate many instances of the
157 same data (e.g., virtualization systems such as KVM).  It can consume a lot
158 of processing power; use with care.  See the Linux kernel source file
159 \fIDocumentation/vm/ksm.txt\fP for more details.  The \fBMADV_MERGEABLE\fP and
160 \fBMADV_UNMERGEABLE\fP operations are available only if the kernel was
161 configured with \fBCONFIG_KSM\fP.
162 .TP 
163 \fBMADV_UNMERGEABLE\fP (Linux 2.6.32 以降)
164 Undo the effect of an earlier \fBMADV_MERGEABLE\fP operation on the specified
165 address range; KSM unmerges whatever pages it had merged in the address
166 range specified by \fIaddr\fP and \fIlength\fP.
167 .TP 
168 \fBMADV_HUGEPAGE\fP (Linux 2.6.38 以降)
169 .\" http://lwn.net/Articles/358904/
170 .\" https://lwn.net/Articles/423584/
171 Enables Transparent Huge Pages (THP) for pages in the range specified by
172 \fIaddr\fP and \fIlength\fP.  Currently, Transparent Huge Pages work only with
173 private anonymous pages (see \fBmmap\fP(2)).  The kernel will regularly scan
174 the areas marked as huge page candidates to replace them with huge pages.
175 The kernel will also allocate huge pages directly when the region is
176 naturally aligned to the huge page size (see \fBposix_memalign\fP(2)).  This
177 feature is primarily aimed at applications that use large mappings of data
178 and access large regions of that memory at a time (e.g., virtualization
179 systems such as QEMU).  It can very easily waste memory (e.g., a 2MB mapping
180 that only ever accesses 1 byte will result in 2MB of wired memory instead of
181 one 4KB page).  See the Linux kernel source file
182 \fIDocumentation/vm/transhuge.txt\fP for more details.  The \fBMADV_HUGEPAGE\fP
183 and \fBMADV_NOHUGEPAGE\fP operations are available only if the kernel was
184 configured with \fBCONFIG_TRANSPARENT_HUGEPAGE\fP.
185 .TP 
186 \fBMADV_NOHUGEPAGE\fP (Linux 2.6.38 以降)
187 Ensures that memory in the address range specified by \fIaddr\fP and \fIlength\fP
188 will not be collapsed into huge pages.
189 .TP 
190 \fBMADV_DONTDUMP\fP (Linux 3.4 以降)
191 Exclude from a core dump those pages in the range specified by \fIaddr\fP and
192 \fIlength\fP.  This is useful in applications that have large areas of memory
193 that are known not to be useful in a core dump.  The effect of
194 \fBMADV_DONTDUMP\fP takes precedence over the bit mask that is set via the
195 \fI/proc/PID/coredump_filter\fP file (see \fBcore\fP(5)).
196 .TP 
197 \fBMADV_DODUMP\fP (Linux 3.4 以降)
198 Undo the effect of an earlier \fBMADV_DONTDUMP\fP.
199 .SH 返り値
200 \fBmadvise\fP()  は成功すると 0 を返す。 エラーが起こると \-1 を返し、 \fIerrno\fP を適切な値に設定する。
201 .SH エラー
202 .TP 
203 \fBEAGAIN\fP
204 何らかのカーネルリソースが一時的に利用できなかった。
205 .TP 
206 \fBEBADF\fP
207 指定したマップは存在するが、ファイルではないところをマップしている。
208 .TP 
209 \fBEINVAL\fP
210 このエラーは以下の理由で発生する。
211 .RS
212 .IP * 3
213 .\" .I len
214 .\" is zero,
215 \fIlen\fP が負の値である。
216 .IP *
217 \fIaddr\fP がページ境界ではない。
218 .IP *
219 \fIadvice\fP が有効な値でない。
220 .IP *
221 アプリケーションがロックされたページや共有ページを (\fBMADV_DONTNEED\fP で) 解放
222 しようとしている。
223 .IP *
224 \fIadvice\fP に \fBMADV_MERGEABLE\fP か \fBMADV_UNMERGEABLE\fP が指定されたが、 カーネルの設定が
225 \fBCONFIG_KSM\fP が有効になっていなかった。
226 .RE
227 .TP 
228 \fBEIO\fP
229 (\fBMADV_WILLNEED\fP の場合) この範囲のページングを行うと、 プロセスの RSS (resident set size)
230 の最大値を越えてしまう。
231 .TP 
232 \fBENOMEM\fP
233 (\fBMADV_WILLNEED\fP の場合) メモリが足りず、ページングに失敗した。
234 .TP 
235 \fBENOMEM\fP
236 指定した範囲のアドレスが、現在マップされていない。 あるいはプロセスのアドレス空間の内部にない。
237 .SH 準拠
238 .\" FIXME . Write a posix_madvise(3) page.
239 POSIX.1b.  POSIX.1\-2001 では、 \fBposix_madvise\fP(3)  を \fBPOSIX_MADV_NORMAL\fP
240 などの定数とともに記述していた (それぞれの振る舞いはここで述べたものに近い)。 ファイルアクセスに対しても \fBposix_fadvise\fP(2)
241 という類似の関数が存在する。
242
243 \fBMADV_REMOVE\fP, \fBMADV_DONTFORK\fP, \fBMADV_DOFORK\fP, \fBMADV_HWPOISON\fP,
244 \fBMADV_MERGEABLE\fP, \fBMADV_UNMERGEABLE\fP は Linux 固有である。
245 .SH 注意
246 .SS "Linux での注意"
247 .LP
248 現在の Linux の実装 (2.4.0) では、 このシステムコールをアドバイスというよりは命令と見ている。
249 したがってこのアドバイスに対して通常行われる動作が不可能な場合は、 エラーを返すことがある (上記の エラー の記述を参照)。
250 この振舞いは標準とは異なる。
251 .LP
252 .\" .SH HISTORY
253 .\" The
254 .\" .BR madvise ()
255 .\" function first appeared in 4.4BSD.
256 Linux の実装では \fIaddr\fP のアドレスはページ境界の値でなければならない。また \fIlength\fP は 0 であっても構わない。 また
257 Linux 版の \fBmadvise\fP()  では、指定されたアドレス範囲にマップされていない部分があると、
258 これらを無視して残りの部分にアドバイスを適用する (しかしシステムコールに対してはちゃんと \fBENOMEM\fP を返す)。
259 .SH 関連項目
260 \fBgetrlimit\fP(2), \fBmincore\fP(2), \fBmmap\fP(2), \fBmprotect\fP(2), \fBmsync\fP(2),
261 \fBmunmap\fP(2), \fBcore\fP(5)
262 .SH この文書について
263 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
264 である。プロジェクトの説明とバグ報告に関する情報は
265 http://www.kernel.org/doc/man\-pages/ に書かれている。