kvm_stats_read(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ NAME ✨

kvm_stats_read β€” the common function to read from the binary statistics file descriptor πŸ’– (and yes bestie, this is a section 9 Kernel API Manual moment, we're in kernel developer territory, act accordingly πŸ’…)


πŸŽ€ SYNOPSIS πŸŽ€

ssize_t kvm_stats_read (char *id , const struct kvm_stats_header *header
, const struct kvm_stats_desc *desc , void *stats , size_t size_stats ,
char __user *user_buffer , size_t size , loff_t *offset );

🌸 ARGUMENTS 🌸

  • id β€” the identification string of the stats 🏷️ like, its little name tag
  • header β€” the stats header, for a vm or a vcpu (both welcome here 🫢)
  • desc β€” start address of an array of stats descriptors, again for a vm or a vcpu
  • stats β€” start address of the stats data block for a vm or a vcpu
  • size_stats β€” the size of the stats data block that stats points at πŸ“
  • user_buffer β€” start address of the userspace buffer (where the good stuff lands 🎁)
  • size β€” the requested read size, coming from userspace
  • offset β€” the start position that the content gets read from, for the corresponding vm or vcpu file descriptor πŸ“

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the file content of a vm/vcpu file descriptor is now defined like this, no cap πŸ‘‡

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Header      β”‚
β”‚ id string   β”‚
β”‚ Descriptors β”‚
β”‚ Stats Data  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

so like, this function technically lets userspace read any amount of data (as long as it's in the limit βœ‹) from any position, but the typical usage? it's giving a whole little ritual. here's the steps everyone actually follows:

  1. Read the header from offset 0. Grab the offset of the descriptors and the stats data, plus some other necessary information. This is a one-time work for the lifecycle of the corresponding vm/vcpu stats fd ✨
  2. Read the id string from its offset. Also a one-time work for the lifecycle of the corresponding vm/vcpu stats fd πŸŽ€
  3. Read the descriptors from their offset and discover all the stats by parsing the descriptors. Yep β€” one-time work for the lifecycle of the corresponding vm/vcpu stats fd πŸ’«
  4. Periodically read the stats data from its offset using pread πŸ” (this is the part where you just keep coming back, main character energy)

πŸ’« RETURN πŸ’«

the number of bytes that has been successfully read πŸ“Š slay.


🌈 SEE ALSO 🌈

Kernel file ./virt/kvm/binary_stats.c πŸ‘€ go read it, iykyk


kay so that's the whole page, bestie β€” brought to you from ./virt/kvm, dated October 2026, and it's literally kvm_stats_read(9) fr fr. mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from