KVM_SWAPINFO(3)
okay bestie, this is KVM_SWAPINFO(3) from the Library Functions Manual, and itβs giving kernel data access with a side of swap stats π
buckle up.
π NAME π
kvm_getswapinfo β returns swap summary statistics for the system. yes, literally that, no cap β¨
π LIBRARY π
Kernel Data Access Library (libkvm, -lkvm). thatβs where this icon lives π«Ά
π§ SYNOPSIS π§
#include <kvm.h>
int
kvm_getswapinfo(kvm_t *kd, struct kvm_swap *, int maxswap, int flags);
π DESCRIPTION π
so kvm_getswapinfo() fills an array of kvm_swap structures with swap summary info 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. that extra entry is not counted in the return value. periodt.
so 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. math is mathing π₯
the flags argument is currently unused and must be passed as 0. donβt try to be cute with it.
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)). ksw_flags contains a copy of the swap device flags. slay.
π¦ 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. iconic little cache moment π«
π DIAGNOSTICS π
if the swap summary information was unobtainable, -1 is returned; otherwise, the number of swap devices actually retrieved is returned. bestie, thatβs the whole vibe check.
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. noted, no cap π
π SEE ALSO π
kisses, this page is sourced/versioned as Debian and dated January 2, 2017. KVM_SWAPINFO(3) out πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (C) 1999 Matthew Dillon. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms