OSDN Git Service

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