OSDN Git Service

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