1

I know that:

  • paging and swapping is done to/from the disk
  • /proc/io gives information of disk I/O

However, I am not sure if /proc/<pid>/io includes I/O that was expected to be done on RAM but went to the disk because of paging and swapping. Do the figures on /proc/<pid>/io include paging and swapping I/O?

  • I would doubt it, since it's the kernel doing the reading and writing of the swap, not the process. But I might be wrong. – Kusalananda Jan 8 '17 at 17:52
2

I had the same question, so I decided to perform some experiments with the swap usage and I/O accounting.

I wrote a simple program, that just requests a large amount of memory and fills it with data:

#include <malloc.h>
#include <string.h>
#include <stdio.h>

int main() {
    for (int i = 0; i < 5000; i++) {
        void* ptr = malloc(1000000);
        memset(ptr, 42, 1000000);
    }

    // Hang for a while to allow us analyze /proc.
    puts("Finished");
    while(1);

    return 0;
}

Then I started running it, increasing the amount of the memory requested with every run (5G, 10G, 12G and so on), and watched the process' /proc/$PID/io and /proc/$PID/status. The following parameters from /proc/$PID/io remained the same for every run (and this was expected, as these parameters show syscall-level IO statistics):

rchar: 1948
wchar: 9
syscr: 7
syscw: 1

The next two parameters, which (as per the kernel procfs documentation) show actual disk I/O, caused by the process, were set to zeroes (it's likely that the program image was already cached in the memory from the previous executions, so execve did not cause a real disk I/O):

read_bytes: 0
write_bytes: 0

When I was close to RAM size (16G), the kernel started to swap out program's memory in quite large amounts (~4G):

$ cat /proc/$PID/status | grep VmSwap
VmSwap:  3908152 kB

At the same time some strange values appeared in /proc/$PID/io:

read_bytes: 307200
write_bytes: 0

Non-zero value of read_bytes appeared when the kernel started swapping, and remained almost the same (~300k) while amount of swap used by the process increased with every consequent run (until it started triggering the OOMKiller).

I repeated these experiments a few times, and the picture remained the same: write_bytes was zero all the time, and read_bytes changed from zero to some small (relatively to the memory amount being swapped) value around 300-400k.

Based on this, I think that /proc/$PID/io does not account actual swap reads and writes, but it accounts some internal kernel activities, caused by the swap usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.