OSDN Git Service

ac1d6a3f61c7044e14aa41d688f2ae7a9c6a6484
[linuxjm/LDP_man-pages.git] / original / man2 / swapon.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
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 .\" 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 2014-02-26 "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 If the
59 .B SWAP_FLAG_PREFER
60 flag is specified in the
61 .BR swapon ()
62 .I swapflags
63 argument, the new swap area will have a higher priority than default.
64 The priority is encoded within
65 .I swapflags
66 as:
67 .br
68 .sp
69 .I "    (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK"
70 .br
71 .PP
72 If the
73 .B SWAP_FLAG_DISCARD
74 flag is specified in the
75 .BR swapon ()
76 .I swapflags
77 argument, freed swap pages will be discarded before they are reused,
78 if the swap device supports the discard or trim operation.
79 (This may improve performance on some Solid State Devices,
80 but often it does not.)
81 See also NOTES.
82 .PP
83 These functions may be used only by a privileged process (one having the
84 .B CAP_SYS_ADMIN
85 capability).
86 .SS Priority
87 Each swap area has a priority, either high or low.
88 The default priority is low.
89 Within the low-priority areas,
90 newer areas are even lower priority than older areas.
91 .PP
92 All priorities set with
93 .I swapflags
94 are high-priority, higher than default.
95 They may have any nonnegative value chosen by the caller.
96 Higher numbers mean higher priority.
97 .PP
98 Swap pages are allocated from areas in priority order,
99 highest priority first.
100 For areas with different priorities,
101 a higher-priority area is exhausted before using a lower-priority area.
102 If two or more areas have the same priority,
103 and it is the highest priority available,
104 pages are allocated on a round-robin basis between them.
105 .PP
106 As of Linux 1.3.6, the kernel usually follows these rules,
107 but there are exceptions.
108 .SH RETURN VALUE
109 On success, zero is returned.
110 On error, \-1 is returned, and
111 .I errno
112 is set appropriately.
113 .SH ERRORS
114 .TP
115 .B EBUSY
116 (for
117 .BR swapon ())
118 The specified
119 .I path
120 is already being used as a swap area.
121 .TP
122 .B EINVAL
123 The file
124 .I path
125 exists, but refers neither to a regular file nor to a block device;
126 .TP
127 .B EINVAL
128 .RB ( swapon ())
129 The indicated path does not contain a valid swap signature or
130 resides on an in-memory filesystem such as tmpfs.
131 .TP
132 .BR EINVAL " (since Linux 3.4)"
133 .RB ( swapon ())
134 An invalid flag value was specified in
135 .IR flags .
136 .TP
137 .B EINVAL
138 .RB ( swapoff ())
139 .I path
140 is not currently a swap area.
141 .TP
142 .B ENFILE
143 The system limit on the total number of open files has been reached.
144 .TP
145 .B ENOENT
146 The file
147 .I path
148 does not exist.
149 .TP
150 .B ENOMEM
151 The system has insufficient memory to start swapping.
152 .TP
153 .B EPERM
154 The caller does not have the
155 .B CAP_SYS_ADMIN
156 capability.
157 Alternatively, the maximum number of swap files are already in use;
158 see NOTES below.
159 .SH CONFORMING TO
160 These functions are Linux-specific and should not be used in programs
161 intended to be portable.
162 The second
163 .I swapflags
164 argument was introduced in Linux 1.3.2.
165 .SH NOTES
166 The partition or path must be prepared with
167 .BR mkswap (8).
168
169 There is an upper limit on the number of swap files that may be used,
170 defined by the kernel constant
171 .BR MAX_SWAPFILES .
172 Before kernel 2.4.10,
173 .B MAX_SWAPFILES
174 has the value 8;
175 since kernel 2.4.10, it has the value 32.
176 Since kernel 2.6.18, the limit is decreased by 2 (thus: 30)
177 if the kernel is built with the
178 .B CONFIG_MIGRATION
179 option
180 (which reserves two swap table entries for the page migration features of
181 .BR mbind (2)
182 and
183 .BR migrate_pages (2)).
184 Since kernel 2.6.32, the limit is further decreased by 1
185 if the kernel is built with the
186 .B CONFIG_MEMORY_FAILURE
187 option.
188
189 Discard of swap pages was introduced in kernel 2.6.29,
190 then made conditional
191 on the
192 .B SWAP_FLAG_DISCARD
193 flag in kernel 2.6.36,
194 .\" To be precise: 2.6.35.5
195 which still discards the
196 entire swap area when
197 .BR swapon ()
198 is called, even if that flag bit is not set.
199 .SH SEE ALSO
200 .BR mkswap (8),
201 .BR swapoff (8),
202 .BR swapon (8)
203 .SH COLOPHON
204 This page is part of release 3.67 of the Linux
205 .I man-pages
206 project.
207 A description of the project,
208 information about reporting bugs,
209 and the latest version of this page,
210 can be found at
211 \%http://www.kernel.org/doc/man\-pages/.