10

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 :)

1
  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.
| improve this answer | |
  • 6
    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 Aug 24 '17 at 3:43
  • 3
    pswpin/pswpout is the number of pages, not kilobytes. – George Sovetov Oct 9 '19 at 20:09
1

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

| improve this answer | |
  • 2
    pswpi/pswpout = pages in/out not kilobytes in/out – IanB May 8 '15 at 5:29
  • 5
    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 Aug 24 '17 at 3:42
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
| improve this answer | |

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.