In this writing, I’m going to explain what Swap Space is and how to increase it.
What is Swap Space?
Swap space is a space reserved by the operating system on hard disk. When the data to be processed is larger than the size of RAM, that space is used as RAM. Thus, continuation of the processes is provided. Since read/write speed of hard disks is pretty lower than that of RAMs, using Swap space slows processes. That’s why, you should try not to use it. If your server uses Swap space, you should find out why or else you may experience performance loss.
If you’re going to configure Swap space for an Oracle database server:
If your RAM is between 512 MB and 2 GB, Swap space should be 1.5 times larger than RAM.
If your RAM is between 2 GB and 16 GB, Swap space should be equal to RAM.
If your RAM is larger than 16 GB, Swap space should be 16 GB.
To mention vm.swappines, which is an important kernel parameter about using Swap space, it stands for the free RAM percentage before Swap. It means the higher the percentage, the higher the probability of using Swap; the lesser the percentage, the lesser the probability of using Swap.
Default value of that parameter, which can be between 0 and 100, is 60. As stated in “Red Hat Performance Tuning” guide, lesser swappines value is suggested for database workload. For example, Red Hat suggests swappines value as 10 for Oracle databases. But, it suggests swappines value as 1 for MariaDB databases.
In order to adjust swappines value temporarily, you may run these commands.
# echo 10 > /proc/sys/vm/swappiness
or
# sysctl -w vm.swappiness=10
In order to adjust swappines value permanently, you should add the line below to the file ‘/etc/sysctl.conf’.
# vi /etc/sysctl.conf
vm.swappines = 10
In order to apply changes instantly, you should run the command below.
# sysctl -p
How to Increase Swap Space?
You can see the space reserved for Swap through the command below.
# free -m
In the index where you will use the space reserved for Swap, a file according to your need is created. I’m going to create a file of 4G size by assigning bs(BYTES) value 1M and count value 4096.
# mkdir /swap_file
# dd if=/dev/zero of=/swap_file/swap_file1 bs=1M count=4096
Change the format of the file you’ve created to Swap file and check it.
# mkswap /swap_file/swap_file1
# file /swap_file/swap_file1
Add the created Swap space to /etc/fstab file.
# vi /etc/fstab
/swap_file/swap_file1 swap swap defaults 0 0
Activate the space by granting necessary authorisation.
# chmod 600 /swap_file/swap_file1
# swapon -a
You should see that your Swap size has increased when you run control commands again.
# swapon -s
# free -m
The picture below shows result of the steps I did on my virtual server.
Hope to see you in new posts,
Take care.
Comments