xref: /freebsd/lib/libsys/swapon.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993
2*8269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
10*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
11*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
13*8269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
14*8269e767SBrooks Davis.\"    without specific prior written permission.
15*8269e767SBrooks Davis.\"
16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*8269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*8269e767SBrooks Davis.\" SUCH DAMAGE.
27*8269e767SBrooks Davis.\"
28*8269e767SBrooks Davis.Dd December 8, 2021
29*8269e767SBrooks Davis.Dt SWAPON 2
30*8269e767SBrooks Davis.Os
31*8269e767SBrooks Davis.Sh NAME
32*8269e767SBrooks Davis.Nm swapon , swapoff
33*8269e767SBrooks Davis.Nd control devices for interleaved paging/swapping
34*8269e767SBrooks Davis.Sh LIBRARY
35*8269e767SBrooks Davis.Lb libc
36*8269e767SBrooks Davis.Sh SYNOPSIS
37*8269e767SBrooks Davis.It vm/vm_param.h
38*8269e767SBrooks Davis.It vm/swap_pager.h
39*8269e767SBrooks Davis.In unistd.h
40*8269e767SBrooks Davis.Ft int
41*8269e767SBrooks Davis.Fn swapon "const char *special"
42*8269e767SBrooks Davis.Ft int
43*8269e767SBrooks Davis.Fn swapoff "const char *special" "u_int flags"
44*8269e767SBrooks Davis.Sh DESCRIPTION
45*8269e767SBrooks DavisThe
46*8269e767SBrooks Davis.Fn swapon
47*8269e767SBrooks Davissystem call
48*8269e767SBrooks Davismakes the block device
49*8269e767SBrooks Davis.Fa special
50*8269e767SBrooks Davisavailable to the system for
51*8269e767SBrooks Davisallocation for paging and swapping.
52*8269e767SBrooks DavisThe names of potentially
53*8269e767SBrooks Davisavailable devices are known to the system and defined at system
54*8269e767SBrooks Davisconfiguration time.
55*8269e767SBrooks DavisThe size of the swap area on
56*8269e767SBrooks Davis.Fa special
57*8269e767SBrooks Davisis calculated at the time the device is first made available
58*8269e767SBrooks Davisfor swapping.
59*8269e767SBrooks Davis.Pp
60*8269e767SBrooks DavisThe
61*8269e767SBrooks Davis.Fn swapoff
62*8269e767SBrooks Davissystem call disables paging and swapping on the given device.
63*8269e767SBrooks DavisAll associated swap metadata are deallocated, and the device
64*8269e767SBrooks Davisis made available for other purposes.
65*8269e767SBrooks Davis.Pp
66*8269e767SBrooks DavisThe
67*8269e767SBrooks Davis.Fa special
68*8269e767SBrooks Davisargument points to the name of the device or file used for swapping.
69*8269e767SBrooks Davis.The
70*8269e767SBrooks Davis.Va flags
71*8269e767SBrooks Davisargument takes the following flags:
72*8269e767SBrooks Davis.Bl -tag -width SWAPOFF_FORCE
73*8269e767SBrooks Davis.It Dv SWAPOFF_FORCE
74*8269e767SBrooks DavisOverrides a very conservative check that prevents swapoff
75*8269e767SBrooks Davisif the total amount of free memory and remaining swap
76*8269e767SBrooks Davisdevices space might be unsufficient for the system to continue
77*8269e767SBrooks Davisoperating.
78*8269e767SBrooks Davis.El
79*8269e767SBrooks Davis.Sh RETURN VALUES
80*8269e767SBrooks DavisIf an error has occurred, a value of -1 is returned and
81*8269e767SBrooks Davis.Va errno
82*8269e767SBrooks Davisis set to indicate the error.
83*8269e767SBrooks Davis.Sh ERRORS
84*8269e767SBrooks DavisBoth
85*8269e767SBrooks Davis.Fn swapon
86*8269e767SBrooks Davisand
87*8269e767SBrooks Davis.Fn swapoff
88*8269e767SBrooks Daviscan fail if:
89*8269e767SBrooks Davis.Bl -tag -width Er
90*8269e767SBrooks Davis.It Bq Er ENOTDIR
91*8269e767SBrooks DavisA component of the path prefix is not a directory.
92*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
93*8269e767SBrooks DavisA component of a pathname exceeded 255 characters,
94*8269e767SBrooks Davisor an entire path name exceeded 1023 characters.
95*8269e767SBrooks Davis.It Bq Er ENOENT
96*8269e767SBrooks DavisThe named device does not exist.
97*8269e767SBrooks Davis.It Bq Er EACCES
98*8269e767SBrooks DavisSearch permission is denied for a component of the path prefix.
99*8269e767SBrooks Davis.It Bq Er ELOOP
100*8269e767SBrooks DavisToo many symbolic links were encountered in translating the pathname.
101*8269e767SBrooks Davis.It Bq Er EPERM
102*8269e767SBrooks DavisThe caller is not the super-user.
103*8269e767SBrooks Davis.It Bq Er EFAULT
104*8269e767SBrooks DavisThe
105*8269e767SBrooks Davis.Fa special
106*8269e767SBrooks Davisargument
107*8269e767SBrooks Davispoints outside the process's allocated address space.
108*8269e767SBrooks Davis.El
109*8269e767SBrooks Davis.Pp
110*8269e767SBrooks DavisAdditionally,
111*8269e767SBrooks Davis.Fn swapon
112*8269e767SBrooks Daviscan fail for the following reasons:
113*8269e767SBrooks Davis.Bl -tag -width Er
114*8269e767SBrooks Davis.It Bq Er ENOTBLK
115*8269e767SBrooks DavisThe
116*8269e767SBrooks Davis.Fa special
117*8269e767SBrooks Davisargument
118*8269e767SBrooks Davisis not a block device.
119*8269e767SBrooks Davis.It Bq Er EBUSY
120*8269e767SBrooks DavisThe device specified by
121*8269e767SBrooks Davis.Fa special
122*8269e767SBrooks Davishas already
123*8269e767SBrooks Davisbeen made available for swapping
124*8269e767SBrooks Davis.It Bq Er ENXIO
125*8269e767SBrooks DavisThe major device number of
126*8269e767SBrooks Davis.Fa special
127*8269e767SBrooks Davisis out of range (this indicates no device driver exists
128*8269e767SBrooks Davisfor the associated hardware).
129*8269e767SBrooks Davis.It Bq Er EIO
130*8269e767SBrooks DavisAn I/O error occurred while opening the swap device.
131*8269e767SBrooks Davis.It Bq Er EINTEGRITY
132*8269e767SBrooks DavisCorrupted data was detected while reading from the file system to open the
133*8269e767SBrooks Davisswap device.
134*8269e767SBrooks Davis.El
135*8269e767SBrooks Davis.Pp
136*8269e767SBrooks DavisLastly,
137*8269e767SBrooks Davis.Fn swapoff
138*8269e767SBrooks Daviscan fail if:
139*8269e767SBrooks Davis.Bl -tag -width Er
140*8269e767SBrooks Davis.It Bq Er EINVAL
141*8269e767SBrooks DavisThe system is not currently swapping to
142*8269e767SBrooks Davis.Fa special .
143*8269e767SBrooks Davis.It Bq Er ENOMEM
144*8269e767SBrooks DavisNot enough virtual memory is available to safely disable
145*8269e767SBrooks Davispaging and swapping to the given device.
146*8269e767SBrooks Davis.El
147*8269e767SBrooks Davis.Sh SEE ALSO
148*8269e767SBrooks Davis.Xr config 8 ,
149*8269e767SBrooks Davis.Xr swapon 8 ,
150*8269e767SBrooks Davis.Xr sysctl 8
151*8269e767SBrooks Davis.Sh HISTORY
152*8269e767SBrooks DavisThe
153*8269e767SBrooks Davis.Fn swapon
154*8269e767SBrooks Davissystem call appeared in
155*8269e767SBrooks Davis.Bx 4.0 .
156*8269e767SBrooks DavisThe
157*8269e767SBrooks Davis.Fn swapoff
158*8269e767SBrooks Davissystem call appeared in
159*8269e767SBrooks Davis.Fx 5.1 .
160