OSDN Git Service

(split) LDP man-pages の original/ を v3.25 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / swapon.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1995-07-22 by Michael Chastain <mec@duracef.shout.net>
28 .\" Modified 1995-07-23 by aeb
29 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1998-09-08 by aeb
31 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" Modified 2004-10-10 by aeb
33 .\" 2004-12-14 mtk, Anand Kumria: added new errors
34 .\" 2007-06-22 Ivana Varekova <varekova@redhat.com>, mtk
35 .\"     Update text describing limit on number of swap files.
36 .\"
37 .TH SWAPON 2 2010-06-15 "Linux" "Linux Programmer's Manual"
38 .SH NAME
39 swapon, swapoff \- start/stop swapping to file/device
40 .SH SYNOPSIS
41 .B #include <unistd.h>
42 .br
43 .B #include <asm/page.h>     /* to find PAGE_SIZE */
44 .br
45 .B #include <sys/swap.h>
46 .sp
47 .BI "int swapon(const char *" path ", int " swapflags );
48 .br
49 .BI "int swapoff(const char *" path );
50 .SH DESCRIPTION
51 .BR swapon ()
52 sets the swap area to the file or block device specified by
53 .IR path .
54 .BR swapoff ()
55 stops swapping to the file or block device specified by
56 .IR path .
57 .PP
58 .BR swapon ()
59 takes a
60 .I swapflags
61 argument.
62 If
63 .I swapflags
64 has the
65 .B SWAP_FLAG_PREFER
66 bit turned on, the new swap area will have a higher priority than default.
67 The priority is encoded within
68 .I swapflags
69 as:
70 .br
71 .sp
72 .I "    (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK"
73 .br
74 .PP
75 These functions may only be used by a privileged process (one having the
76 .B CAP_SYS_ADMIN
77 capability).
78 .SS Priority
79 Each swap area has a priority, either high or low.
80 The default priority is low.
81 Within the low-priority areas,
82 newer areas are even lower priority than older areas.
83 .PP
84 All priorities set with
85 .I swapflags
86 are high-priority, higher than default.
87 They may have any nonnegative value chosen by the caller.
88 Higher numbers mean higher priority.
89 .PP
90 Swap pages are allocated from areas in priority order,
91 highest priority first.
92 For areas with different priorities,
93 a higher-priority area is exhausted before using a lower-priority area.
94 If two or more areas have the same priority,
95 and it is the highest priority available,
96 pages are allocated on a round-robin basis between them.
97 .PP
98 As of Linux 1.3.6, the kernel usually follows these rules,
99 but there are exceptions.
100 .SH "RETURN VALUE"
101 On success, zero is returned.
102 On error, \-1 is returned, and
103 .I errno
104 is set appropriately.
105 .SH ERRORS
106 .TP
107 .B EBUSY
108 (for
109 .BR swapon ())
110 The specified
111 .I path
112 is already being used as a swap area.
113 .TP
114 .B EINVAL
115 The file
116 .I path
117 exists, but refers neither to a regular file nor to a block device;
118 or, for
119 .BR swapon (),
120 the indicated path does not contain a valid swap signature or
121 resides on an in-memory file system like tmpfs; or, for
122 .BR swapoff (),
123 .I path
124 is not currently a swap area.
125 .TP
126 .B ENFILE
127 The system limit on the total number of open files has been reached.
128 .TP
129 .B ENOENT
130 The file
131 .I path
132 does not exist.
133 .TP
134 .B ENOMEM
135 The system has insufficient memory to start swapping.
136 .TP
137 .B EPERM
138 The caller does not have the
139 .B CAP_SYS_ADMIN
140 capability.
141 Alternatively, the maximum number of swap files are already in use;
142 see NOTES below.
143 .SH "CONFORMING TO"
144 These functions are Linux-specific and should not be used in programs
145 intended to be portable.
146 The second
147 .I swapflags
148 argument was introduced in Linux 1.3.2.
149 .SH NOTES
150 The partition or path must be prepared with
151 .BR mkswap (8).
152
153 There is an upper limit on the number of swap files that may be used,
154 defined by the kernel constant
155 .BR MAX_SWAPFILES .
156 Before kernel 2.4.10,
157 .B MAX_SWAPFILES
158 has the value 8;
159 since kernel 2.4.10, it has the value 32.
160 Since kernel 2.6.18, the limit is decreased by 2 (thus: 30)
161 if the kernel is built with the
162 .B CONFIG_MIGRATION
163 option
164 (which reserves two swap table entries for the page migration features of
165 .BR mbind (2)
166 and
167 .BR migrate_pages (2)).
168 Since kernel 2.6.32, the limit is further decreased by 1
169 if the kernel is built with the
170 .B CONFIG_MEMORY_FAILURE
171 option.
172 .SH "SEE ALSO"
173 .BR mkswap (8),
174 .BR swapoff (8),
175 .BR swapon (8)