On Linux, what is the size of pages reported by vmstat command and/or /proc/vmstat?
As many have stated on StackExchange and elsewhere, a typical kernel/mmu page size for Linux is 4 KiB. I have verified that this is the case on my OS/architecture (RHEL 6.6, Intel Xeon E5-2690).
Now among other things, the vmstat -s
command reports on "pages paged in" and "pages paged out", which are counters that start from 0 at boot time. I have confirmed that at any given moment, these values are exactly equal to the values found for the pgpgin
and pgpgout
entries in /proc/vmstat
(does vmstat command get them from /proc/vmstat
?). Other commands, and in particular sar -B
report pgpgin/s
and pgpgout/s
as Kibibytes paged in/out per second during a particular interval.
In recent tests, I have seen that pgpgin/s
and pgpgout/s
values from sar also correspond exactly to a rate calculated from vmstat values for a specified interval. This leads me to conclude that vmstat is reporting values for pages of 1 KiB in size. Thus the pgpgin/out
values of /proc/vmstat
are the number of KiB paged in/out since boot.
My questions are:
- Is this a valid conclusion, and
- If so, why do vmstat and other facilities report in 1 KiB pages instead of the 4 KiB pages that are the "common currency" of the OS and architecture? In particular, vmstat is saying "
pages paged in/out
", not "KiBs paged in/out
". This is confusing.
Solution 1:
In regards to the counters in /proc/vmstat
the function that appears to update these values is submit_bio
in Linux/block/blk-core.c
.
2067 blk_qc_t submit_bio(struct bio *bio)
2068 {
...
2079 count = bio_sectors(bio);
2080
2081 if (op_is_write(bio_op(bio))) {
2082 count_vm_events(PGPGOUT, count);
2083 } else {
2084 task_io_account_read(bio->bi_iter.bi_size);
2085 count_vm_events(PGPGIN, count);
2086 }
...
2100 }
2101 EXPORT_SYMBOL(submit_bio);
bio_sectors
is a macro in Linux/include/linux/bio.h
64 #define bio_sectors(bio) ((bio)->bi_iter.bi_size >> 9)
This seems to suggest to me that the numbers are counted in sector sizes (512) bytes. Given thats what value you'd end up getting if you right shifted a byte count by nine.
This appears to be a similar setup between kernels 2.6.27 - 4.0.x anyways.