What is Swap in Linux and how to use it?

linux

Perhaps many of you have heard of this term, most already know it, but for those newbies who don't know yet What I'm talking about I'll tell you a little about swap.

The swap or swap memory space or also known as virtual memory, is the one that uses the space on the HDD instead of a memory module.

Otherwise, applications use RAM and its availability to run and be able to work on the computer, when there are few applications running on the system, these are managed with available RAM.

Now what happens when the opposite is the case if your applications need a lot of RAM or there is simply no more memory available This is when Swap comes in.

Swap comes into use when real memory runs out, the system copies some of the contents of RAM memory to the swap memory space in order to perform other tasks.

One of the main disadvantages of using this system is that the system will become slower, since the data transfer speed between the RAM and the HDD is vastly different and it all depends on your hardware.

Although in SDD this changes radically since there is a better data transfer.

Speed ​​matters here while RAM memory information passes in a span of nanoseconds. An SSD accesses data in microseconds while, like a normal hard drive, accesses data in milliseconds. This means that RAM is 1000 times faster than SSD and 100.000 times faster than regular hard drive.

When is it necessary to use the Swap?

swap

Even though there is a lot of information on the net, You will find two types and they are the ones who say that Swap at this point is useless and others that it is extremely useful.

Here comes a dilemma, the reality is that personally I have not had the need to use a swap partition, this because in my case I do not usually demand too much from my computers.

Although for everyone is different, from my part to this day I have never crashed the system and I have not suffered because it slows down due to lack of RAM memory, it has happened to me that I notice slowness, but it has been due because my hard drive already had problems and I had to change it.

However the questions they ask us are:

  • ¿How much should be the size of the exchange?
  • ¿Swap must be twice the size of RAM or should it be half the size of the RAM?

Since both are linked, I think that by common sense we can deduce what should be done.

If you have a computer with 16 GB of RAM your Swap would be 32 GB or 8GB, the reality is that none, by common sense when accessing 8 GB of memory on your HDD takes you around 2 min onwards, seeing the table of transfer speed described above is not consistent.

Now if you have more than 8Gb of RAM with only 2GB of swap is enough, using more does not make sense.

Now If you have 6 GB or less, it is recommended that you use 1GB to 2GB.

If you use video editing tasks, renders or to play titles that require something considerable, the healthiest and best thing is to increase our RAM memory and only have our 2GB of Swap.

Finally, it is up to you to choose how much disk space you will dedicate to Swap, as I mentioned, personally I have never saturated my system so it is also part of your way of using your computer to have several applications open if not you have in use.

 


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

7 comments, leave yours

Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Gregory said

    I find the article somewhat confusing for which it is initiated. The right thing to do is to have the ram we need, if possible that we are left over (the years have passed when ram was an almost inaccessible luxury), swap takes you out of a pinch, but when you have to continually access it, it leaves you the equipment almost inoperative, too many delays give you problems with the communications of the servers, make the waiting times in games unacceptable, etc, etc. The old rule of double swap than ram is obsolete, although depending on which processes it can be interesting, if you work with huge data, but the calculations are progressive, it is feasible to play with the swap to avoid having to install huge amounts of ram. In cases like office automation, 4GB of ram and 4GB of swap are usually enough, but with the greediness of web browsers, 8GB ram and 2GB of swap are more recommended, for games three-quarters of the same and if you increase to 16GB of ram you can minimize the swap, or remove it.

  2.   fedu said

    Terribly messy

    RAM less than 1 GB so swap must be Double your Ram
    RAM greater than 1 GB swap equal to 2 GB

    but if you want to hibernate the swap they have to be at least the same as your swap you use or not, because hibernation is done in the swap.

  3.   fedu said

    but if you want to hibernate the swap they have to be at least the same as your RAM uses it or not, because hibernation is done in the swap.

    1.    Darkcrizt said

      I know that the information is confusing and that is why I comment that we must know for what purpose the computer is going to be busy and be aware of how much RAM we have, since as you say, the Swap recommendation must be the size of the RAM if we are talking about hibernate and here is how I say if you have 8 GB or more as a mere example.
      Having a swap area of ​​this size is quite incongruous and especially when if you are going to hibernate your computer it is occupying all the RAM available at that time. Has no sense.
      Without more, from a personal point of view, using more than 2GB of swap just doesn't make sense.

  4.   joelgsm said

    In an interactive system (a user pc), there should be no swap because at the moment in which for whatever reason the system starts to pull swap, the computer freezes and opens a window to kill the process that is "Eat" the ram is something super slow, and it usually pays to turn off by unplugging the power.
    The swap is only useful for the ordinary user to hibernate the computer.

  5.   Gregory said

    I always saw how much waste to use a lot of swap just to hibernate, in fact I in particular never hibernate, when I turn off I do it for real.

  6.   Kevin Tanza said

    I'm going to be the first to admit that I didn't have any knowledge about Linux swap; I am not at all an expert in everything that has to do with this technology class, so I am very grateful for this explanation 🙂 It has been very good and beneficial.