xref: /freebsd/lib/libkvm/kvm_getswapinfo.3 (revision 1b6c76a2fe091c74f08427e6c870851025a9cf67)
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 under the terms of the BSD
5.\" Copyright as found in /usr/src/COPYRIGHT in the FreeBSD source tree.
6.\"
7.\" $FreeBSD$
8.\"
9.Dd January 22, 1999
10.Dt KVM_SWAPINFO 3
11.Os
12.Sh NAME
13.Nm kvm_getswapinfo
14.Nd return swap summary statistics for the system
15.Sh LIBRARY
16.Lb libkvm
17.Sh SYNOPSIS
18.Fd #include <kvm.h>
19.Ft int
20.Fn kvm_getswapinfo "kvm_t *kd" "struct kvm_swap *" "int maxswap" "int flags"
21.Sh DESCRIPTION
22The
23.Fn kvm_getswapinfo
24function fills an array of
25.Vt kvm_swap
26structures with swap summary
27information for each swap device, for up to
28.Fa maxswap
29\- 1 devices.
30The number of devices, up to
31.Fa maxswap
32\- 1, is returned.  A grand
33total of all swap devices (including any devices that go beyond
34.Fa maxswap
35\- 1) is returned in one additional array entry.  This
36entry is not counted in the return value.
37Thus, if you specify a
38.Fa maxswap
39value of 1, the function will typically return the
40value 0 and the single
41.Vt kvm_swap
42structure will be filled with
43the grand total over all swap devices.  The grand total is calculated
44from all available swap devices whether or not you made room
45for them all in the array.
46the grant total is returned.
47.Pp
48The flags argument is currently unused and must be passed as 0.
49.Pp
50If an error occurs, -1 is returned.
51.Pp
52Each swap partition and the grand total is summarized in the
53.Vt kvm_swap
54structure.  This structure contains the following fields:
55.Pp
56.Bl -item -offset indent -compact
57.It
58.Va char ksw_devname[] ;
59.It
60.Va int ksw_total ;
61.It
62.Va int ksw_used ;
63.It
64.Va int ksw_flags ;
65.El
66.Pp
67Values are in
68.Dv PAGE_SIZE Ns 'd
69chunks (see
70.Xr getpagesize 3 ) .
71.Va ksw_flags
72contains
73a copy of the swap device flags.
74.Pp
75.Sh CACHING
76This function caches the nlist values for various kernel variables which
77it reuses in successive calls.
78You may call the function with
79.Fa kd
80==
81.Dv NULL
82to clear the cache.
83.Sh DIAGNOSTICS
84If the load average was unobtainable, \-1 is returned; otherwise,
85the number of swap devices actually retrieved is returned.
86.Pp
87If the name of the swap device does not fit in the static char buffer
88in the structure, it is truncated.  The buffer is always zero terminated.
89.Sh SEE ALSO
90.Xr kvm 3
91