What is SWAP memory?

Now get to know one of the things that most doubt newcomers to Linux users, and look, thinking about maybe even some older ones. After all, what SWAP? How it works, how to configure? This is what we will answer in this article.

How SWAP Memory Works

SWAP: A Virtual Memory for Your Computer

I know there are a lot of people who have this question, especially those who will be installing Linux for the first time partitioning the hard drive, so I decided to write this article to make you understand what SWAP works and how it can be used to your advantage. , often even to improve the performance of your computer.

SWAP memory assists RAM memory
SWAP memory assists RAM memory

What SWAP?

If you are a layman in operating systems, it is worth quoting that may seem obvious to those who already know a little about the subject; Inside your computer are embedded chips with integrated circuits soldered to it, these devices we give the generic name of "memory comb", you can see the example of one in the image below.

Kingston DDR3 Memory
Kingston "Memory Comb" Example

I will not go into too much technical detail because the subject of the article is already technical enough, the RAMs, like the one in the image above, can be of varying sizes following two basic models, one for Desktop (as above) and one slightly smaller. Commonly used in laptops like Notebooks and Netbooks, regardless of their size and capacity (measured in Giga Bytes) the memories have the same functions, storing data while the processor works with them.

As soon as you turn on your computer the operating system is loaded into RAM to enable your Facebook entry to duel your drages.

But why did I talk about RAM?

Then, SWAP memory has an almost familiar connection with RAM, one helps the other, to be clear, SWAP memory usually comes into action when the RAM can't "handle it."

On today's computers this is much rarer, computers with 4GB of RAM or more rarely use SWAP memory, as you can see below on my computer, of the 1.9 GB of SWAP only 1.5 MB is being used!

SWAP memory usage in the system

After all, what is SWAP memory?

It can be said to be a computational technique used by operating systems to increase the amount of actual computer memory in order to run programs and the system itself without crashes.

This virtual memory that will help the RAM is stored on your hard drive and has differences from system to system, but fulfills the same function.

The Differences of SWAP Memory on Linux and Windows

Although they work in a similar way the way SWAP implemented on Windows and Linux differs.

On windows

Windows logo
Image: Reproduction

In Microsoft system SWAP a file inside the system root (C: /) called PAGEFILE.SYS and it is created without your knowing it during Windows installation, usually putting the same amount of RAM you actually have in the computer, ie if you have 2GB RAM it will have 2048 MB in PAGEFILE.SYS if it has 4GB of RAM will have about 4096 MB of SWAP and so on, and you can change these values ​​to plus or minus or even disable SWAP.

On linux

SWAP on Linux distros

On Linux the SWAP is set at the time of user formatting unless you follow the path of the automated installation, so the SWAP allocation will be similar to Windows, however, the Linux SWAP is not in a file inside the root, SWAP is a partition part of the root partition of the system, you can also change its size but only by repartitioning, the great advantage of using SWAP with a partition partition that you can use the same SWAP for multiple systems.

If you installed a Windows dual boot (two systems on the same PC) each system would have a SWAP for itself taking up more HD, using a shared SWAP on a dual Linux boot both systems could occupy the same SWAP.

SWAP Myths, Doubts, and Tips

With this interesting feature that SWAP has to work as if it were a normal RAM raise questions about its functionality and application, here are some of them with their proper answers:

– The more SWAP the better?

WRONG, especially on current computers the use of very low SWAP memory so there is no need for you to have a lot of allocated paging memory (paging is also a SWAP nomenclature), SWAP is much more useful on older computers that have little RAM as they will Physical memory is easier to fill, so auxiliary memory activity is very useful.

– How much should I use SWAP?

This is a split point, if you search for it you will find many saying that you should always use twice the actual amount of memory, but based on experience I think this is a big exaggeration, since systems with more than 4GB of RAM rarely use SWAP.

So I define it like this:

RAM MEMORY (REAL) > = 3GB = USE 2GB SWAP

Otherwise use 4GB of SWAP and be happy, no more than that.

– Can I use the computer without SWAP?

Yes, it can, but even if your computer has 8GB of RAM if there is SWAP memory it will use up a bit, if you have plenty of memory and never leave it fully loaded there is really no need for SWAP, but if you have a modest computer or a PC Gamer or a very interesting editing island have the "2 Giginhas" of SWAP as I commented in the previous topic.

– What is the disadvantage of using SWAP?

With all that has been said so far you may think that using SWAP has only advantages but not quite, although most of the time it will be useful if you make the system use too much SWAP invariably slower it is good to remember that the data is written to the hard drive and it is in turn much slower than a RAM, as soon as its SWAPINESS factor (we'll see later) is very high this will even make your hard drive work harder than it should.

SWAPINESS

This is a configuration that Linux allows you to do, the term SWAPINESS is used to designate the amount of free memory your computer must have in order for small files to start being sent to SWAP memory.

Now that I really don't understand!

Quiet, simple to understand, in Ubuntu the SWAPINESS default of 60 on a scale from 0 to 100. With the default of 60 means that when you have 60% of free memory the system will start sending some data to the SWAP partition. , this value can change and even interesting if you have a good amount of memory, we teach you how to do this in this article, I for example use SWAPINESS as 10.

SWAP is not the only alternative, meet ZRAM

ZRAM creates a RAM block device that functions as a virtual disk drive but is compressed and stored in memory rather than using the swap partition (which is slower), allowing for fast data exchange by increasing the amount of memory. available before the system starts swapping with the disk. In order to gain performance, especially on low-memory computers, the Lubuntu distribution (Ubuntu with the LXDE graphical environment) already comes with this functionality by default.

And this was another article to make you better know the system you use, if you want to receive blog updates in your e-mail and not miss any post like this, subscribe to our newsletter below, I promise to send it to you all the end of the day the posts that are posted here on Diolinux, until next time!