]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/swapon.2
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / 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@gmx.net>
32 .\" Modified 2004-10-10 by aeb
33 .\" 2004-12-14 mtk, Anand Kumria: added new errors
34 .\"
35 .TH SWAPON 2 2004-10-10 "Linux 2.6.7" "Linux Programmer's Manual"
36 .SH NAME
37 swapon, swapoff \- start/stop swapping to file/device
38 .SH SYNOPSIS
39 .B #include <unistd.h>
40 .br
41 .B #include <asm/page.h> /* to find PAGE_SIZE */
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 .BR swapon ()
57 takes a
58 .I swapflags
59 argument.
60 If
61 .I swapflags
62 has the
63 .I SWAP_FLAG_PREFER
64 bit turned on, the new swap area will have a higher priority than default.
65 The priority is encoded within
66 .I swapflags
67 as:
68 .br
69 .sp
70 .I " (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK"
71 .br
72 .PP
73 These functions may only be used by a privileged process (one having the
74 .B CAP_SYS_ADMIN
75 capability).
76 .SH PRIORITY
77 Each swap area has a priority, either high or low.
78 The default priority is low.
79 Within the low-priority areas,
80 newer areas are even lower priority than older areas.
81 .PP
82 All priorities set with
83 .I swapflags
84 are high-priority, higher than default.
85 They may have any non-negative value chosen by the caller.
86 Higher numbers mean higher priority.
87 .PP
88 Swap pages are allocated from areas in priority order,
89 highest priority first.
90 For areas with different priorities,
91 a higher-priority area is exhausted before using a lower-priority area.
92 If two or more areas have the same priority,
93 and it is the highest priority available,
94 pages are allocated on a round-robin basis between them.
95 .PP
96 As of Linux 1.3.6, the kernel usually follows these rules,
97 but there are exceptions.
98 .SH "RETURN VALUE"
99 On success, zero is returned.
100 On error, \-1 is returned, and
101 .I errno
102 is set appropriately.
103 .SH ERRORS
104 .TP
105 .B EBUSY
106 (for
107 .BR swapon ())
108 The specified
109 .I path
110 is already being used as a swap area.
111 .TP
112 .B EINVAL
113 The file
114 .I path
115 exists, but refers neither to a regular file nor to a block device;
116 or, for
117 .BR swapon (),
118 the indicated path does not contain a valid swap signature;
119 or, for
120 .BR swapoff (),
121 .I path
122 is not currently a swap area.
123 .TP
124 .B ENFILE
125 The system limit on the total number of open files has been reached.
126 .TP
127 .B ENOENT
128 The file
129 .I path
130 does not exist.
131 .TP
132 .B ENOMEM
133 The system has insufficient memory to start swapping.
134 .TP
135 .B EPERM
136 The caller does not have the
137 .B CAP_SYS_ADMIN
138 capability, or all
139 .B MAX_SWAPFILES
140 (earlier 8; 32 since Linux 2.4.10) are in use.
141 .SH "CONFORMING TO"
142 These functions are Linux specific and should not be used in programs
143 intended to be portable.
144 The second
145 .I swapflags
146 argument was introduced in Linux 1.3.2.
147 .SH NOTES
148 The partition or path must be prepared with
149 .BR mkswap (8).
150 .SH "SEE ALSO"
151 .BR mkswap (8),
152 .BR swapoff (8),
153 .BR swapon (8)