xref: /freebsd/lib/libkvm/kvm_getswapinfo.3 (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
1.\" Copyright (C) 1999 Matthew Dillon. All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.Dd January 2, 2017
25.Dt KVM_SWAPINFO 3
26.Os
27.Sh NAME
28.Nm kvm_getswapinfo
29.Nd return swap summary statistics for the system
30.Sh LIBRARY
31.Lb libkvm
32.Sh SYNOPSIS
33.In kvm.h
34.Ft int
35.Fn kvm_getswapinfo "kvm_t *kd" "struct kvm_swap *" "int maxswap" "int flags"
36.Sh DESCRIPTION
37The
38.Fn kvm_getswapinfo
39function fills an array of
40.Vt kvm_swap
41structures with swap summary
42information for each swap device, for up to
43.Fa maxswap
44\- 1 devices.
45The number of devices, up to
46.Fa maxswap
47\- 1, is returned.
48A grand
49total of all swap devices (including any devices that go beyond
50.Fa maxswap
51\- 1) is returned in one additional array entry.
52This
53entry is not counted in the return value.
54Thus, if you specify a
55.Fa maxswap
56value of 1, the function will typically return the
57value 0 and the single
58.Vt kvm_swap
59structure will be filled with
60the grand total over all swap devices.
61The grand total is calculated
62from all available swap devices whether or not you made room
63for them all in the array.
64The grand total is returned.
65.Pp
66The flags argument is currently unused and must be passed as 0.
67.Pp
68If an error occurs, -1 is returned.
69.Pp
70Each swap partition and the grand total is summarized in the
71.Vt kvm_swap
72structure.
73This structure contains the following fields:
74.Pp
75.Bl -item -offset indent -compact
76.It
77.Va char ksw_devname[] ;
78.It
79.Va u_int ksw_total ;
80.It
81.Va u_int ksw_used ;
82.It
83.Va int ksw_flags ;
84.El
85.Pp
86Values are in
87.Dv PAGE_SIZE Ns 'd
88chunks (see
89.Xr getpagesize 3 ) .
90.Va ksw_flags
91contains
92a copy of the swap device flags.
93.Sh CACHING
94This function caches the nlist values for various kernel variables which
95it reuses in successive calls.
96You may call the function with
97.Fa kd
98==
99.Dv NULL
100to clear the cache.
101.Sh DIAGNOSTICS
102If the swap summary information was unobtainable, \-1 is returned;
103otherwise, the number of swap devices actually retrieved is returned.
104.Pp
105If the name of the swap device does not fit in the static char buffer
106in the structure, it is truncated.
107The buffer is always zero terminated.
108.Sh SEE ALSO
109.Xr kvm 3
110