4

I have a swap file /swapfile of 1GB size in accordance with the procedure described in the ubuntu swap faq.

When doing a RAM intensive task, I use the "System Monitor" to check the load on my Memory and my Swap. When the task is done, the Memory load goes down quickly ... however, the Swap load stays high for a very long time and only trickles down very slowly (see image).

system monitor gui

When calling sudo swapoff -a && swapon -a, I can clear the Swap manually ... but I'd rather know:

  1. Why is Swap taking so long to be cleared?
  2. Is this impacting the performance?
3

Short answer: if your computer is not acting very slowly, it's fine.

Linux will only get the contents out of swap if they are needed, otherwise, there's no point in loading something that isn't in use from swap into RAM, thereby reducing the cache.

A way to check if your system is being limited by swap is checking

vmstat 1

and looking at the wa column, which shows how long it takes before a process can run. Also, use a tool such as htop and see how many processes are in disk sleep(D).

Also, you should have a bit more swap. According to the SwapFAQ:

    RAM(MB) No hibernation  With Hibernation  Maximum
     256     256              512               512
     512     512             1024              1024
    1024    1024             2048              2048

    RAM(GB) No hibernation  With Hibernation  Maximum
      1      1                2                   2
      2      1                3                   4
      3      2                5                   6
      4      2                6                   8
      5      2                7                  10
      6      2                8                  12
      8      3               11                  16
     12      3               15                  24
     16      4               20                  32
     24      5               29                  48
     32      6               38                  64
     64      8               72                 128
    128     11              139                 256

If you have 16GB of RAM, you should have between 4GB and 32GB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.