Swap: Difference between revisions

From Halfface
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 6: Line 6:
To return swap to ram.
To return swap to ram.
  swapoff -a; swapon -a
  swapoff -a; swapon -a
(swapoff -a; swapon -a) & watch free -m
See swappiness value.
See swappiness value.
  cat /proc/sys/vm/swappiness
  cat /proc/sys/vm/swappiness
Line 11: Line 12:
  sudo sysctl vm.swappiness=0
  sudo sysctl vm.swappiness=0
sort processes on swap usage.
sort processes on swap usage.
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k2 -n | tail
<pre>
for PROCESS in /proc/*/; do  swapused=$(awk 'BEGIN { total = 0 } /^Swap:[[:blank:]]*[1-9]/ { total = total + $2 } END { print total }' ${PROCESS}/smaps 2>/dev/null || echo 0);  if [ $swapused -gt 0 ]; then    /bin/echo -e "${swapused}k\t$(cat ${PROCESS}/cmdline)";  fi; done | sort -nr
for PROCESS in /proc/*/; do  swapused=$(awk 'BEGIN { total = 0 } /^Swap:[[:blank:]]*[1-9]/ { total = total + $2 } END { print total }' ${PROCESS}/smaps 2>/dev/null || echo 0);  if [ $swapused -gt 0 ]; then    /bin/echo -e "${swapused}k\t$(cat ${PROCESS}/cmdline)";  fi; done | sort -nr
</pre>
=add swap on existing disk=
dd if=/dev/zero of=swapfile bs=1M count=10000
mkswap swapfile
swapon swapfile

Latest revision as of 10:58, 13 March 2024

How to handle swappiness

Start top and press O then p to sort by swap.

top -c

Look to see if any swap is being used. si and so is swap in and swap out.

vmstat 1

To return swap to ram.

swapoff -a; swapon -a
(swapoff -a; swapon -a) & watch free -m

See swappiness value.

cat /proc/sys/vm/swappiness

To set swippiness value.

sudo sysctl vm.swappiness=0

sort processes on swap usage.

for PROCESS in /proc/*/; do   swapused=$(awk 'BEGIN { total = 0 } /^Swap:[[:blank:]]*[1-9]/ { total = total + $2 } END { print total }' ${PROCESS}/smaps 2>/dev/null || echo 0);   if [ $swapused -gt 0 ]; then     /bin/echo -e "${swapused}k\t$(cat ${PROCESS}/cmdline)";   fi; done | sort -nr

add swap on existing disk

dd if=/dev/zero of=swapfile bs=1M count=10000
mkswap swapfile
swapon swapfile