UNIX Paging/Swap

Check

free -g

              total        used        free      shared  buff/cache   availableMem:             58          44           1           2          12          10Swap:            15          12           3

lsps -s

lsps -a

AIX refers to Swap space as Paging space
Example output from lsps -sTotal Paging Space   Percent Used      26240MB              44%
Example output from lsps -aPage Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type Chksumhd6             hdisk0            rootvg       26240MB    44   yes   yes    lv     0

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(/^-+$/)}'

The "swappiness" of a system determines whether the Linux kernel runs with a preference for reclaiming  file pages or anonymous pages. 

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 swapping

wait 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