What is the exact difference between the parameters (pgpgin, pswpin) and (pswpout, pgpgout) in /proc/vmstat?

15,078

Solution 1

So old question and no correct answer so far.

First of all, memory is segmented by CPU and Kernel into so called pages. Size of page is given by architecture of CPU, many architectures support multiple different page sizes, but most common page size in x86_64 architecture has 4KB in size. These parameters you talk about are showing how many memory pages were either read / written to disk and how many of them are swap.

Keep in mind that page in is a normal activity in Linux kernel, it happens almost every time when you load a binary from disk (that is not cached) into operating memory - that is everytime you start any application.

Because pgin and pgout operations are not always something you need to worry about, additional counters were created that contain only information for swap - that's the pswpin and pswpout counters - they are incremented when a memory page is either written into swap or when it's read from swap.

Again - this also doesn't indicate a problem, it only indicate problem under certain circumstances - such as when you see these numbers changing very much in short period of time (which is usually when your system is out of memory).

So in nutshell:

  • pgpgin, pgpgout - number of pages that are read from disk and written to memory, you usually don't need to care that much about these numbers
  • pswpin, pswpout - you may want to track these numbers per time (via some monitoring like prometheus), if there are spikes it means system is heavily swapping and you have a problem

Solution 2

For latest Linux kernels pgpgin – Number of kilobytes the system has paged in from disk per second. pgpgout – Number of kilobytes the system has paged out to disk per second.

pswpin – Number of pages the system has swapped in from disk per second. pswpout – Number of pages the system has swapped out to disk per second.

The pgpgin and pgpgout essentially indicates IO activity.

As pointed out in email

Solution 3

  1. pgpgin - Number of kilobytes the system has paged in from disk per second.
  2. pgpgout - Number of kilobytes the system has paged out to disk per second.
  3. pswpin - Number of kilobytes the system has swapped in from disk per second.
  4. pswpout - Number of kilobytes the system has swapped out to disk per second.
Share:
15,078

Related videos on Youtube

Nehal J Wani
Author by

Nehal J Wani

Trying to learn technical stuff.

Updated on September 18, 2022

Comments

  • Nehal J Wani
    Nehal J Wani over 1 year

    Please note that this question is specific to linux only. And by swap space, I mean the dedicated swap partition.

    I did google a bit on this, and found these definitions:

    Paging refers to writing portions, termed pages, of a process’ memory to disk.
    Swapping, strictly speaking, refers to writing the entire process, not just part, to disk.
    In Linux, true swapping is exceedingly rare, but the terms paging and swapping
    often are used interchangeably.
    

    and

    page-out: The system's free memory is less than a threshold "lotsfree" and unnused / least used pages are moved to the swap area.
    page-in: One process which is running requested for a page that is not in the current memory (page-fault), it's pages are being brought back to memory.
    swap-out: System is thrashing and has deactivated a process and it's memory pages are moved into the swap area.
    swap-in: A deactivated process is back to work and it's pages are being brought into the memory.
    

    Now, you may want to duplicate this question with the ones asking about differences between paging and swapping. But I seek a bit more. At any point of time, are these counters in /proc/vmstat mutually exclusive? By that, I mean, does the parameter pswpin include some counts from pgpgin or vice-verse? What exactly happens when a process is deactivated? If all of its pages are moved to swap space, then how exactly is it different from multiple pageouts? Also, if a pagein occurs whenever a page fault occurs, what can one say about the other two parameters pgmajfault and pgfault with respect to this event? Is it the case that whenever a pagefault (major? minor?) occurs, a corresponding pagein also occurs?

    It would be helpful if some example programs/benchmarks are suggested to test these individual parameters.

    PS: I may keep adding/editing the questions :)

  • IanB
    IanB almost 9 years
    pswpi/pswpout = pages in/out not kilobytes in/out
  • devkev
    devkev over 6 years
    The values in /proc/vmstat are not per second, they are total since last boot (see linuxinsight.com/proc_vmstat.html). If you want rate values over some unit of time, then you need to take the difference between the /proc/vmstat values - which is exactly what utilities like vmstat and sar can do for you.
  • devkev
    devkev over 6 years
    The values in /proc/vmstat are not per second, they are total since last boot (see linuxinsight.com/proc_vmstat.html). If you want rate values over some unit of time, then you need to take the difference between the /proc/vmstat values - which is exactly what utilities like vmstat and sar can do for you.
  • George Sovetov
    George Sovetov over 4 years
    pswpin/pswpout is the number of pages, not kilobytes.
  • Daniel Beardsley
    Daniel Beardsley over 3 years
    Exactly the answer I've been scouring the internet for, thank you!