1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
.\" $OpenBSD: swapctl.2,v 1.22 2015/07/15 02:57:02 jasper Exp $
.\" $NetBSD: swapctl.2,v 1.10 1998/08/29 17:11:09 mrg Exp $
.\"
.\" Copyright (c) 1997 Matthew R. Green
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. 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. 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
.\" 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.
.\"
.Dd $Mdocdate: July 15 2015 $
.Dt SWAPCTL 2
.Os
.Sh NAME
.Nm swapctl
.Nd modify swap configuration
.Sh SYNOPSIS
.In sys/param.h
.In sys/swap.h
.In unistd.h
.Ft int
.Fn swapctl "int cmd" "const void *arg" "int misc"
.Sh DESCRIPTION
The
.Fn swapctl
function is used to add and delete swap devices, modify their configuration or
query their statistics.
.Pp
The
.Fa cmd
parameter specifies the operation to be performed.
The
.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
.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
.Fa misc
swap devices are returned.
The
.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]; /* path to entry */
};
.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
.Pp
All but
.Dv SWAP_NSWAP
and
.Dv SWAP_STATS
require superuser privileges.
.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.
.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.
.Sh RETURN VALUES
If the
.Fa cmd
parameter is
.Dv SWAP_NSWAP
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 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
A component of a pathname exceeded
.Dv NAME_MAX
characters, or an entire pathname (including the terminating NUL)
exceeded
.Dv PATH_MAX
bytes.
.It Bq Er ENOENT
The named device does not exist.
For the
.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 superuser.
.It Bq Er EBUSY
The device specified by
.Fa arg
has already been made available for swapping.
.It Bq Er EINVAL
The device configured by
.Fa arg
has no associated size, or the
.Fa cmd
was unknown.
.It Bq Er ENXIO
The major device number of
.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.
.El
.Sh SEE ALSO
.Xr config 8 ,
.Xr swapctl 8
.Sh HISTORY
The
.Fn swapctl
function call appeared in
.Nx 1.3 .
The
.Fa se_path
member was added to
.Vt struct swapent
in
.Nx 1.4 ,
when the header file was also moved from
.In vm/vm_swap.h .
.Sh AUTHORS
.An -nosplit
The current swap system was designed and implemented by
.An Matthew Green Aq Mt mrg@eterna.com.au ,
with help from
.An Paul Kranenburg Aq Mt pk@NetBSD.ORG
and
.An Leo Weppelman Aq Mt leo@NetBSD.ORG ,
and insights from
.An Jason R. Thorpe Aq Mt thorpej@NetBSD.ORG .
|