What Is A Swap Partition In Linux And What Does It Do

What Is A Swap Partition In Linux And What Does It Do

What Is A Swap Partition In Linux And What Does It Do

 Most Linux installations recommend that you include a Swap partition. This may seem strange to Windows users, who are used to keeping all operating systems on one partition. So what does a Swap partition do, do we need one, and how big should it be? The following is an explanation of what is a swap partition on Linux and what it does.

What are Swaps

Our system must use Random Access Memory (RAM) when running applications. When there are only a few applications running the system, we manage with the available RAM. But if there are too many applications running or if the applications require a lot of RAM, then our system will get into trouble. If an application needs more memory but all RAM is used, the application will crash.

Swap acts as a reliever for our system when RAM runs out. What happens here is that when the RAM runs out, our Linux system uses part of the hard disk memory and allocates it to running applications. This sounds cool. Meaning if we allocate like 50GB swap size our system can run hundreds or even thousands of applications simultaneously? but that is WRONG thinking!

Because, speed is important here. RAM accesses data in the order of nanoseconds. SSDs access data in microseconds, while normal hard disks access data in milliseconds. This means that RAM is 1000 times faster than SSD and 100000 times faster than regular HDD. If an application depends too much on swap, its performance suffers because it cannot access data at the same rate as it would in RAM. So instead of taking 1 second on a task, it may take several minutes to complete the same task. This would render the app nearly useless.

Advantages and Disadvantages of Swaps

Pros of Using Swaps:

* Provide overflow space when our memory is fully loaded

* Can move items that are rarely needed from our high-speed memory

* Allows us to hibernate

Disadvantages of Using Swaps:

* Takes up space on your hard drive because the Swap partition does not resize dynamically

* Can add wear and tear to your hard drive

* No need to increase performance

When the Swap Partition Doesn't Help

Swap partition doesn't always help improve performance? If we have installed Linux on a laptop that only has 1GB of memory and a 5400rpm hard drive. With only 1GB of memory, we can imagine that it can fill up quickly with several browser tabs open. The SWAP partition allows us to keep everything open because the memory just overflows.

But then a bottleneck appears, due to the hard drive's 5400rpm speed. Because the hard drive is very slow, and the system constantly wants to access the Swap partition, and finally the laptop becomes very slow. The swappiness set doesn't guarantee that, even if there is space now in memory, everything in the Swap partition will be moved back. Instead, much of it will remain in the Swap partition, causing the laptop to continue to be sluggish. This can probably only be fixed by rebooting, which takes a while as the system has to wipe everything from the SWAP partition before shutting down.

When is Swap Necessary?


+ If our system has less than 1 GB of RAM, we must use swap because most applications will soon run out of RAM.

+ If our system uses resource heavy applications like video editors, it would be a good idea to use some swap space because our RAM might run out here.

+ If we use hibernation, then we have to add swap because RAM content will be written to swap partition. This also means that the swap size must be at least the size of RAM.

+ Avoid strange occurrences such as programs going crazy that eat up RAM.

What Size Required For Swap?

People have different opinions about the ideal swap size. Even major Linux distributions don't have the same swap size guidelines. If we follow Red Hat's advice, they recommend a swap size of 20% of RAM for modern systems (i.e. 4GB or higher of RAM). CentOS has a different recommendation for swap partition sizes. They suggest double RAM size if RAM is less than 2GB and RAM size + 2GB if RAM size is more than 2GB i.e. 5GB swap for 3GB RAM. Maybe we are confused, which one should we choose. This is why, the table below will tell us Ubuntu's recommended swap size based on RAM size and hibernation needs.

RAM Size Swap Size (Without Hibernation) Swap Size (With Hibernation)

256MB 256MB 512MB

512MB 512MB 1GB

1gb 1gb 2gb





8GB 3GB 11GB

12GB 3GB 15GB

16GB 4GB 20GB

24GB 5GB 29GB

32GB 6GB 38GB

64GB 8GB 72GB

128GB 11GB 139GB


So What is a Swap Partition? Swap is the second type of memory in modern Linux systems. The main function of Swap space is to replace disk space for RAM memory when real RAM fills up and more space is required. Swaps can also make a huge difference in the performance of our systems, sometimes for the better and sometimes for the worse. For that we must be able to make the right decision when choosing it.

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ ________

So many articles What is a Swap Partition in Linux and what does it do. Look forward to other interesting articles and don't forget to share this article with your friends. Thank you…

Resa Risyan

Just an ordinary person who wants to share a little knowledge, hopefully the knowledge I provide can be useful for all of us. Keep in mind! Useful knowledge is an investment in the afterlife.

Also, read the article about What Is Password Spraying And How They Work. And see you in another article. Bye
Read Also :
DotyCat - Teaching is Our Passion