kvm_stats_read(9)
β¨ 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 tagheaderβ 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 vcpustatsβ start address of the stats data block for a vm or a vcpusize_statsβ the size of the stats data block thatstatspoints at πuser_bufferβ start address of the userspace buffer (where the good stuff lands π)sizeβ the requested read size, coming from userspaceoffsetβ 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:
- 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 β¨ - Read the id string from its offset. Also a one-time work for the lifecycle of the corresponding vm/vcpu stats fd π
- 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 π«
- 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms