OSDN Git Service

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