xref: /netbsd-src/lib/libc/sys/swapctl.2 (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1.\"	$NetBSD: swapctl.2,v 1.31 2004/03/25 01:13:32 wiz 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.\" Copyright (c) 1980, 1991, 1993
30.\"	The Regents of the University of California.  All rights reserved.
31.\"
32.\" Redistribution and use in source and binary forms, with or without
33.\" modification, are permitted provided that the following conditions
34.\" are met:
35.\" 1. Redistributions of source code must retain the above copyright
36.\"    notice, this list of conditions and the following disclaimer.
37.\" 2. Redistributions in binary form must reproduce the above copyright
38.\"    notice, this list of conditions and the following disclaimer in the
39.\"    documentation and/or other materials provided with the distribution.
40.\" 3. Neither the name of the University nor the names of its contributors
41.\"    may be used to endorse or promote products derived from this software
42.\"    without specific prior written permission.
43.\"
44.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54.\" SUCH DAMAGE.
55.\"
56.Dd June 20, 1997
57.Dt SWAPCTL 2
58.Os
59.Sh NAME
60.Nm swapctl
61.Nd modify swap configuration
62.Sh LIBRARY
63.Lb libc
64.Sh SYNOPSIS
65.In unistd.h
66.In sys/swap.h
67.Ft int
68.Fn swapctl "int cmd" "const void *arg" "int misc"
69.Sh DESCRIPTION
70The
71.Nm
72function is used to add and delete swap devices, and modify their
73configuration.
74.Pp
75The
76.Fa cmd
77parameter specifies the operation to be performed.
78The
79.Fa arg
80and
81.Fa misc
82parameters have different meanings, depending on the
83.Fa cmd
84parameter.
85.Bl -item -offset indent
86.It
87If
88.Fa cmd
89is
90.Dv SWAP_NSWAP ,
91the current number of swap devices in the system is returned.
92The
93.Fa arg
94and
95.Fa misc
96parameters are ignored.
97.It
98If
99.Fa cmd
100is
101.Dv SWAP_STATS ,
102the current statistics for swap devices are returned in the
103.Fa arg
104parameter.
105No more than
106.Fa misc
107swap devices are returned.
108The
109.Fa arg
110parameter should point to an array of at least
111.Fa misc
112struct swapent structures:
113.Bd -literal
114struct swapent {
115	dev_t	se_dev;			/* device id */
116	int	se_flags;		/* entry flags */
117	int	se_nblks;		/* total blocks */
118	int	se_inuse;		/* blocks in use */
119	int	se_priority;		/* priority */
120	char	se_path[PATH_MAX+1];	/* path to entry */
121};
122.Ed
123.Pp
124The flags are defined as
125.Bd -literal
126	SWF_INUSE       in use: we have swapped here
127	SWF_ENABLE      enabled: we can swap here
128	SWF_BUSY        busy: I/O happening here
129	SWF_FAKE        fake: still being built
130.Ed
131.It
132If
133.Fa cmd
134is
135.Dv SWAP_ON ,
136the
137.Fa arg
138parameter is used as a pathname of a file to enable swapping to.
139The
140.Fa misc
141parameter is used to set the priority of this swap device.
142.It
143If
144.Fa cmd
145is
146.Dv SWAP_OFF ,
147the
148.Fa arg
149parameter is used as the pathname of a file to disable swapping from.
150The
151.Fa misc
152parameter is ignored.
153.It
154If
155.Fa cmd
156is
157.Dv SWAP_CTL ,
158the
159.Fa arg
160and
161.Fa misc
162parameters have the same function as for the
163.Dv SWAP_ON
164case, except that they change the priority of a currently enabled swap device.
165.It
166If
167.Fa cmd
168is
169.Dv SWAP_DUMPDEV ,
170the
171.Fa arg
172parameter is used as the pathname of a device to use as the dump device,
173should the system panic.
174.It
175If
176.Fa cmd
177is
178.Dv SWAP_GETDUMPDEV ,
179the
180.Fa arg
181parameter points to a dev_t, which is filled in by the current dump device.
182.El
183.Pp
184When swapping is enabled on a block device, the first portion of the disk is
185left unused to prevent any disklabel present from being overwritten.
186This space is allocated from the swap device when the
187.Dv SWAP_ON
188command is used.
189.Pp
190The priority of a swap device can be used to fill faster swap devices before
191slower ones.
192A priority of 0 is the highest, with larger numbers having lower priority.
193For a fuller discussion on swap priority, see the
194.Sx SWAP PRIORITY
195section in
196.Xr swapctl 8 .
197.Sh RETURN VALUES
198If the
199.Fa cmd
200parameter is
201.Dv SWAP_NSWAP
202or
203.Dv SWAP_STATS ,
204.Fn swapctl
205returns the number of swap devices, if successful.
206The
207.Dv SWAP_NSWAP
208command is always successful.
209Otherwise it returns 0 on success and \-1
210on failure, setting the global variable
211.Va errno
212to indicate the error.
213.Sh ERRORS
214.Fn swapctl
215succeeds unless:
216.Bl -tag -width Er
217.It Bq Er ENOTDIR
218A component of the path prefix is not a directory.
219.It Bq Er ENAMETOOLONG
220A component of a pathname exceeded
221.Dv NAME_MAX
222characters, or an entire path name exceeded
223.Dv PATH_MAX
224characters.
225.It Bq Er ENOENT
226The named device does not exist.
227For the
228.Dv SWAP_CTL
229command, the named device is not currently enabled for swapping.
230.It Bq Er EACCES
231Search permission is denied for a component of the path prefix.
232.It Bq Er ELOOP
233Too many symbolic links were encountered in translating the pathname.
234.It Bq Er EPERM
235The caller is not the super-user.
236.It Bq Er EBUSY
237The device specified by
238.Fa arg
239has already been made available for swapping.
240.It Bq Er EINVAL
241The device configured by
242.Fa arg
243has no associated size, or the
244.Fa cmd
245was unknown.
246.It Bq Er ENXIO
247The major device number of
248.Fa arg
249is out of range (this indicates no device driver exists
250for the associated hardware).
251.It Bq Er EIO
252An I/O error occurred while opening the swap device.
253.It Bq Er EFAULT
254.Fa arg
255points outside the process' allocated address space.
256.El
257.Sh SEE ALSO
258.Xr swapctl 8
259.Sh HISTORY
260The
261.Fn swapctl
262function call appeared in
263.Nx 1.3 .
264The
265.Fa se_path
266member was added to
267.Va struct swapent
268in
269.Nx 1.4 ,
270when the header file was also moved from
271.Aq Pa vm/vm_swap.h
272to its current location in
273.Aq Pa sys/swap.h .
274.Sh AUTHORS
275The current swap system was designed and implemented by
276Matthew Green
277.Aq mrg@eterna.com.au ,
278with help from Paul Kranenburg
279.Aq pk@NetBSD.org
280and Leo Weppelman
281.Aq leo@NetBSD.org ,
282and insights from Jason R. Thorpe
283.Aq thorpej@NetBSD.org .
284