ef1gcw
Last Updated: July 16, 2019
·
2.236K
· infoslack

Managing RAM and SWAP

Have you ever had to clean the cache RAM or SWAP your unix like ?

The linux saves space in the cache for programs and commands that have been recently used, allowing to run more quickly in the future.
This space can reach the limit of physical memory, causing delays in execution of processes.

Clearing the cache RAM

$ sync
$ echo 3 > /proc/sys/vm/drop_caches

or use sysctl to configure kernel parameters at runtime

$ sysctl vm.drop_caches=3
  • sync makes the whole system cache files that are temporarily stored in memory, be discharged and released on disk, avoiding data loss.
  • option 3 does the kernel release pagecache, dentries and inodes.
  • other options: 1 is only released pagecache, 2 inodes and frees pagecache
  • to learn more: Drop Caches and Sysctl vm

Controlling SWAP

You can configure the behavior of the system in relation to the SWAP through a kernel parameter in the file /proc/sys/vm/swappiness.
This file contains a number from 0 to 100, the system determines the predisposition to use SWAP.
A low number makes him leave to use SWAP only in extreme situations, while a higher number, it makes more use SWAP, which keeps more RAM free to use the disk cache.

Increasing or decreasing the use of SWAP

$ echo "90" > /proc/sys/vm/swappiness
$ echo "10" > /proc/sys/vm/swappiness

or use sysctl to configure kernel parameters at runtime

$ sysctl vm.swappiness=20

Remember to reset the SWAP partition to validate the configuration:

$ swapoff -a
$ swapon -a

Use with caution =)