As promised, during the previous post, let’s get nerdy and show how to make changes to your swap settings.
Let’s start from the beginning.
1- How much swap do I have and how much am I using?
First one is really simple and I bet most of you know this already.
Use the free command to identify your memory usage and in there you will have the swap.
Ex. free -m will show you the used and free memory in Megabytes.
If you don’t have the free command, you can use /proc/meminfo to gather that information.
Ex. cat /proc/meminfo | grep Swap*
2- Am I using a Swap disk or Swap files?
Couldn’t be easier.
Ex. cat /proc/swaps
Does it need an explanation?
3- I need a bigger swap space!
Great, let’s increase it.
Is it a virtual machine? Even better.
Let’s start by turnoff the swap disk.
In the case above would be just running swapoff /dev/sdc1.
Next, increase the space in your virtual disk, delete the old partition and make a new one.
After just format the new partition as swap. Ex. mkswap /dev/sdc1 and swapon /dev/sdc1
Don’t forget to update fstab.
4- How about having multiple swap disks?
Well, almost the same as before, but instead of resize, just add a new disk and create new swap partition.
After that the fun starts.
Create the swap file system like mkswap /dev/sdf1 and swapon /dev/sdf1.
Now you have 2 swap areas. When the first one is full, the second will be used.
Don’t forget to add to fstab for mounting on boot.
5- How to make multiple swap partitions be used simultaneously?
Swap partitions can be used simultaneously, acting like a “RAID” group. This will improve performance significantly, especially when using separate disks.
For that, the disks should be mounted using the same priority, as seen below:
In this case I defined the priority as 3, but it could be any value. If you have more, keep in mind that the higher the number, the higher the priority up to 32767.
So, after beating up swap files in this post. I’ll let it sink in, before I do another post on Swap files.
For now i’ll page out myself!