KVM_SWAPINFO(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

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