0

I have 5.4 GB of 6.8 GB usage of RAM and 927.5 MB of 976 MB of Swap memory. Even though i have 1.4 GB of RAM usage Ubuntu is using up all of the swap memory. Although the swap memory is using my SSD space it will be much slower than my RAM. Shouldn't it use up all the RAM and then occupy Swap ?Extreme Swap usage

4
  • 1
    No it shouldn't use up all memory before touching swap. Refer help.ubuntu.com/community/SwapFaq and setting swappiness which allows some configuration of when swap is used.
    – guiverc
    Dec 22, 2019 at 7:18
  • 1
    The situation you currently show depends on prior use. You must have run before in a memory-full situation where swap is then intensively used. Please describe how you can reproduce this memory state. It surely is not like this after booting your computer. Is this a system that is only rarely being rebooted?
    – vanadium
    Dec 22, 2019 at 11:18
  • 1
    @vanadium Yes it's running on a laptop and I reboot it only when the system update asks me to do so or I have have a new feature which applies after the reboot. Otherwise it's mostly suspended with the lid closed. It mostly has a maximum uptime of about a week or two. Dec 22, 2019 at 11:31
  • 1
    That is what I expected. What you see accordingly is very normal. I have posted an anwer.
    – vanadium
    Dec 22, 2019 at 11:40

3 Answers 3

2

You can use sysctl vm.swappiness=10 to reduce the drastic swap rate. And you can switch on or off with swapoff -a and swapon -a with root privileges. If you want to use hibernation, suitable spot for swap space is twice the size of RAM size.

2
  • How should I increase it to 4GB and why should I do so. Is it healthy for my system ?? Dec 22, 2019 at 11:42
  • 1
    Swap Space is only useful if you have low amount of RAM. And only if you leave your pc in hibernation, you need twice the size of RAM as a suitable spot. This tutorial is for Manjaro but works fine on Ubuntu: classicforum.manjaro.org/index.php?topic=30763.0 Dec 22, 2019 at 12:28
0

Edit /etc/sysctl.conf as root. Change or add this line to the file:

vm.swappiness = 5

One way to do this is by using sudo nano /etc/sysctl.conf in a terminal window.
Reboot the system after saving the edited file.

This will instruct the system to use swap memory only when RAM is used almost completely.

976 MB of swap memory is not enough. It should be increased to at least 4 GB.

2
0

Ubuntu will use RAM. When this becomes limiting, currently unused segments of memory are moved to swap space. That memory will be retrieved from there only when needed again in active RAM. If not needed, it will just be kept in swap even if in the mean time more RAM is becoming available.

You did not provide any indication of the use of your machine that resulted in the memory state you show. The memory state of a linux machine is dependent on how the system has run and what the memory requirements have been thus far. For sure, a freshly booted machine with 6 GB RAM will not be using swap. Swap use will eventually grow depending on the memory needed by your computer use.

I would merely thrust your linux system, which employs SWAP to maximize efficient use of real RAM. Still, you may want to decrease the tendency to use swap by changing the swappiness value. This will decrease the tendency to swap away active applications and give you a subjective impression of more responsiveness, although some processes may be more limited because of less RAM.

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.