Hi. I'm jon.404, a Unix/Linux/Database/Openstack/Kubernetes Administrator, AWS/GCP/Azure Engineer, mathematics enthusiast, and amateur philosopher. This is where I rant about that which upsets me, laugh about that which amuses me, and jabber about that which holds my interest most: *nix.
Paging? Swapping? Which is it?
Posted 04-15-2013 at 11:52 AM by rocket357
It's a bit big to be called a "one-liner", but this "script" will give you a short overview of paging levels vs. swapping levels on your machine.
Set T=<seconds> to whatever timeframe you want to test for.
Demand Paging:
"Shuffling" individual pages around (i.e. reading another block of code in from the executable file stored on disk, or flushing dirty pages back to disk). Could also occur if a page in the filesystem cache is "paged" in to a process's address space.
Swapping:
Moving infrequently used pages out to the swap area or recalling them back in from the swap area when they are needed.
Set T=<seconds> to whatever timeframe you want to test for.
Code:
T=5; ( vmstat -s; sleep $T; vmstat -s ) | awk -v T="$T" -F'[(/)]' '/pages paged in/{ pgpio=pgpin; pgpin=$1 } /pages paged out/{ pgpoo=pgpon; pgpon=$1 } /pages swapped in/{ pgsio=pgsin; pgsin=$1 } /pages swapped out/{ pgsoo=pgson; pgson=$1 } END { printf "== Current %i second intervals ==\nPaged in: %6.0f = %6.3f KB/s\nPaged out: %6.0f = %6.3f KB/s\nSwapped in: %6.0f = %6.3f KB/s\nSwapped out: %6.0f = %6.3f KB/s\n", T, pgpin-pgpio, ((pgpin-pgpio)*4)/T, pgpon-pgpoo, ((pgpon-pgpoo)*4)/T, pgsin-pgsio, ((pgsin-pgsio)*4)/T, pgson-pgsoo, ((pgson-pgsoo)*4)/T}';
"Shuffling" individual pages around (i.e. reading another block of code in from the executable file stored on disk, or flushing dirty pages back to disk). Could also occur if a page in the filesystem cache is "paged" in to a process's address space.
Swapping:
Moving infrequently used pages out to the swap area or recalling them back in from the swap area when they are needed.
Total Comments 2
Comments
-
Very handy. Thanks.
Posted 04-15-2013 at 12:50 PM by vmccord -
You're welcome, vmccord.
Posted 04-15-2013 at 01:10 PM by rocket357