If you have been installing Linux for years, you will probably do the procedure mechanically. Some things you keep doing may not be right.
For example, the size you think the swap partition should have
What does Linux use the swap or swap partition for?
The data and the programs that are being executed are stored in the so-called Random Access Memory or Ram. What is stored in RAM memory is lost when you turn off the computer.
In the old days RAM was expensive. This limited the number of programs that could be run simultaneously and their power. The solution was to use a disk space to free up data that was not necessary at the moment.
We call a swap partition a area of the hard drive that the operating system uses for temporary storage. Used when there is not enough space in RAM to save the data of the active application.
Access to information written to the swap partition will be significantly slower than access to information stored in RAM. Thus, the Linux distribution that we are using will prefer use swap partition for older data.
Criteria to know if we need to create a swap partition.
On modern computers, a Linux distribution with normal use can work without problems by not setting a swap partition. But there are times when having it is essential and is always recommended.
It is absolutely necessary to create a swap partition andIn these cases:
- If our team has 2GB or less of RAM. Although there are hardly any desktops or notebooks left with this amount of RAM, it is common in computers originally designed to work with the cloud.
- When we use memory-intensive applications RAM like video editors.
- If we want to enable hibernation mode on our computer.
When you have enough RAM memory (More than 8 or 16 GB depending on the type of applications you use) it is convenient to assign a percentage of the disk to the swap partition. This will help prevent a malfunctioning program from consuming more memory than necessary and locking up the system.
This is not as weird as it sounds.
Two years ago GNOME 3.26 users reported that memory consumption increased exponentially when switching between windows or accessing the menu. Although the subject is corrected, it does not hurt to be forewarned.
Of course the size of the hard drive you have will be a factor to consider. If you installed your Linux distribution on a 16GB pendrive, you won't have many options.
Ways to determine the proper size of the swap partition.
As you could see if you installed different Linux distributions using the automatic installation mode, there is no uniform criterion when determining how much disk space to allocate to the swap partition.
- If the RAM memory is equal to or less than 2GB e is assignedl double the disk space.
- In case the RAM memory is greater than 2 GB and less than 5 GB slet's get 2 gb to RAM.
- When the RAM that we have is greater than 5 GB we allocate 20% of the disk space.
- In order to use hibernate mode without problems, the size of the swap partition must be equal to the size of the RAM plus the square root of the size of the RAM.
Of course, there is no combination of hardware and software that is the same as another. It is best to try different sizes of disk space to find the one that works best with our RAM and applications.
Swap files
It is possible that due to lack of space or some other reason, a physical space on the hard disk cannot be allocated as a swap area.
In that case you can create a file and configure it as swap. Once this is done, it will fulfill exactly the same function of storing unnecessary data that does not have a place in RAM.
Very enlightening, finally.
I have a doubt. I have several hard drives and 16 G of RAM.
My interest in swap is to be able to hibernate.
I currently have 4 disks, an SSD where I have the EFI partition, the / boot and the /, and the rest are HDDs. In one of them I have a 20G swap partition but my LinuxMint does not hibernate properly. I have followed several guides but I never get it.
Could it be necessary to exceed 20G?
Thank you
It is not an exact science. In theory 20GB meets the memory + square root of memory rule. Try giving it 10 gb more and if it works go down.
If my ram memory is 8gb with 2gb of SWAP it is enough, but if my memory is 16gb it is doubled, 4, 8,16 etc- ...