KSTAT(4)
hey bestie π you're looking at KSTAT(4) from the Kernel Interfaces Manual β the page for kstat, aka kernel statistics. It's giving βpeek behind the kernel curtainβ energy, but make it official. No cap, every flag and field is down below. π«Ά
β¨ NAME β¨
kstat β kernel statistics
πΈ SYNOPSIS πΈ
pseudo-device kstat
Short, iconic, does exactly what it says. π
π¦ DESCRIPTION π¦
The /dev/kstat device exposes kernel statistics (kstats) to userland. That's the whole vibe: kernel data says hi to userland. β¨
π IOCTLS π
The kstat ioctl(2) calls are provided in <sys/kstat.h>.
With the exception of KSTATIOC_VERSION, the kstat ioctl(2) calls use the kstat_req structure to request or enumerate kernel statistic data from the kernel:
struct kstat_req {
unsigned int ks_rflags;
#define KSTATIOC_F_IGNVER (1 << 0)
/* the current version of the kstat subsystem */
unsigned int ks_version;
uint64_t ks_id;
char ks_provider[KSTAT_STRLEN];
unsigned int ks_instance;
char ks_name[KSTAT_STRLEN];
unsigned int ks_unit;
struct timespec ks_created;
struct timespec ks_updated;
struct timespec ks_interval;
unsigned int ks_type;
unsigned int ks_state;
void *ks_data;
size_t ks_datalen;
unsigned int ks_dataver;
};
The kstat subsystem increments a version number when a kstat is added to or removed from the subsystem so changes to the set of kstats can be detected. The current version can be requested with a KSTATIOC_VERSION ioctl(2) call. Programs requesting a kstat with the other ioctl(2) calls pass the current version in ks_version, and if the version differs an error will be returned with errno(2) set to EINVAL to indicate that the program should resynchronise with the kernel subsystem. This check can be disabled by setting the KSTATIOC_F_IGNVER flag in ks_rflags.
A kstat is identified by a 64bit number, or the combination of a provider name, instance number, name, and unit number.
Unless ks_data is NULL, the kstat subsystem will request an update of the statistics data and copy up to ks_datalen bytes of it to the specified memory.
The kstat ioctl(2) calls are as follows:
KSTATIOC_VERSIONunsigned intβ Get the current version of the set of kernel statistics.KSTATIOC_FIND_IDstruct kstat_reqβ Request the kstat identified byks_id.KSTATIOC_NFIND_IDstruct kstat_reqβ Request a kstat with an identifier greater than or equal toks_id.KSTATIOC_FIND_PROVIDERstruct kstat_reqβ Request the kstat identified byks_provider,ks_instance,ks_name, andks_unit.KSTATIOC_NFIND_PROVIDERstruct kstat_reqβ Request the kstat or next kstat from the set of kstats ordered byks_provider,ks_instance,ks_name, andks_unit.KSTATIOC_FIND_NAMEstruct kstat_reqβ Request the kstat identified byks_name,ks_unit,ks_provider, andks_instance.KSTATIOC_NFIND_NAMEstruct kstat_reqβ Request the kstat or next kstat from the set of kstats ordered byks_name,ks_unit,ks_provider, andks_instance.
Upon the successful request of a kstat, the kstat driver will update the kstat_req structure with current information about that kstat. Updated fields include:
ks_versionβ The current version of the kstat subsystem.ks_idβ The 64bit unique identifier for the requested kstat. A kstat can be requested using this identifier and theKSTATIOC_FIND_IDioctl(2)call.ks_provider,ks_instance,ks_name,ks_unitβ The fully specified identifier of the kstat. A kstat can be requested using these identifiers with theKSTATIOC_FIND_NAMEandKSTATIOC_FIND_PROVIDERioctl(2)calls. Groups of kstats with the same identifier or name can be enumerated or requested with theKSTATIOC_NFIND_NAMEandKSTATIOC_NFIND_PROVIDERioctl(2)calls without having to fetch the entire set of kstats and filtering them.ks_createdβ The system uptime when the kstat was created and added to the kstat subsystem.ks_updatedβ The system uptime at which the kstat data payload was last updated. A kstat provider may update data when requested, or report when data was last updated by some other process.ks_updatedcan be used by a program to identify if data has been updated, or for calculating rates of changes of values between updates.ks_typeβ The type or structure of the data payload. Currently supported types are documented inkstat_create(9).ks_datalenβ The amount of data the kstat provides in bytes. When requesting kstat data, the program specifies the amount of space available atks_databy setting this variable.
π FILES π
/dev/kstat
π₯ SEE ALSO π₯
π HISTORY π
The kstat device appeared in OpenBSD 6.8. Periodt. π
okay bestie, that's the whole page β this little love letter is from the Debian build, dated January 14, 2022, and it's filed under KSTAT(4). Go forth and check those kstats. πβ¨
π¦ where this page comes from
- nixpkgs unstable: cvs-export
- Copyright (c) 2022 Jonathan Gray <jsg@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms