xref: /netbsd-src/sbin/swapctl/swapctl.8 (revision 2de962bd804263c16657f586aa00f1704045df8e)
1.\"	$NetBSD: swapctl.8,v 1.39 2007/08/02 18:53:46 he Exp $
2.\"
3.\" Copyright (c) 1997 Matthew R. Green
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. The name of the author may not be used to endorse or promote products
15.\"    derived from this software without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.Dd August 2, 2007
30.Dt SWAPCTL 8
31.Os
32.Sh NAME
33.Nm swapctl ,
34.Nm swapon
35.Nd system swap management tool
36.Sh SYNOPSIS
37.Nm
38.Fl A
39.Op Fl f | Fl o
40.Op Fl n
41.Op Fl p Ar priority
42.Op Fl t Ar blk|noblk|auto
43.Nm
44.Fl D Ar dumpdev|none
45.Nm
46.Fl U
47.Op Fl n
48.Op Fl t Ar blk|noblk|auto
49.Nm
50.Fl a
51.Op Fl p Ar priority
52.Ar path
53.Nm
54.Fl c
55.Fl p Ar priority
56.Ar path
57.Nm
58.Fl d
59.Ar path
60.Nm
61.Fl l | Fl s
62.Op Fl k | Fl m | Fl g | Fl h
63.Nm
64.Fl q
65.Nm
66.Fl z
67.Nm swapon
68.Fl a
69.Op Fl t Ar blk|noblk
70.Nm swapon
71.Ar path
72.Sh DESCRIPTION
73The
74.Nm
75program adds, removes,
76lists and prioritizes swap devices and files for the system.
77The
78.Nm swapon
79program acts the same as the
80.Nm
81program, as if called with the
82.Fl a
83option, except if
84.Nm swapon
85itself is called with
86.Fl a
87in which case,
88.Nm swapon
89acts as
90.Nm
91with the
92.Fl A
93option.
94.Pp
95The following options are available:
96.Bl -tag -width 123456
97.It Fl A
98This option causes
99.Nm
100to read the
101.Pa /etc/fstab
102file for devices and files with a
103.Dq sw
104or
105.Dq dp
106type, and adds all
107.Dq sw
108type entries as swap devices and sets the last
109.Dq dp
110type entry as the dump device.
111If no swap devices are configured,
112.Nm
113will exit with an error code.
114If used together with
115.Fl t Ar auto
116this option will not read
117.Pa /etc/fstab
118but query the kernel for all swap partitions on local hard disks.
119.It Fl a
120The
121.Fl a
122option requires that a
123.Ar path
124also be in the argument list.
125The
126.Ar path
127is added to the kernel's list of swap devices using the
128.Xr swapctl 2
129system call.
130When using the
131.Nm swapon
132form of this command, the
133.Fl a
134option is treated the same as the
135.Fl A
136option, for backwards compatibility.
137.It Fl c
138The
139.Fl c
140option changes the priority of the listed swap device or file.
141.It Fl D
142The
143.Fl D
144option requires that a
145.Ar dumpdev
146also be in the argument list.
147The kernel dump device is set to
148.Ar dumpdev .
149The word
150.Dq none
151can be used instead of a
152.Ar dumpdev
153to disable the currently set dump device.
154This change is made via the
155.Xr swapctl 2
156system call.
157The dump device is used when the system crashes
158to write a current snapshot of real memory, to be saved later with
159.Xr savecore 8
160at system reboot, and analyzed to determine the problem.
161.It Fl d
162The
163.Fl d
164option removes the listed
165.Ar path
166from the kernel's list of swap devices or files.
167.It Fl f
168Used in combination with the
169.Fl A
170command and
171.Fl t Ar auto
172flag this option makes
173.Nm
174use the first discovered swap device to also become the dump device.
175The
176.Fl f
177option is mutually exclusive with the
178.Fl o
179option.
180.It Fl g
181The
182.Fl g
183option uses (1024 * 1024 * 1024) byte blocks instead of the default 512 byte.
184.It Fl h
185The
186.Fl h
187option uses
188.Xr humanize_number 3
189to display the sizes.
190.It Fl k
191The
192.Fl k
193option uses 1024 byte blocks instead of the default 512 byte.
194.It Fl l
195The
196.Fl l
197option lists the current swap devices and files, and their usage statistics.
198.It Fl m
199The
200.Fl m
201option uses (1024 * 1024) byte blocks instead of the default 512 byte.
202.It Fl n
203Used with the
204.Fl A
205or
206.Fl U
207command, the
208.Fl n
209option makes
210.Nm
211print the action it would take, but not actually change any swap or
212dump devices.
213.It Fl o
214Similar to the
215.Fl f
216flag, this
217.Dq Dump Only
218option makes
219.Nm
220find the first swap device and configure it as dump device.
221No swap device is changed.
222This option needs to be used in combination with
223.Fl A Fl t Ar auto
224and is mutually exclusive with
225.Fl f .
226.It Fl p
227The
228.Fl p
229option sets the priority of swap devices or files to the
230.Ar priority
231argument.
232This works with the
233.\" .Fl d ,
234.Fl a ,
235.Fl c ,
236and
237.Fl l
238options.
239.It Fl q
240Query
241.Pa /etc/fstab ,
242checking for any defined swap or dump devices.
243If any are found,
244.Nm
245returns with an exit status of 0, if none are found the exit status will
246be 1.
247.It Fl s
248The
249.Fl s
250option displays a single line summary of current swap statistics.
251.It Fl t
252This flag modifies the function of the
253.Fl A
254and
255.Fl U
256options.
257The
258.Fl t
259option allows the type of device to add to be specified.
260An argument of
261.Ar blk
262causes all block devices in
263.Pa /etc/fstab
264to be added.
265An argument of
266.Ar noblk
267causes all non-block devices in
268.Pa /etc/fstab
269to be added.
270An argument of
271.Ar auto
272causes all swap partitions on local hard disks to be used.
273This option is useful in early system startup, where swapping
274may be needed before all file systems are available, such as during
275disk checks of large file systems.
276.It Fl U
277This option causes
278.Nm
279to read the
280.Pa /etc/fstab
281file for devices and files with a
282.Dq sw
283type, and remove all these entries as swap devices.
284If no swap devices are unconfigured,
285.Nm
286will exit with an error code.
287If used together with
288.Fl t Ar auto
289this option will not read
290.Pa /etc/fstab
291but unconfigure all local swap partitions.
292.It Fl z
293The
294.Fl z
295option displays the current dump device.
296.El
297.Sh SWAP PRIORITY
298The
299.Nx
300swap system allows different swap devices and files to be assigned different
301priorities, to allow the faster resources to be used first.
302Swap devices at the same priority are used in a round-robin fashion until
303there is no more space available at this priority, when the next priority
304level will be used.
305The default priority is 0, the highest.
306This value can be any valid integer,
307with higher values receiving less priority.
308.Sh SWAP OPTIONS
309When parsing the
310.Pa /etc/fstab
311file for swap devices, the following options are recognized:
312.Pp
313.Bl -tag -width nfsmntpt=/path -compact
314.It priority=N
315This option sets the priority of the specified swap device to N.
316.It nfsmntpt=/path
317This option is useful for swapping to NFS files.
318It specifies the local mount point to mount an NFS filesystem.
319The mount point must exist as a directory.
320Typically, once this mount has succeeded, the file to be used for swapping
321on will be available under this point mount.
322For example:
323.Bd -literal
324server:/export/swap/client none swap sw,nfsmntpt=/swap
325.Ed
326.El
327.Sh EXIT STATUS
328If the requested operation was sucessful, the
329.Nm
330utility exits with status 0.
331If an error occurred, the exit status is 1.
332.Pp
333For easy scriptability, the
334.Fl z
335operation (query dump device) and
336.Fl l
337(list swap partitions) return an exit status of 1 if no dump device or
338swap partition has been configured.
339If any swap partition is available or
340a dump device is set, the respective query returns 0.
341.Sh SEE ALSO
342.Xr swapctl 2 ,
343.Xr fstab 5 ,
344.Xr mount_nfs 8
345.Sh HISTORY
346The
347.Nm
348program was first made available in
349.Nx 1.3 .
350The original
351.Nm swapon
352program, provided for backwards compatibility, appeared in
353.Bx 4.0 .
354.Sh AUTHORS
355The
356.Nm
357program was written by
358.An Matthew R. Green Aq mrg@eterna.com.au .
359.Sh CAVEATS
360Using the automatic swap partition detection done by the
361.Fl A Fl t Ar auto
362option may be dangereous.
363Depending on the on-disk partitioning scheme used, the type of a partition
364may not be accurately recognizable as a swap partition.
365The autodetection might recognize and use partitions on
366removable media like USB sticks.
367An easy way to test the autoconfiguration is to use
368.Nm
369with the
370.Fl n
371option.
372.Sh BUGS
373If no swap information is specified in
374.Pa /etc/fstab ,
375the system startup scripts (see
376.Xr rc 8 )
377will configure no swap space and your machine will behave very badly
378if (more likely when) it runs out of real memory.
379.Pp
380Local and remote swap files cannot be configured until after the file
381systems they reside on are mounted read/write.
382The system startup scripts need to
383.Xr fsck 8
384all local file systems before this can happen.
385This process requires substantial amounts of memory on some systems.
386If you configure no local block swap devices on a machine that has local
387file systems to check and rely only on swap files, the machine will have
388no swap space at all during system
389.Xr fsck 8
390and may run out of real memory, causing fsck to abnormally exit and
391startup scripts to fail.
392