How to work with swap space on Linux system - infinitivehost

How To Work With Swap Space On Linux System

Swap space is an integral part of modern computers and is not OS-specific. Linux may boost a host’s total amount of virtual memory by making use of swap space. It may utilise a swap file on a standard file system or logical drive, or it may have its own swap partition(s).

Conventional computers use one of two distinct forms of memory. RAM, or random-access memory, is used to temporarily store information and software while it is being used by the computer. Data and programs must be stored in RAM for the computer to utilise them. In the event that you power down your computer, any information saved in RAM will be erased.

Contemporary Linux machines furthermore make use of the second form of memory known as swap space. Swap space’s principal purpose is to act as a memory replacement when regular RAM is at capacity.

Read More: What Is The Inode Number In Linux?

Overview of Swap Systems


Overview of Swap Systems - infinitivehost

A computer will have one of two types of memory installed. First, there’s random-access memory (RAM), which is what a computer uses to temporarily store information and programs while they’re being utilised. The Random Access Memory (RAM) of a computer is where all of its active programs and data are kept. Data saved in RAM is considered “volatile,” meaning they will be deleted in the event of a power failure.

Permanent information and computer programs are stored on hard drives, which are magnetic media. When data is written to a disk and the power is cut to the computer, the information on the disk is not lost. To use the computer’s processing power, the central processor unit (CPU) has to have access to the data and programs stored on the hard drive, but it can only do so if a copy of everything is first stored in the random access memory (RAM). A computer moves some operating system components, including the kernel and init or system, and data from the hard disk into RAM, where the CPU can access it immediately, during the startup process.

More about Swap Space 


More about Swap Space - infinitivehost

Swap space’s principal purpose is to act as a memory replacement when regular RAM is at capacity.

Let’s say, for the sake of argument, that your machine has 8GB of random access memory. If you launch applications that don’t use up all of that RAM, then everything will work well and no swapping will be necessary. But let’s say that when you add more rows to your spreadsheet, it increases in size, and eventually uses up all of your RAM along with the other programs you have open. You would have to put your spreadsheet work on hold until you could free up some RAM by shutting unused apps if you didn’t have access to swap space.

The kernel employs a memory management system that can identify memory pages whose data has not been accessed for some time. To free up RAM, the memory management software “pages” (swaps) less often used memory pages to a separate area of the hard drive. That way, you may add additional information to your spreadsheet without worrying about running out of RAM. The kernel’s memory management code keeps tabs on the memory pages that have been switched out to the hard drive, allowing them to be “paged back in” to RAM if and when they are required.

How much memory should be set up for swap?

Back when most computers’ RAM was still measured in KB or MB, a good rule of thumb for how much swap space should be allotted on the hard drive was 2X the amount of RAM installed in the machine. In this case, a swap partition of 128KB would be the best size for a machine with 64KB of RAM. This guideline reflected the reality that, in those days, RAM capacities were often fairly tiny and that setting aside more than 2X RAM for swap space would not boost speed. Most computers wasted their time thrashing with swap space exceeding their RAM capacity.

RAM (Random Access Memory) has become a cheap commodity, and most modern computers have several gigabytes or more of it installed. One of my more recent machines has 32GB of RAM, while my primary workstation has 64GB. Memory on my older machines ranges from 4 to 8 GB.

However, the 2X multiplier is far from the limiting performance factor for swap space when dealing with PCs with massive quantities of RAM. 

* Having access to swap space does not negatively impact performance.

It’s probably best if we avoid thrashing, which is a well-known performance issue. Linux can become stuck in a memory swapping loop when RAM is low. Because of this, the system is useless. Some individuals attempt to stay out of this predicament by turning off swap in favour of using RAM exclusively. Although at first glance it may appear to be sound advice, a deeper look reveals that this is not always the case.

* Memories Eventually Get Set Free

Memory pages will be switched even if there is no swap space available. As we know from prior discussion, the page cache is used to store recently accessed data from read files. Even if swap space is disabled, the original file can still be swapped if it is located on disk.

* Unidentified Documents Will Never Be Traded

Anonymous memory is a subset of the memory spectrum. The programs that need access to this memory do not have a file on disk to back it up. Some of the memory allocated to the system’s “anonymous pages” is reserved for usage during system initialisation and then never used again. You can definitely do a switch using those pages. Therefore, enabling swap will result in less physical memory being wasted.

Read More: WooCommerce vs Magento- Which Platform Fits your e-commerce


This post taught us that, no matter how much RAM we have, it’s always a good idea to have some dedicated to swap. As an added bonus, we dispelled the myth that using swap space can slow down your computer. Always keep some room on your hard drive set aside as swap space. Our Linux system will be healthier, even if there is no discernible boost in performance.

Leave a Reply

Your email address will not be published. Required fields are marked *