1.\" $OpenBSD: swapctl.8,v 1.36 2021/08/24 13:15:07 jmc Exp $ 2.\" $NetBSD: swapctl.8,v 1.14 1998/05/22 18:27:52 msaitoh Exp $ 3.\" 4.\" Copyright (c) 1997 Matthew R. Green 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd $Mdocdate: August 24 2021 $ 29.Dt SWAPCTL 8 30.Os 31.Sh NAME 32.Nm swapctl , 33.Nm swapon 34.Nd system swap management tool 35.Sh SYNOPSIS 36.Nm swapctl 37.Fl A 38.Op Fl p Ar priority 39.Op Fl t Cm blk | noblk 40.Nm swapctl 41.Fl a 42.Op Fl p Ar priority 43.Ar path 44.Nm swapctl 45.Fl c 46.Fl p Ar priority 47.Ar path 48.Nm swapctl 49.Fl d 50.Ar path 51.Nm swapctl 52.Op Oo Fl l Oc | Fl s 53.Op Fl k 54.Nm swapon 55.Fl a | Ar path 56.Sh DESCRIPTION 57The 58.Nm 59program adds, removes, 60lists and prioritizes swap devices and files for the system. 61The 62.Nm swapon 63program acts the same as 64.Ic swapctl -a , 65except if 66.Nm swapon 67itself is called with 68.Fl a , 69in which case 70it acts as 71.Ic swapctl -A . 72.Pp 73The options are as follows: 74.Bl -tag -width Ds 75.It Fl A 76This option causes 77.Nm 78to read the 79.Pa /etc/fstab 80file for devices and files with an 81.Dq sw 82type, and adds all these entries 83as swap devices. 84If no swap devices are configured, 85.Nm 86will exit with an error code. 87.It Fl a 88The 89.Fl a 90option requires that a 91.Ar path 92also be in the argument list. 93The 94.Ar path 95is added to the kernel's list of swap devices using the 96.Xr swapctl 2 97system call. 98When using the 99.Nm swapon 100form of this command, the 101.Fl a 102option is treated the same as the 103.Fl A 104option, for backwards compatibility. 105.It Fl c 106The 107.Fl c 108option changes the priority of the listed swap device or file. 109.It Fl d Ar path 110The 111.Fl d 112option removes the listed 113.Ar path 114from the kernel's list of swap devices or files. 115.It Fl k 116The 117.Fl k 118option uses 1024 byte blocks instead of the default 512 byte. 119.It Fl l 120The 121.Fl l 122option lists the current swap devices and files, and their usage statistics. 123.It Fl p Ar priority 124The 125.Fl p 126option sets the priority of swap devices or files to the 127.Ar priority 128argument. 129.It Fl s 130The 131.Fl s 132option displays a single line summary of current swap statistics. 133.It Fl t Cm blk | noblk 134This flag modifies the function of the 135.Fl A 136option. 137The 138.Fl t 139option allows the type of device to add to be specified. 140An argument of 141.Cm blk 142causes all block devices in 143.Pa /etc/fstab 144to be added. 145An argument of 146.Cm noblk 147causes all non-block devices in 148.Pa /etc/fstab 149to be added. 150This option is useful in early system startup, where swapping 151may be needed before all file systems are available, such as during 152disk checks of large file systems. 153.El 154.Sh SWAP OPTIONS 155Lines such as the following 156specify swap devices in 157.Pa /etc/fstab : 158.Bd -literal -offset indent 159/dev/sd1b none swap sw 160d48d0e3fc1c39531.k none swap sw 161.Ed 162.Pp 163The initial swap device (root disk, partition b) need not appear in 164.Pa /etc/fstab , 165though it is not an error for it to do so. 166.Pp 167Additional flags include: 168.Pp 169.Bl -tag -width nfsmntpt=/path -compact 170.It priority=N 171Swap devices and files may be assigned different priorities, 172to allow faster resources to be used first. 173Swap devices at the same priority are used in a round-robin fashion until 174there is no more space available at this priority, when the next priority 175level will be used. 176The default priority is 0, the highest. 177This value can be any valid integer, 178with higher values receiving less priority. 179.It nfsmntpt=/path 180This option is useful for swapping to NFS files. 181It specifies the local mount point to mount an NFS filesystem. 182Typically, once 183this mount has succeeded, the file to be used for swapping on will 184be available under this point mount. 185For example: 186.Bd -literal 187server:/export/swap/client none swap sw,nfsmntpt=/swap 188.Ed 189.El 190.Sh EXIT STATUS 191.Ex -std swapctl 192.Sh SEE ALSO 193.Xr swapctl 2 , 194.Xr vnd 4 , 195.Xr fstab 5 , 196.Xr mount_nfs 8 , 197.Xr mount_vnd 8 198.Sh HISTORY 199The 200.Nm 201program was originally developed in 202.Nx 1.3 . 203It was ported to 204.Ox 2.6 205by Tobias Weingartner. 206The original 207.Nm swapon 208program, provided for backwards compatibility, appeared in 209.Bx 4.0 . 210.Sh AUTHORS 211The 212.Nm 213program was written by 214.An Matthew R. Green Aq Mt mrg@eterna.com.au . 215.Sh BUGS 216Local and remote swap files cannot be configured until the file 217systems they reside on are mounted read/write. 218The system startup scripts need to 219.Xr fsck 8 220all local file systems before this can happen. 221This process requires substantial amounts of memory on some systems. 222If one configures no 223local block swap devices on a machine that has local file systems to 224check and rely only on swap files, the machine will have no swap space 225at all during system 226.Xr fsck 8 227and may run out of real memory, causing fsck to abnormally exit and 228startup scripts to fail. 229