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.
free -h
andswapon
. Report back to @heynnema – heynnema Jan 06 '19 at 01:21