Showing posts with label swap. Show all posts
Showing posts with label swap. Show all posts

Sunday, November 29, 2015

Setup a swap file for Linux / Ubuntu

Set up a swap file of 2GB in the "/" folder and attach swap to it

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Test:

sudo swapon -s
free -m

Make your changes permanent:

sudo vi /etc/fstab

Add the following line:

/swapfile   none    swap    sw    0   0

save & close the file.

Twek swapinness (0-100). If near to 0 the kernel  will use swap only it is absolutely necessary.  Values near to 100 mean use more swap and use less RAM.
To see swappiness:
 
cat /proc/sys/vm/swappiness
 
and to change it
 
sudo vi /etc/sysctl.conf 
 
and add at the end of the file

vm.swappiness=10
 
(source) 

Wednesday, May 16, 2012

Adding swap space on CentOS

# login as root with
su -

# not '-' sign - important!

#allocate file: 20 GB = 20 * 1024 * 1024
dd if=/dev/zero of=/swapfile bs=1024 count=20971520

mkswap /swapfile

#set permissions:
chown root:root /swapfile
chmod 0600 /swapfile

#add immediately to OS
swapon /swapfile

# edit fstab for persistence:
vi /etc/fstab

# edit fstab by adding the following line at the end of the file:
/swapfile /swap swap defaults 0 0

# check if the swap is allocated
free -m