---
name: "kstat"
section: "4"
platform: "openbsd"
package: "man"
version: "8.0-current-20261101"
release: "OpenBSD 8.0-current (2026-11-01)"
platforms: ["openbsd"]
url: "https://new.carta.tech/kstat/4"
---

# kstat(4)

kernel statistics

## NAME

**kstat** – kernel statistics

## SYNOPSIS

**pseudo-device kstat**

## DESCRIPTION

The */dev/kstat* device exposes kernel statistics (kstats) to userland.

## IOCTLS

The kstat [ioctl(2)](/ioctl/2.md) calls are provided in ⟨sys/kstat.h⟩.

With the exception of KSTATIOC\_VERSION, the kstat [ioctl(2)](/ioctl/2.md) 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)](/ioctl/2.md) call. Programs requesting a kstat with the other [ioctl(2)](/ioctl/2.md) calls pass the current version in *ks\_version*, and if the version differs an error will be returned with [errno(2)](/errno/2.md) 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)](/ioctl/2.md) calls are as follows:

- KSTATIOC\_VERSION *unsigned int*

  Get the current version of the set of kernel statistics.

- KSTATIOC\_FIND\_ID *struct kstat\_req*

  Request the kstat identified by *ks\_id*.

- KSTATIOC\_NFIND\_ID *struct kstat\_req*

  Request a kstat with an identifier greater than or equal to *ks\_id*.

- KSTATIOC\_FIND\_PROVIDER *struct kstat\_req*

  Request the kstat identified by *ks\_provider*, *ks\_instance*, *ks\_name*, and *ks\_unit*.

- KSTATIOC\_NFIND\_PROVIDER *struct kstat\_req*

  Request the kstat or next kstat from the set of kstats ordered by *ks\_provider*, *ks\_instance*, *ks\_name*, and *ks\_unit*.

- KSTATIOC\_FIND\_NAME *struct kstat\_req*

  Request the kstat identified by *ks\_name*, *ks\_unit*, *ks\_provider*, and *ks\_instance*.

- KSTATIOC\_NFIND\_NAME *struct kstat\_req*

  Request the kstat or next kstat from the set of kstats ordered by *ks\_name*, *ks\_unit*, *ks\_provider*, and *ks\_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 the KSTATIOC\_FIND\_ID [ioctl(2)](/ioctl/2.md) 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 the KSTATIOC\_FIND\_NAME and KSTATIOC\_FIND\_PROVIDER [ioctl(2)](/ioctl/2.md) calls. Groups of kstats with the same identifier or name can be enumerated or requested with the KSTATIOC\_NFIND\_NAME and KSTATIOC\_NFIND\_PROVIDER [ioctl(2)](/ioctl/2.md) 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\_updated* can by 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 in kstat\_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 at *ks\_data* by setting this variable.

## FILES

- */dev/kstat*

  ## SEE ALSO

kstat\_create(9), kstat\_kv\_init(9)

## HISTORY

The **kstat** device appeared in OpenBSD 6.8.
