NetBSD/lib/libc/sys/swapctl.2

284 lines
7.6 KiB
Groff
Raw Normal View History

2005-05-30 01:12:27 +04:00
.\" $NetBSD: swapctl.2,v 1.32 2005/05/29 21:12:27 christos Exp $
.\"
.\" Copyright (c) 1997 Matthew R. Green
2004-03-21 08:47:44 +03:00
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1993-03-21 12:45:37 +03:00
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
2005-05-30 01:12:27 +04:00
.Dd May 29, 2005
.Dt SWAPCTL 2
.Os
1993-03-21 12:45:37 +03:00
.Sh NAME
1997-06-12 19:46:19 +04:00
.Nm swapctl
.Nd modify swap configuration
.Sh LIBRARY
.Lb libc
1993-03-21 12:45:37 +03:00
.Sh SYNOPSIS
.In unistd.h
.In sys/swap.h
1993-03-21 12:45:37 +03:00
.Ft int
2005-05-30 01:12:27 +04:00
.Fn swapctl "int cmd" "void *arg" "int misc"
1997-06-13 02:39:15 +04:00
.Sh DESCRIPTION
The
.Nm
function is used to add and delete swap devices, and modify their
1997-10-17 03:13:24 +04:00
configuration.
1997-06-20 09:47:58 +04:00
.Pp
The
.Fa cmd
parameter specifies the operation to be performed.
The
1997-06-20 09:47:58 +04:00
.Fa arg
and
.Fa misc
parameters have different meanings, depending on the
.Fa cmd
parameter.
.Bl -item -offset indent
.It
If
.Fa cmd
is
.Dv SWAP_NSWAP ,
the current number of swap devices in the system is returned.
The
1997-06-20 09:47:58 +04:00
.Fa arg
and
.Fa misc
parameters are ignored.
.It
If
.Fa cmd
is
.Dv SWAP_STATS ,
the current statistics for swap devices are returned in the
.Fa arg
parameter.
No more than
1997-06-20 09:47:58 +04:00
.Fa misc
swap devices are returned.
The
1997-06-20 09:47:58 +04:00
.Fa arg
parameter should point to an array of at least
.Fa misc
struct swapent structures:
.Bd -literal
struct swapent {
dev_t se_dev; /* device id */
int se_flags; /* entry flags */
int se_nblks; /* total blocks */
int se_inuse; /* blocks in use */
int se_priority; /* priority */
char se_path[PATH_MAX+1]; /* path to entry */
1997-06-20 09:47:58 +04:00
};
.Ed
.Pp
The flags are defined as
.Bd -literal
SWF_INUSE in use: we have swapped here
SWF_ENABLE enabled: we can swap here
SWF_BUSY busy: I/O happening here
SWF_FAKE fake: still being built
.Ed
1997-06-20 09:47:58 +04:00
.It
If
.Fa cmd
is
.Dv SWAP_ON ,
the
.Fa arg
parameter is used as a pathname of a file to enable swapping to.
The
.Fa misc
parameter is used to set the priority of this swap device.
.It
If
.Fa cmd
is
.Dv SWAP_OFF ,
the
.Fa arg
parameter is used as the pathname of a file to disable swapping from.
The
.Fa misc
parameter is ignored.
.It
If
.Fa cmd
is
.Dv SWAP_CTL ,
the
.Fa arg
and
.Fa misc
parameters have the same function as for the
.Dv SWAP_ON
case, except that they change the priority of a currently enabled swap device.
.It
If
.Fa cmd
is
.Dv SWAP_DUMPDEV ,
the
.Fa arg
parameter is used as the pathname of a device to use as the dump device,
should the system panic.
.It
If
.Fa cmd
is
.Dv SWAP_GETDUMPDEV ,
the
.Fa arg
parameter points to a dev_t, which is filled in by the current dump device.
1997-06-20 09:47:58 +04:00
.El
.Pp
When swapping is enabled on a block device, the first portion of the disk is
left unused to prevent any disklabel present from being overwritten.
This space is allocated from the swap device when the
.Dv SWAP_ON
command is used.
.Pp
The priority of a swap device can be used to fill faster swap devices before
slower ones.
A priority of 0 is the highest, with larger numbers having lower priority.
For a fuller discussion on swap priority, see the
.Sx SWAP PRIORITY
section in
.Xr swapctl 8 .
1997-06-20 09:47:58 +04:00
.Sh RETURN VALUES
If the
.Fa cmd
parameter is
.Dv SWAP_NSWAP
1997-06-20 09:47:58 +04:00
or
.Dv SWAP_STATS ,
.Fn swapctl
returns the number of swap devices, if successful.
The
.Dv SWAP_NSWAP
command is always successful.
Otherwise it returns 0 on success and \-1
1997-06-20 09:47:58 +04:00
on failure, setting the global variable
.Va errno
to indicate the error.
.Sh ERRORS
.Fn swapctl
succeeds unless:
.Bl -tag -width Er
.It Bq Er ENOTDIR
A component of the path prefix is not a directory.
.It Bq Er ENAMETOOLONG
2001-09-16 05:38:59 +04:00
A component of a pathname exceeded
1997-06-20 09:47:58 +04:00
.Dv NAME_MAX
2001-09-16 05:38:59 +04:00
characters, or an entire path name exceeded
1997-06-20 09:47:58 +04:00
.Dv PATH_MAX
characters.
.It Bq Er ENOENT
The named device does not exist.
For the
1997-06-20 09:47:58 +04:00
.Dv SWAP_CTL
command, the named device is not currently enabled for swapping.
.It Bq Er EACCES
Search permission is denied for a component of the path prefix.
.It Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname.
.It Bq Er EPERM
The caller is not the super-user.
.It Bq Er EBUSY
The device specified by
.Fa arg
has already been made available for swapping.
1997-06-20 09:47:58 +04:00
.It Bq Er EINVAL
The device configured by
.Fa arg
has no associated size, or the
.Fa cmd
was unknown.
.It Bq Er ENXIO
2001-09-16 05:38:59 +04:00
The major device number of
1997-06-20 09:47:58 +04:00
.Fa arg
is out of range (this indicates no device driver exists
for the associated hardware).
.It Bq Er EIO
An I/O error occurred while opening the swap device.
.It Bq Er EFAULT
.Fa arg
points outside the process' allocated address space.
1999-03-09 06:58:14 +03:00
.El
1993-03-21 12:45:37 +03:00
.Sh SEE ALSO
.Xr swapctl 8
1993-03-21 12:45:37 +03:00
.Sh HISTORY
The
1997-06-12 19:46:19 +04:00
.Fn swapctl
1993-03-21 12:45:37 +03:00
function call appeared in
1997-06-12 19:46:19 +04:00
.Nx 1.3 .
The
.Fa se_path
member was added to
.Va struct swapent
in
1998-08-29 21:11:09 +04:00
.Nx 1.4 ,
when the header file was also moved from
.Aq Pa vm/vm_swap.h
to its current location in
.Aq Pa sys/swap.h .
.Sh AUTHORS
The current swap system was designed and implemented by
Matthew Green
.Aq mrg@eterna.com.au ,
with help from Paul Kranenburg
.Aq pk@NetBSD.org
and Leo Weppelman
.Aq leo@NetBSD.org ,
and insights from Jason R. Thorpe
.Aq thorpej@NetBSD.org .