---
name: "kvm_getswapinfo"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/kvm_getswapinfo"
---

# kvm\_getswapinfo(3)

return swap summary statistics for the system

## NAME

**kvm\_getswapinfo** – return swap summary statistics for the system

## LIBRARY

Kernel Data Access Library (libkvm, -lkvm)

## SYNOPSIS

**#include \<kvm.h\>**

*int*\

**kvm\_getswapinfo**(*kvm\_t \*kd*, *struct kvm\_swap \**, *int maxswap*, *int flags*);

## DESCRIPTION

The **kvm\_getswapinfo**() function fills an array of *kvm\_swap* structures with swap summary information for each swap device, for up to *maxswap* - 1 devices. The number of devices, up to *maxswap* - 1, is returned. A grand total of all swap devices (including any devices that go beyond *maxswap* - 1) is returned in one additional array entry. This entry is not counted in the return value. Thus, if you specify a *maxswap* value of 1, the function will typically return the value 0 and the single *kvm\_swap* structure will be filled with the grand total over all swap devices. The grand total is calculated from all available swap devices whether or not you made room for them all in the array. The grand total is returned.

The flags argument is currently unused and must be passed as 0.

If an error occurs, -1 is returned.

Each swap partition and the grand total is summarized in the *kvm\_swap* structure. This structure contains the following fields:

-

  *char* *ksw\_devname\[\]*;

-

  *u\_int* *ksw\_total*;

-

  *u\_int* *ksw\_used*;

-

  *int* *ksw\_flags*;

Values are in PAGE\_SIZE'd chunks (see [getpagesize(3)](/getpagesize/3.md)). *ksw\_flags* contains a copy of the swap device flags.

## CACHING

This function caches the nlist values for various kernel variables which it reuses in successive calls. You may call the function with *kd* == NULL to clear the cache.

## DIAGNOSTICS

If the swap summary information was unobtainable, -1 is returned; otherwise, the number of swap devices actually retrieved is returned.

If the name of the swap device does not fit in the static char buffer in the structure, it is truncated. The buffer is always zero terminated.

## SEE ALSO

[kvm(3)](/kvm/3.md)
