5

Most of the fields are understandable but can someone please explain me the difference between "pages paged in" and "pages swapped in"?. I'm pretty sure that swapping is when the entire process is moved into the swap space on the hard drive and paging is when some pages are moved into the swap space. So does this mean that "pages paged in" are the pages that belong to sections of processes that are moved into main memory and "pages swapped in" are the pages that belong to entire processes moved into main memory? Can someone shed some light here please. If you have additional information regarding the other fields that would be great too. I have read the manual but did not found useful information regarding this command with this specific option. Example of the command output:

vmstat -s
       131072 K total memory
       125700 K used memory
        59836 K active memory
        49268 K inactive memory
         5372 K free memory
            0 K buffer memory
       101984 K swap cache
            0 K total swap
            0 K used swap
            0 K free swap
        18594 non-nice user cpu ticks
            0 nice user cpu ticks
        17990 system cpu ticks
    108464145 idle cpu ticks
         1121 IO-wait cpu ticks
            0 IRQ cpu ticks
            0 softirq cpu ticks
            0 stolen cpu ticks
       123672 pages paged in
       486324 pages paged out
            0 pages swapped in
            0 pages swapped out
            0 interrupts
      7439516 CPU context switches
   1457280256 boot time
       131927 forks

This is the output of a related file that can help to contrast values and understand it better, it was taken at the same time than the previous one:

cat /proc/meminfo
MemTotal:         131072 kB
MemFree:            5404 kB
Cached:           101984 kB
Buffers:               0 kB
Active:            59820 kB
Inactive:          49268 kB
Active(anon):      11532 kB
Inactive(anon):    16920 kB
Active(file):      48288 kB
Inactive(file):    32348 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         28452 kB
Shmem:             21348 kB
Slab:              16544 kB
SReclaimable:      10580 kB
SUnreclaim:         5964 kB

2 Answers 2

5

Consider your program needs to load in to the memory to run. You have certain amount of address space available and your program needs more. Divide this address space available to you into pages. These are called virtual pages. Try mapping these virtual pages into physical memory and assume you do not have enough physical memory to load all pages. You will load the pages that are immediately needed and leave the one you don't need right now out. But when the time comes you will unload unused pages to load pages needed for the program to run. This is what the paging algorithm does and you see as "pages paged in" and "pages paged out".

Swap-in or swap-out on the other hand deals with the whole memory space required to run your program. Let's say your process is in a state it is waiting for some resource to be available. There is no need for it to stay loaded into the memory, until the condition get satisfied. Meanwhile there are other processes waiting for memory to run. The your whole process gets swapped out and then swapped back in, when the time comes.

Considering the modern systems with gobs of physical memory, swapping is becoming the thing of the past for most systems.

Of course neither of the algorithms (paging and/or swapping) is that simple. This is just a ten thousand feet overview. You can read much more detail about these, elsewhere on the web.

3
  • Thank you, so do you consider this definitions to be correct? - pages paged in: pages affected by the paging algorithm which are in main memory; the paging algorithm work with portions of programs code - pages paged out: pages affected by the paging algorithm which are in the hard drive swap space; the paging algorithm work with portions of programs code Mar 10, 2016 at 3:59
  • - paged swapped in: pages affected by the swapping algorithm which are in main memory; the swapping algorithm move entire programs in and out of main memory and is a thing of the past for most systems - pages swapped out: pages affected by the swapping algorithm which are in the hard drive swap space; the swapping algorithm move entire programs in and out of main memory and is a thing of the past for most systems Mar 10, 2016 at 4:00
  • I have hard time tracking the two part comment but for the most part, it is safe to say yes.
    – MelBurslan
    Mar 10, 2016 at 4:04
1

/proc/vmstat (since Linux 2.6.0)

This file displays various virtual memory statistics. Each line of this file contains a single name-value pair, delimited by white space. ... Details can be found by consulting the kernel source code.)

It is of course cheap to criticize man 5 proc, but some guidance/overview would be welcome.

mm/vmstat.c:

#ifdef CONFIG_VM_EVENT_COUNTERS
        /* enum vm_event_item counters */
        "pgpgin",
        "pgpgout",
        "pswpin",
        "pswpout",
         ...

(Before this part, the /* Node-based counters */ are listed, also some other sets (zone, numa, writeback))

These are event counters, not the number of pages in Memory at a given moment.

Here three main events with values from /proc/vmstat as I see it (with formatted numbers)

    pgpgin           2'023'720
    pgpgout         32'622'399
    pswpin                   0
    pswpout                  0
    ...
    pgalloc_normal 753'397'448

Unlike a bank account, you can not say:

money_now = money_in - money_out

because MM is complicated.

I'm pretty sure that swapping is when the entire process is moved into the swap space

Before consulting the source, you should also consult wikipedia. This is the original meaning of swapping half a century ago.


Petr wrote 2016 on superuser:

So in a 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

(vmstat 1 5 can also monitor: for five secs every sec one value for si and so (difference in bytes, not sum of pages))

Petr: So old question and no correct answer so far.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .