How Big To Make A Swap Partition When Installing Linux

Table of contents:

How Big To Make A Swap Partition When Installing Linux
How Big To Make A Swap Partition When Installing Linux

Video: How Big To Make A Swap Partition When Installing Linux

Video: How Big To Make A Swap Partition When Installing Linux
Video: How to create Linux Swap Partition | Swap Partition in Linux 2024, November
Anonim

A couple of frequently asked questions when installing Linux - how big should a swap partition be and is it needed at all? Previously, it was recommended to make a swap partition twice the amount of RAM, but now, when the amount of RAM on a computer can reach 128 gigabytes, this rule does not always apply, because in most cases a swap partition will waste free space on the hard disk. …

How big to make a swap partition when installing Linux
How big to make a swap partition when installing Linux

What is a swap partition and what is it for

When the program starts up, its code and some data are loaded into RAM (Random Access Memory). If one or more running programs require less RAM than installed on the computer, then they will continue to function normally. But, if there is less free space left in the RAM than the program needs to load its data, then it will give an error and stop working.

At such moments, Linux begins to use the swap partition on the hard disk as RAM, "increasing" its available volume - it moves unused data from the RAM to it, freeing up space for new ones.

It would seem, why then do you need relatively expensive RAM at all, if for the same money you can buy a much larger hard drive and use it all as a swap partition? It's all about speed. Accessing data in RAM is about a hundred thousand times faster than on a hard drive (actual data varies from system to system). The same operation with access to data in RAM and a swap partition, which would take one second in the first case, will take many hours in the second.

Thus, a swap partition is not suitable for permanent use as random access memory, but it can help a lot at peak times, preventing programs from freezing and stopping.

So how much space should you allocate for the swap partition?

It is impossible to determine a clear answer to this question, because it depends on the specific configuration of the system and the range of tasks it solves, but there are basic recommendations:

  • if the amount of RAM is less than 2 gigabytes, then the swap partition must be at least twice as large
  • if the amount of RAM is more than 2 gigabytes, then the size of the swap partition must be equal to RAM * 2 + 2GB
  • if the amount of RAM is more than 4 gigabytes, then the size of the swap partition should be equal to 20% of the size of the RAM

Recommended: