xref: /freebsd/lib/libkvm/kvm_getswapinfo.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
19e749cc9SWarner Losh.\" Copyright (C) 1999 Matthew Dillon. All rights reserved.
2e92324a2SMatthew Dillon.\"
3e92324a2SMatthew Dillon.\" Redistribution and use in source and binary forms, with or without
49e749cc9SWarner Losh.\" modification, are permitted provided that the following conditions
59e749cc9SWarner Losh.\" are met:
69e749cc9SWarner Losh.\" 1. Redistributions of source code must retain the above copyright
79e749cc9SWarner Losh.\"    notice, this list of conditions and the following disclaimer.
89e749cc9SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright
99e749cc9SWarner Losh.\"    notice, this list of conditions and the following disclaimer in the
109e749cc9SWarner Losh.\"    documentation and/or other materials provided with the distribution.
119e749cc9SWarner Losh.\"
129e749cc9SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
139e749cc9SWarner Losh.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
149e749cc9SWarner Losh.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
159e749cc9SWarner Losh.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
169e749cc9SWarner Losh.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
179e749cc9SWarner Losh.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
189e749cc9SWarner Losh.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199e749cc9SWarner Losh.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
209e749cc9SWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
219e749cc9SWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
229e749cc9SWarner Losh.\" SUCH DAMAGE.
23e92324a2SMatthew Dillon.\"
24eca80cd0SPedro F. Giffuni.Dd January 2, 2017
25e92324a2SMatthew Dillon.Dt KVM_SWAPINFO 3
26e92324a2SMatthew Dillon.Os
27e92324a2SMatthew Dillon.Sh NAME
286a389e51SMatthew Dillon.Nm kvm_getswapinfo
29e92324a2SMatthew Dillon.Nd return swap summary statistics for the system
307f5e8c84SAlexey Zelkin.Sh LIBRARY
317f5e8c84SAlexey Zelkin.Lb libkvm
32e92324a2SMatthew Dillon.Sh SYNOPSIS
3332eef9aeSRuslan Ermilov.In kvm.h
34e92324a2SMatthew Dillon.Ft int
356a389e51SMatthew Dillon.Fn kvm_getswapinfo "kvm_t *kd" "struct kvm_swap *" "int maxswap" "int flags"
36e92324a2SMatthew Dillon.Sh DESCRIPTION
37e92324a2SMatthew DillonThe
386a389e51SMatthew Dillon.Fn kvm_getswapinfo
39d0353b83SRuslan Ermilovfunction fills an array of
40d0353b83SRuslan Ermilov.Vt kvm_swap
41d0353b83SRuslan Ermilovstructures with swap summary
42d0353b83SRuslan Ermilovinformation for each swap device, for up to
43d0353b83SRuslan Ermilov.Fa maxswap
44d0353b83SRuslan Ermilov\- 1 devices.
45d0353b83SRuslan ErmilovThe number of devices, up to
46d0353b83SRuslan Ermilov.Fa maxswap
471a0a9345SRuslan Ermilov\- 1, is returned.
481a0a9345SRuslan ErmilovA grand
49e92324a2SMatthew Dillontotal of all swap devices (including any devices that go beyond
50d0353b83SRuslan Ermilov.Fa maxswap
511a0a9345SRuslan Ermilov\- 1) is returned in one additional array entry.
521a0a9345SRuslan ErmilovThis
53d0353b83SRuslan Ermiloventry is not counted in the return value.
54d0353b83SRuslan ErmilovThus, if you specify a
55d0353b83SRuslan Ermilov.Fa maxswap
56d0353b83SRuslan Ermilovvalue of 1, the function will typically return the
57d0353b83SRuslan Ermilovvalue 0 and the single
58d0353b83SRuslan Ermilov.Vt kvm_swap
59d0353b83SRuslan Ermilovstructure will be filled with
601a0a9345SRuslan Ermilovthe grand total over all swap devices.
611a0a9345SRuslan ErmilovThe grand total is calculated
62e92324a2SMatthew Dillonfrom all available swap devices whether or not you made room
63e92324a2SMatthew Dillonfor them all in the array.
64c75526d5SRuslan ErmilovThe grand total is returned.
65e92324a2SMatthew Dillon.Pp
66e92324a2SMatthew DillonThe flags argument is currently unused and must be passed as 0.
67e92324a2SMatthew Dillon.Pp
68e92324a2SMatthew DillonIf an error occurs, -1 is returned.
69e92324a2SMatthew Dillon.Pp
70d0353b83SRuslan ErmilovEach swap partition and the grand total is summarized in the
71d0353b83SRuslan Ermilov.Vt kvm_swap
721a0a9345SRuslan Ermilovstructure.
731a0a9345SRuslan ErmilovThis structure contains the following fields:
74d0353b83SRuslan Ermilov.Pp
75d0353b83SRuslan Ermilov.Bl -item -offset indent -compact
76d0353b83SRuslan Ermilov.It
77d0353b83SRuslan Ermilov.Va char ksw_devname[] ;
78d0353b83SRuslan Ermilov.It
79eca80cd0SPedro F. Giffuni.Va u_int ksw_total ;
80d0353b83SRuslan Ermilov.It
81eca80cd0SPedro F. Giffuni.Va u_int ksw_used ;
82d0353b83SRuslan Ermilov.It
83d0353b83SRuslan Ermilov.Va int ksw_flags ;
84e92324a2SMatthew Dillon.El
85e92324a2SMatthew Dillon.Pp
86d0353b83SRuslan ErmilovValues are in
87d0353b83SRuslan Ermilov.Dv PAGE_SIZE Ns 'd
88d0353b83SRuslan Ermilovchunks (see
89d0353b83SRuslan Ermilov.Xr getpagesize 3 ) .
90d0353b83SRuslan Ermilov.Va ksw_flags
91d0353b83SRuslan Ermilovcontains
92e92324a2SMatthew Dillona copy of the swap device flags.
93e92324a2SMatthew Dillon.Sh CACHING
94e92324a2SMatthew DillonThis function caches the nlist values for various kernel variables which
95d0353b83SRuslan Ermilovit reuses in successive calls.
96d0353b83SRuslan ErmilovYou may call the function with
97d0353b83SRuslan Ermilov.Fa kd
98d0353b83SRuslan Ermilov==
99d0353b83SRuslan Ermilov.Dv NULL
100e92324a2SMatthew Dillonto clear the cache.
101e92324a2SMatthew Dillon.Sh DIAGNOSTICS
102*ea143d1bSDimitry AndricIf the swap summary information was unobtainable, \-1 is returned;
103*ea143d1bSDimitry Andricotherwise, the number of swap devices actually retrieved is returned.
104e92324a2SMatthew Dillon.Pp
105e92324a2SMatthew DillonIf the name of the swap device does not fit in the static char buffer
1061a0a9345SRuslan Ermilovin the structure, it is truncated.
1071a0a9345SRuslan ErmilovThe buffer is always zero terminated.
108e92324a2SMatthew Dillon.Sh SEE ALSO
109e92324a2SMatthew Dillon.Xr kvm 3
110