UNIX Paging/Swap
Check
free -g
Processes by Swap Space Usage
for file in /proc/*/status
do
awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file
done | sort -k 2 -n -r | less
Top 15 Paging Space Users...
svmon -Pgt15 | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}'
Swappiness
For a full discussion of swappiness see: https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/The "swappiness" of a system determines whether the Linux kernel runs with a preference for reclaiming file pages or anonymous pages.
Setting swappiness to 100 gives file pages and anonymous pages equal priority.
Reducing the swappiness value tells the OS to bias away from anonymous page reclamation.
The default swappiness setting is 60.
Setting the swappiness value to zero simply shifts the swap-associated hard drive activity to file-associated hard drive activity (this might be valid if your filesystem disks are significantly more performant than your swap space disks, but this really is a situation you should avoid).
For single-purpose servers, such as database servers, you may get guidance from the vendor.
You can check the swappiness of your system using...
cat /proc/sys/vm/swappiness
To change the value to, for example, 30...
sudo sysctl vm.swappiness=30
To make the change persistent over a reboot you need to edit the config file...
/etc/sysctl.conf
Add or update a line like this...
vm.swappiness=30
Clearing Swap
Linux
Assuming that used memory plus used swap space is less that the total memory in your system...
swapoff -a
swapoff will fail if there is insufficent memory to stop swappingwait 30 seconds...
swapon -a
Adding Swap
Linux
Adding Swap Partition
Assumes a disk device called /dev/myswap has been created...
sudo mkswap -f /dev/myswap
sudo swapon /dev/myswap
Add this line to the bottom of /etc/fstab...
/dev/myswap swap swap defaults 0 0
Adding Swap File
To add a 4GB swap file (instead of using a swap partition)...
sudo dd if=/dev/zero of=/var/myswap bs=1M count=4096
sudo mkswap /var/myswap
sudo swapon /var/myswap
Add this line to the bottom of /etc/fstab...
/var/myswap swap swap defaults 0 0
Oracle recommends:
RAM Swap Space
Between 1GB and 2GB 1.5 times the size of the RAM
Between 2GB and 16GB Equal to the size of the RAM
More than 16GB 16GB
Determine the target paging space size...
mem=$(lsattr -E -l sys0 -a realmem | awk '{ print $2 }')
(( mem = mem / 1024 ))
if [[ ${mem} -ge 1024 && ${mem} -lt 2048 ]] then (( mem = mem * 1.5 )) fi
if [[ ${mem} -ge 2048 && ${mem} -lt 16384 ]] then (( mem = mem )) fi
if [[ ${mem} -ge 16384 ]] then (( mem = 16384 )) fi
echo $mem
Determine the current paging space size...
lvn=$(lsps -a | grep -v "Page Space" | awk '{ print $1 }')
siz=$(lsps -a | grep -v "Page Space" | awk '{ print $4 }' | tr -d 'MB')
echo $lvn
echo $siz
Determine physical partition (PP) size of the volume group containing the paging space. Divide the amount of extra space required by the PP size to calculate the number of LPs to add...(assumes PP size and LP size are equal)..
pps=$(lslv ${lvn} | grep "PP SIZE" | awk '{ print $6 }')
(( mem = mem - siz ))
(( mem = mem / pps ))
echo $pps
echo $mem
Make the change...
chps -s ${mem} ${lvn}
Bibliography
https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/ https://www.redhat.com/sysadmin/clear-swap-linuxhttps://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/
LRUDhttps://www.ibm.com/support/pages/lrud-process-consuming-cpu