0

I've had this problem since Hardy Hereon. Ubuntu becomes unstable when applications ask for too much memory. The memory request sends kswapd to an overdrive that makes the system unstable and I have no choice but to restart the system.

This happens for example if I try to open a very large (a few GBs) text file or if I open FF and Chrome at the same time. Other OSs such as Windows and Mac OS warn you when there is a shortage of memory but Ubuntu just lets the system get unstable.

Soren A
  • 6,799
Reza
  • 1,235
  • 3
  • 17
  • 31

1 Answers1

1

The issue is due to slow SWAP memory on disk being used in cases where you run out of RAM memory.

You will experience this issue more often when RAM is limited, at 2 GB or less. On systems with at least 4 GB, you should easily be able to run multiple applications at the same time and open quite large documents without running into the issue. So the very first solution to this issue is to upgrade to at least 4 GB RAM.

You will also experience this issue more strongly if you have single large demands for memory, e.g. opening a large graphics file, as opposed to having many small demands on memory, e.g. open many applications. In the latter case, smaller chunks of ram will be swapped, resulting in shorter swap operations. In the former case, the system is occupied for a very long time swapping memory in and out.

Finally, the issue will be worse if you have a swap file on a traditional hard drive instead of on a much faster and silent SSD drive. Hard disks are so much slower than RAM. SSD drives are significantly faster.

Solution and workarounds

The very best and only fundamental solution to avoid your system being locked up by swap activities is to install additional RAM. It is relatively cheap nowadays.

If you systematically work in low-memory situations, you may want to keep swappiness sufficiently high. By default, it is as high as 60, but you might want to increase it to e.g. 80. Here is how to change swappiness. This will make sure that RAM quickly is swapped out so RAM is freed to be used for new demands. In addition, swapping occurs continuously instead of suddenly all at once as memory drops beyond a certain threshold. Thus, you will less quickly run into minute long freezing, but the price is that your user interface overall will feel more slow and sluggish although processes will run more efficiently.

Use an SSD for SWAP. The intensive writing on the SSD will reduce the life time of the drive, though.

Yet another trick is to use zram. This creates a compressed swap file in fast ram. That leaves you with even less RAM for your applications. However, RAM can then be swapped to the zram, which works very fast, effectively allowing you to store more information in RAM.

vanadium
  • 88,010
  • Another post to read is https://askubuntu.com/questions/103915/how-do-i-configure-swappiness. Modern SSD's lifetime is not decreased by intensive writing. zram only reduces available RAM. vm.swappiness=80 will only increase swap activity, and slow down the machine, esp if you're swapping to HDD. You basic answer is mostly correct, but without looking at free -h or swapon, how can you be sure? – heynnema Jan 06 '19 at 15:03
  • In the question, it is clear swap is in use, and indication is given that it happens on opening large files or multiple programs. Symptoms are totally consistent with a system with relatively limited RAM. Don't know what I will achieve more with the actual numbers in this case. – vanadium Jan 06 '19 at 16:09
  • I agree that it sounds like a RAM or swap problem, but without specific data, you can't assume... what if free -h showed 16G RAM and a 1G swap? The answer would need to be different, yes? – heynnema Jan 06 '19 at 18:31
  • I am quite sure we will have the way more typical case here. Lets await the info from OP. – vanadium Jan 06 '19 at 20:09