OSDN Git Service

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