1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) Markus Kuhn, 1996
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, write to the Free
22 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
25 .\" 1995-11-26 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
26 .\" First version written
28 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
29 .\" all rights reserved.
30 .\" Translated Sun Feb 23 16:33:31 JST 1997
31 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
32 .\" Updated & Modified Fri May 21 03:32:57 JST 2004
33 .\" by Yuichi SATO <ysato444@yahoo.co.jp>
36 .\"WORD: process ¥×¥í¥»¥¹
37 .\"WORD: paging ¥Ú¡¼¥¸¥ó¥°
40 .\"WORD: stack ¥¹¥¿¥Ã¥¯
41 .\"WORD: segment ¥»¥°¥á¥ó¥È
42 .\"WORD: kernel ¥«¡¼¥Í¥ë
43 .\"WORD: shared memory ¶¦Í¥á¥â¥ê
44 .\"WORD: unlock ¥¢¥ó¥í¥Ã¥¯
45 .\"WORD: real-time ¥ê¥¢¥ë¡¦¥¿¥¤¥à
46 .\"WORD: algorithm ¥¢¥ë¥´¥ê¥º¥à
47 .\"WORD: security ¥»¥¥å¥ê¥Æ¥£
48 .\"WORD: scheduling ¥¹¥±¥¸¥å¡¼¥ê¥ó¥°
49 .\"WORD: password ¥Ñ¥¹¥ï¡¼¥É
50 .\"WORD: secret key ÈëÌ©¸°
51 .\"WORD: heap ¥Ò¡¼¥×(heap)
52 .\"WORD: automatic variable ¼«Æ°ÊÑ¿ô
53 .\"WORD: copy-on-write ½ñ¤¹þ¤ß»þ¥³¥Ô¡¼
55 .\"WORD: root ¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼
57 .TH MLOCKALL 2 1995-11-26 "Linux 1.3.43" "Linux Programmer's Manual"
60 .\"O mlockall \- disable paging for calling process
61 mlockall \- ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥Ú¡¼¥¸¥ó¥°¤ò¶Ø»ß¤¹¤ë
65 .B #include <sys/mman.h>
67 \fBint mlockall(int \fIflags\fB);
72 .\"O disables paging for all pages mapped into the address space of the
73 .\"O calling process. This includes the pages of the code, data and stack
74 .\"O segment, as well as shared libraries, user space kernel data, shared
75 .\"O memory and memory mapped files. All mapped pages are guaranteed to be
76 .\"O resident in RAM when the
78 .\"O system call returns successfully and they are guaranteed to stay in RAM
79 .\"O until the pages are unlocked again by
83 .\"O or until the process terminates or starts another program with
86 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë¥Þ¥Ã¥×¤µ¤ì¤Æ¤¤¤ëÁ´¤Æ¤Î¥Ú¡¼¥¸¤Î
87 ¥Ú¡¼¥¸¥ó¥° (paging) ¤ò¶Ø»ß¤¹¤ë¡£¤³¤ì¤Ë¤Ï¥³¡¼¥É¡¢¥Ç¡¼¥¿¡¢¥¹¥¿¥Ã¥¯¤Î
88 ³Æ¥»¥°¥á¥ó¥È¡¢¶¦Í¥é¥¤¥Ö¥é¥ê¡¢¥«¡¼¥Í¥ë¤Î¥æ¡¼¥¶¡¼¶õ´Ö¥Ç¡¼¥¿¡¢
89 ¶¦Í¥á¥â¥ê¡¢¥á¥â¥ê¡¦¥Þ¥Ã¥×¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ò´Þ¤ó¤Ç¤¤¤ë¡£
91 ¥·¥¹¥Æ¥à¡¦¥³¡¼¥ë¤¬À®¸ù¤·¤¿¾ì¹ç¤Ë¤ÏÁ´¤Æ¤Î¥Þ¥Ã¥×¤µ¤ì¤¿¥Ú¡¼¥¸¤Ï RAM ¤Ë
92 »Ä¤ê³¤±¤ë¤³¤È¤òÊݾڤµ¤ì¤ë¡¢¤½¤·¤Æ
96 ¤Ë¤è¤Ã¤Æ¥Ú¡¼¥¸¤¬¥¢¥ó¥í¥Ã¥¯¤µ¤ì¤¿¤ê¡¢¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿¤ê¡¢
98 ¤Ë¤è¤Ã¤Æ¾¤Î¥×¥í¥°¥é¥à¤ò³«»Ï¤·¤¿¤ê¤¹¤ë¤Þ¤Ç¤Ï RAM ¤Ë»Ä¤ë¤³¤È¤¬
100 .\"O Child processes do not inherit page locks across a
103 ¤ò¹Ô¤Ê¤Ã¤¿¾ì¹ç¤Ë»Ò¥×¥í¥»¥¹¤Ï¥Ú¡¼¥¸¤Î¥í¥Ã¥¯¤ò·Ñ¾µ¤·¤Ê¤¤¡£
105 .\"O Memory locking has two main applications: real-time algorithms and
106 .\"O high-security data processing. Real-time applications require
107 .\"O deterministic timing, and, like scheduling, paging is one major cause
108 .\"O of unexpected program execution delays. Real-time applications will
109 .\"O usually also switch to a real-time scheduler with
110 .\"O .BR sched_setscheduler .
111 ¥á¥â¥ê¤Î¥í¥Ã¥¯¤Ë¤Ï¼ç¤ËÆó¤Ä¤Î»È¤¤Æ»¤¬¤¢¤ë¡£¥ê¥¢¥ë¡¦¥¿¥¤¥à (real-time)
112 ¥¢¥ë¥´¥ê¥º¥à¤È¹â¤¤¥»¥¥å¥ê¥Æ¥£¤Î¥Ç¡¼¥¿½èÍý¤Ç¤¢¤ë¡£¥ê¥¢¥ë¡¦¥¿¥¤¥à¤Î
113 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï·èÄêŪ¤Ê¥¿¥¤¥ß¥ó¥°¤ä¥¹¥±¥¸¥å¡¼¥ê¥ó¥°¤òÍ׵ᤷ¡¢
114 ¥Ú¡¼¥¸¥ó¥°¤Ïͽ´ü¤·¤Ê¤¤¥×¥í¥°¥é¥à¤Î¼Â¹ÔÃÙ¤ì¤ò¤â¤¿¤é¤¹½ÅÍפÊÍ×°ø¤Ç¤¢¤ë¡£
115 ¥ê¥¢¥ë¡¦¥¿¥¤¥à¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¤¿¤¤¤Æ¤¤¤Ï
116 .BR sched_setscheduler
117 ¤Ç¥ê¥¢¥ë¡¦¥¿¥¤¥à¡¦¥¹¥±¥¸¥å¥é¡¼¤ËÊѹ¹¤µ¤ì¤ë¡£
118 .\"O Cryptographic security software often handles critical bytes like
119 .\"O passwords or secret keys as data structures. As a result of paging,
120 .\"O these secrets could be transfered onto a persistent swap store medium,
121 .\"O where they might be accessible to the enemy long after the security
122 .\"O software has erased the secrets in RAM and terminated. For security
123 .\"O applications, only small parts of memory have to be locked, for which
126 °Å¹æ¤ä¥»¥¥å¥ê¥Æ¥£¤Î¥½¥Õ¥È¥¦¥§¥¢¤Ï¤·¤Ð¤·¤Ð¥Ñ¥¹¥ï¡¼¥É¤äÈëÌ©¸°¤Î¥Ç¡¼¥¿¤Î
127 ¤è¤¦¤Ê½ÅÍפʥХ¤¥È¤ò°·¤¦¡£¥Ú¡¼¥¸¥ó¥°¤Î·ë²Ì¡¢¤³¤ì¤é¤ÎÈëÌ©¤¬
128 ¥¹¥ï¥Ã¥×ÍѤθÇÄêÇÞÂΤËžÁ÷¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£¤½¤·¤Æ¤½¤ì¤Ï¥»¥¥å¥ê¥Æ¥£
129 ¡¦¥½¥Õ¥È¥¦¥§¥¢¤¬ RAM ¾å¤ÎÈëÌ©¤òºï½ü¤·¤Æ½ªÎ»¤·¤¿¤º¤Ã¤È¸å¤Ë¤Ç¤âŨ¤Ë¤è¤Ã¤Æ
130 ¥¢¥¯¥»¥¹¤¬²Äǽ¤Ë¤Ê¤ë¤«¤â¤·¤ì¤Ê¤¤¡£¥»¥¥å¥ê¥Æ¥£¡¦¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï
131 ¥á¥â¥ê¤Î¤Û¤ó¤Î¾®¤µ¤ÊÉôʬ¤Î¤ß¤¬¥í¥Ã¥¯¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤½¤Î¤¿¤á¤Ë
137 .\"O parameter can be constructed from the bitwise OR of the following
140 ¥Ñ¥é¥á¡¼¥¿¡¼¤Ï°Ê²¼¤ÎÆâÍÆ¤Î¥Ó¥Ã¥È OR ¤«¤é¤Ê¤ë:
143 .\"O Lock all pages which are currently mapped into the address space of
145 ¸½ºß¡¢¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë¥Þ¥Ã¥×¤µ¤ì¤Æ¤¤¤ëÁ´¤Æ¤Î¥Ú¡¼¥¸¤ò¥í¥Ã¥¯¤¹¤ë¡£
148 .\"O Lock all pages which will become mapped into the address space of the
149 .\"O process in the future. These could be for instance new pages required
150 .\"O by a growing heap and stack as well as new memory mapped files or
151 .\"O shared memory regions.
152 ¾Íè¡¢¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë¥Þ¥Ã¥×¤µ¤ì¤ëÁ´¤Æ¤Î¥Ú¡¼¥¸¤ò¥í¥Ã¥¯¤¹¤ë¡£
153 ¤³¤ì¤ÏÎ㤨¤Ð¡¢À®Ä¹¤¹¤ë¥Ò¡¼¥× (heap) ¤ä¥¹¥¿¥Ã¥¯¤Î¾¤Ë
154 ¿·¤·¤¤¥á¥â¥ê¡¦¥Þ¥Ã¥×¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ä¶¦Í¥á¥â¥êÎΰè¤Ê¤É¤ËɬÍפȤʤ롣
158 .\"O has been specified and the number of locked pages exceeds the upper
159 .\"O limit of allowed locked pages, then the system call which caused the
160 .\"O new mapping will fail with
163 ¤¬»ØÄꤵ¤ì¤Æ¤ª¤ê¡¢¥í¥Ã¥¯¤µ¤ì¤¿¥Ú¡¼¥¸¤Î¿ô¤¬¥í¥Ã¥¯¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¥Ú¡¼¥¸¿ô¤Î
164 ¾å¸Â¤òĶ¤¨¤¿¾ì¹ç¤Ë¤Ï¡¢¿·¤·¤¯¥Ú¡¼¥¸¤ò¥Þ¥Ã¥×¤¹¤ë¥·¥¹¥Æ¥à¡¦¥³¡¼¥ë¤Ï
167 .\"O If these new pages have been mapped by the the growing stack, then the
168 .\"O kernel will deny stack expansion and send a
170 À®Ä¹¤¹¤ë¥¹¥¿¥Ã¥¯¤Ë¤è¤Ã¤Æ¿·¤·¤¤¥Ú¡¼¥¸¤¬¥Þ¥Ã¥×¤µ¤ì¤ë¾ì¹ç¤Ï¡¢¥«¡¼¥Í¥ë¤Ï
171 ¥¹¥¿¥Ã¥¯¤Î³ÈÄ¥¤òµñÈݤ·¡¢
175 .\"O Real-time processes should reserve enough locked stack pages before
176 .\"O entering the time-critical section, so that no page fault can be
177 .\"O caused by function calls. This can be achieved by calling a function
178 .\"O which has a sufficiently large automatic variable and which writes to
179 .\"O the memory occupied by this large array in order to touch these stack
180 .\"O pages. This way, enough pages will be mapped for the stack and can be
181 .\"O locked into RAM. The dummy writes ensure that not even copy-on-write
182 .\"O page faults can occur in the critical section.
183 ¥ê¥¢¥ë¡¦¥¿¥¤¥à¡¦¥×¥í¥»¥¹¤Ï´Ø¿ô¸Æ¤Ó½Ð¤·¤Ç¥Ú¡¼¥¸¡¦¥Õ¥©¡¼¥ë¥È¤¬È¯À¸¤·¤Ê¤¤
184 ¤è¤¦¤Ë»þ´Ö¤¬Ã×̿Ū¤ÊÉôʬ¤ËÆþ¤ëÁ°¤Ë½½Ê¬¤Ê¥í¥Ã¥¯¤µ¤ì¤¿¥¹¥¿¥Ã¥¯¤ò³ÎÊݤ·¤Æ
185 ¤ª¤¯É¬Íפ¬¤¢¤ë¡£¤³¤ì¤Ï½½Ê¬¤ËÂ礤ʼ«Æ°ÊÑ¿ô¤ò³ÎÊݤ¹¤ë´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¡¢
186 ¤³¤ì¤é¤Î¥¹¥¿¥Ã¥¯ÍѤΥڡ¼¥¸¤¬¥á¥â¥ê¤Ë³ÎÊݤµ¤ì¤ë¤è¤¦¤Ë¤³¤ÎÂ礤ÊÇÛÎó¤Ë
187 ½ñ¤¹þ¤ß¤ò¹Ô¤Ê¤¦¤³¤È¤Ë¤è¤Ã¤ÆãÀ®¤Ç¤¤ë¡£¤³¤ÎÊýË¡¤Ë¤è¤Ã¤Æ½½Ê¬¤Ê¥Ú¡¼¥¸¤¬
188 ¥¹¥¿¥Ã¥¯¤Ë¥Þ¥Ã¥×¤µ¤ì¡¢RAM ¤Ë¥í¥Ã¥¯¤µ¤ì¤ë¡£¥À¥ß¡¼¤Î½ñ¤¹þ¤ß¤ÏÃ×̿Ū¤Ê
189 Éôʬ¤Ç½ñ¤¹þ¤ß»þ¥³¥Ô¡¼ (copy-on-write) ¤Ë¤è¤ë¥Ú¡¼¥¸¡¦¥Õ¥©¡¼¥ë¥È¤µ¤¨
190 µ¯¤¤Ê¤¤¤³¤È¤òÊݾڤ¹¤ë¡£
192 .\"O Memory locks do not stack, i.e., pages which have been locked several times
197 .\"O will be unlocked by a single call to
198 .\"O .BR munlockall .
199 ¥á¥â¥ê¤Î¥í¥Ã¥¯ (lock) ¤ÏÎßÀѤ·¤Ê¤¤¡£Î㤨¤ÐÊ£¿ô²ó
203 ¤ò¸Æ¤Ó½Ð¤·¤Æ¥í¥Ã¥¯¤µ¤ì¤¿¥Ú¡¼¥¸¤â°ì²ó¤Î
205 ¤Ë¤è¤Ã¤Æ¥¢¥ó¥í¥Ã¥¯ (unlock) ¤µ¤ì¤ë¡£
206 .\"O Pages which are mapped to several locations or by several processes stay
207 .\"O locked into RAM as long as they are locked at least at one location or by
208 .\"O at least one process.
209 Ê£¿ô¤Î¾ì½ê¤äÊ£¿ô¤Î¥×¥í¥»¥¹¤Ë¥Þ¥Ã¥×¤µ¤ì¤Æ¤¤¤ë¥Ú¡¼¥¸¤Ï¡¢¾¯¤Ê¤¯¤È¤â°ì¤Ä¤Î¾ì½ê¡¢
210 °ì¤Ä¤Î¥×¥í¥»¥¹¤Ç¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤ë¸Â¤ê¤Ï RAM ¤Ë»Ä¤ê³¤±¤ë¡£
211 .\"O .SH "RETURN VALUE"
215 .\"O returns zero. On error, \-1 is returned, and
217 .\"O is set appropriately.
220 ¤Ï¥¼¥í¤òÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢\-1 ¤¬ÊÖ¤µ¤ì¡¢
227 .\"O The process tried to exceed the maximum number of allowed locked
229 µö¤µ¤ì¤ë¾å¸Â¤òĶ¤¨¤ë¿ô¤Î¥Ú¡¼¥¸¤ò¥í¥Ã¥¯¤·¤è¤¦¤È¤·¤¿¡£
232 .\"O The calling process does not have appropriate privileges. Only root
233 .\"O processes are allowed to lock pages.
234 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤¬Å¬ÀÚ¤ÊÆø¢¤ò½êͤ·¤Æ¤¤¤Ê¤¤¡£
235 ¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼¤Î¥×¥í¥»¥¹¤Î¤ß¤¬¥Ú¡¼¥¸¤ò¥í¥Ã¥¯¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
238 .\"O Unknown flags were specified.
239 ̤ÃΤΥե饰¤¬»ØÄꤵ¤ì¤¿¡£
240 .\"O .SH AVAILABILITY
242 .\"O On POSIX systems on which
247 .\"O .B _POSIX_MEMLOCK
248 .\"O is defined in <unistd.h> to a value greater than 0. (See also
249 .\"O .BR sysconf (3).)
253 ¤¬ÍøÍѲÄǽ¤Ê POSIX ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢
256 ¤¬ 0 ¤è¤êÂ礤¤ÃͤËÄêµÁ¤µ¤ì¤Æ¤¤¤ë
259 .\"O .\" POSIX 1003.1-2001: It shall be defined to -1 or 0 or 200112L.
260 .\"O .\" -1: unavailable, 0: ask using sysconf().
261 .\"O .\" glibc defines it to 1.
262 .\" POSIX 1003.1-2001 ¤Ç¤Ï¡¢¤³¤ÎÃͤò -1, 0, 200112L ¤Î
263 .\" ¤É¤ì¤«¤ËÄêµÁ¤¹¤Ù¤¤È¤·¤Æ¤¤¤ë¡£
264 .\" -1 ¤Ï»ÈÍÑÉԲġ¢0 ¤Ï sysconf() ¤ò»È¤Ã¤Æ¿Ò¤Í¤ë¤È¤¤¤¦°ÕÌ£¤Ç¤¢¤ë¡£
265 .\" glibc ¤Ç¤Ï¡¢¤³¤ÎÃͤò 1 ¤È¤·¤Æ¤¤¤ë¡£
266 .\"O .SH "CONFORMING TO"
268 .\"O POSIX.1b, SVr4. SVr4 documents an additional EAGAIN error code.
269 POSIX.1b, SVR4. SVr4 ¤Ë¤Ï¾¤Ë EAGAIN ¥¨¥é¡¼¤Ë¤Ä¤¤¤Æ¤Îµ½Ò¤¬¤¢¤ë¡£