Swapping

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

Memory swapping is a computer technology that enables an operating system to provide more memory to a running application or process than is available in physical random access memory (RAM). When the physical system memory is exhausted, the operating system can opt to make use of memory swapping techniques to get additional memory. Mostly, swapping means the os outsource some memory to the swap space on a disk (In Linux this is a disk partition and in Windows there is a swap file called "pagefile.sys")

Display processes using swap space

find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -h | cut -d " " -f2-


Swappiness configuration (Debian based Linux distributions)

This control is used to define how aggressive (sic) the kernel will swap memory pages. Higher values will increase aggressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone. Get current used swap space:

free -h

Get current swappiness configuration

sysctl vm.swappiness

Change swappiness for the current session (swappiness config are removed after reboot):

sudo sysctl vm.swappiness=0

Change swappiness persitent (in sysctl.conf under /etc/)

# Add this line to change swappiness from a default (60) to 0 (decrease swap usage)
vm.swappiness = 0


Disable Swap

Disable swapping for the current session:

swapoff -a

Disable swap permanently:

  • In /etc/fstab comment the entire line of the swap-space by adding a #.