tags: - ubuntu categories: - informational comments: true
In case of lack of system memory, add a file system based swap file. Ensure there is atleast 1GB disk space to create a swap file.
fallocate -l 1G /swapfile dd if=/dev/zero of=/swapfile bs=1024 count=1048576 chmod 600 /swapfile mkswap /swapfile
vi /etc/fstab /swapfile swap swap defaults 0 0
Direct quote from Ubuntu web page
The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk.
Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.
swappiness can have a value of between 0 and 100
swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
The default setting in Ubuntu is swappiness=60.
Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation.
A value of swappiness=10 is recommended, but feel free to experiment.
Note: Ubuntu server installations have different performance requirements to desktop systems, and the default value of 60 is likely more suitable.
To check the swappiness value
To change the swappiness value A temporary change (lost on reboot) with a swappiness value of 10 can be made with
sudo sysctl vm.swappiness=10
To make a change permanent, edit the configuration file with your favorite editor:
cat /etc/sysctl.d/100-swap-manager.conf vm.swappiness=60 vm.vfs_cache_pressure=120 sysctl -p
At the default value of
vfs_cache_pressure=100 the kernel will attempt to reclaimd
entries and inodes at a “fair” rate with respect to pagecache and swapcache reclaim.
vfs_cache_pressure causes the kernel to prefer to retain dentry and
vfs_cache_pressure=0, the kernel will never reclaim dentries and inodes due
to memory pressure and this can easily lead to out-of-memory conditions.
vfs_cache_pressure beyond 100 causes the kernel to prefer to reclaim
dentries and inodes.