3

I work with many applications open at the same time (e.g. PhpStorm, Android Studio, Chrome, Firefox, FileZilla, Evince, SublimeText).

It happens more and more often that the hardware goes to the limit: the work led lights up, I feel that the hardware is working, the system becomes so slow that I cannot move the mouse or do anything until a few minutes, after some programs crash. Sometimes I have to wait hoping to open the terminal by doing some killall.

Is there a way to reserve a certain amount of RAM for the operating system to prevent it from freezing? I need a fast response operating system, even if other applications get a little slower.

I am using Ubuntu, with an SSD drive with about 5GB of free space in the home directory.

free -m:

              total        used        free      shared  buff/cache   available
Mem:           7,8G        4,4G        1,6G        204M        1,8G        2,9G
Swap:          2,0G        1,7G        344M

Edit:

I manually set 2 GB RAM for Swap because it is needed to make composer update works in PHPStorm for a Symfony project.

Thanks

2

3 Answers 3

1

The easiest answer is: reduce your swap space (see how in this other question).

Explanations:

When your RAM gets full, the kernel starts using the swap space more often (on the much slower disk drive) and applications need to wait a longer time to access their memory, degrading the performance of those applications. The poor performance will continue until the swap space is filled up, and the kernel starts killing applications (Out of memory errors, aka. OOM). Hence, the bigger the swap space size, the longer the applications will perform poorly. By reducing the swap size, you will reduce the time needed for the kernel to kill applications, freeing some memory.

Unfortunately, the desktop environment (responsible for displaying your mouse cursor and windows) is considered as much an "application" as a browser. So the kernel cannot distiguish the desktop environment from the other applications and decide something like "the desktop environment memory should not be swapped" and make it more responsive than other applications.

Other answers include:

  • put your RAM-hungry applications within a cgroup and limit their usage of memory
  • buy more RAM
  • use ZRAM

This SuperUser answer explains in details the situation and possible solutions.

1
  • thanks for your info, see my edit about the swap. Feb 21, 2021 at 11:21
1

I would look in to adjusting swappiness and cache pressure of the system.

You can adjust the swappiness by running sysctl vm.swappiness=X, where X is between 0 and 100. The setting will change at what percentage of available RAM swap will start being used. With a swappiness of 0, the system won't swap until it has run out of RAM, and a setting of 100 means it will swap at all times. This description is over-simplified, but it's the basics. Normally I use a swappiness of 10.

You can also adjust cache_pressure, which determines how often the system caches inode and dentry (file system) data. This is often performance intensive and worth caching. The 0 to 100 value signifies how much the system will choose to cache.

Hope this helps Jason C.

1

You're hitting the infamous "Out of Memory" (OOM) bug. This has gone for more than 16 years, and it's only since mid-2019 that this bug is getting attention... without any reliable fix since. This is due to Linux bad habit to cache things, overcommitting way too much RAM and unability to tell how much unreclaimable cache/buffers you really have.

However, there's something simple that works really well to prevent you hitting that OOM bug: nohang.

You'll find out why you're hitting OOM there, but also a ppa down that link to install it. This will not fix the bug, but this is the best thing we have against that nowadays.

Do also consider using a less RAM hogging Desktop Environment, since every software you do launch with a heavy one will use even more RAM. Also, Gnome 3, despite being able to do far less than Mate (a GTK 3-based Gnome 2 revival), is the hoggiest one after Cinnamon, comes then KDE and Mate.

I would suggest XFCE, which only eats around 600MB of RAM instead of the more than 1.3GBs of KDE (old Gnome 3 from 7 years ago already ate that much, should be more nowadays).

Same goes for browsers, anything Chrome/Chromium-based hogs a lot (except... Edge on Windows). Avoid Electron or JavaScript-based "apps" as much as you can, since they're eating way too much RAM for what they can do, or anything that uses a lot of RAM for little functionnality (e.g. a fully-featured text editor shouldn't use more than 30MB of RAM, etc ).

What duthils said is good (ZRAM and CGroups), but sometimes buying more RAM to cater bad developers who don't want to optimize their software isn't an appropriate fix.

Also consider, tab suspenders for your browsers, like Firefox's "Auto Tab Discard" extension and Vivaldi, which is a very powerful browser based on Chromium that natively have manual tab discarding if you really need such Chromium-based browser.

Since you're a developper: Remember, unused RAM IS NOT wasted RAM (the reverse wrong assumption is almost always made by... web developpers).

This is especially true when cached RAM is mostly not real reclaimable RAM, which is exactly why you're hitting that OOM issue. You can easily check that by looking at top's "available" RAM after an echo 3 > /proc/sys/vm/drop_caches to see that there's still some cache left, often by a lot.

2
  • 1
    You make a lot of claims here with no evidence. This entire answer reads like a personal blog post. Can you offer any evidence to back any of the many claims you make? I'm not saying you're wrong, you might be right, but since you offer no evidence, this is just some random internet user's opinion. I would especially like to see evidence supporting your claim that the OOM is considered a bug, that it's getting attention since 2019, that cinnamon is more resource hungry than KDE, etc.
    – terdon
    Feb 21, 2021 at 13:59
  • 1
    OOM gets attention since 2019, yet using early-oom or systemd-oomd still aren't enough to stop that in 2021. You can easily check that on a virtual machine. Set 5GB of RAM and 5.5GB of swap, then launch RAM hogging websites on Chrome (e.g. Facebook, Google Maps, 4K Youtube video, etc) : youtube.com/watch?v=PLVWgNrVNlc , and see only nohang is that unforgiving. Same goes for DEs, download and boot up every Debian LiveCD in a VM, disable compositing so it will only use RAM (no GPU RAM), launch top and then echo 3 > /proc/sys/vm/drop_caches to see how much RAM they really use.
    – X.LINK
    Feb 22, 2021 at 0:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .