UsageToday, I want to talk about the SWAP, and to increase his size, reduce it or configure the system to load it at boot. Before talking about that, I would like to describe briefly what Ram and SWAP are used for. Ram, and in some situation SWAP, are used by processes to work. To understand better, a picture is often a good idea.
ManagementThe swap file could be stored in a specific partition. To keep this article as simple as possible, we will not talk about this case. To begin with, we have to determine how much ram and swap do we have ? We can use the top command to know that. In my case, I have ~= 2go (2009380) of ram and I have decided to fix the swap to ~= 512 mo (524284). Let's guess that 512 mo is not enough and we would like to increase the size to 1go. To do that, we have to follow this procedure:
- identify where is the swap file and his size swapon -s
- deallocate the swap swapoff /swap
- delete the previous swapp file rm /swap
- create a new file with specific size dd if=/dev/zero of=/pathToTheNewSwap bs=1024 count=1M*if you want 512 mo, replace 1M by 512k
- format the new file to a swap format mkswap /pathToTheNewSwap
- configure the system to use the new swap as swap swapon /pathToTheNewSwap
- configure the system to load it at each boot, you have to delete the line about the previous swap file and add a line for the new one.
vi /etc/fstab /pathToTheNewSwap swap swap sw 0 0