Get warning on low memory to avoid freezing

Is there a program or some way to get a warning when the RAM memory is running low?

My computer often crashes/freezes without warning when I’m in the middle of something because it runs out of memory. I have to force shutdown and then turn the computer back on.

I have 4 gigs of RAM and am rather careful to not open a lot of things at once, but can’t be looking at Htop or qps all the time to keep up with memory usage.

I don’t have swap partition or file. Maybe it would be better to have?

1 Like

Yes you’re much better with swap than without.

will tell you how to create a swapfile

More details on swap can be found here

I remember when I stole 4GB of RAM from a box (ie. box went from 8GB down to 4GB as I needed 4GB to test another box with issues) and I didn’t expect to notice a difference - boy was I wrong! That box didn’t have swap enabled & it became horrific to use with only 4GB. By simply adding swap, the machine was back to normal; at least it felt that way to me (for the remaining days before I got my 8GB back)

You didn’t provide any release details.

Lubuntu 22.04 LTS includes systemd-oomd which monitors RAM & autokills when it gets low; I talked about it a little here

In my own usage, I use extensions on both firefox and chromium that are a little buggy and lead to memory leaks… The browsers are fine if used without those extensions, but I want the benefits of the extensions thus use them leading to the RAM leak issue… It’s this issue that made me really notice the systemd-oomd change in jammy, but it’s an issue I’ve had for years, and just dealt with on prior releases (pre systemd-oomd) via a terminal open with htop… When I felt the system slow a little; I’d look at htop for clues of what I felt was memory-leak; then just close the browser impacted (be it firefox or chromium - or both), wait a little (giving the linux kernel time to clean up the memory), then re-start the browsers… Using it this way was my preferred option to having no-adblocker on the browsers.

With 4GB of RAM - you need swap, esp. if you’re using a web-browser.


A web browser will always use more memory. My Kubuntu 22.04 install uses less than 800mb of ram at boot but if I open many websites the ram consumption increases to over 3gb ram consumption. I suggest to add swap, like @guiverc said.
Nowadays a minimum of 8gb of ram is recommended, which is what I am running on.


You can add a widget that shows your RAM use. It’s pretty accurate, from what I can tell, though you’re looking at a pretty small image. You can adjust the colors according to your needs, if that’ll help make it more visually informative.

On the subject of RAM, there’s no way I could live within 4 GB, or even 8 GB. I’m not doing much right at the moment and I’m using ~12 GB of RAM. I can kinda live with 16 GB of RAM - but I’m more comfortable with 32 GB of RAM. (I do quite a bit, often including running multiple virtual machines at a time. I also have a few browsers open all the time and some of them have near triple-digit tabs open.)


8gb is fine as long as you are not using windows.
By the way,i have a linux mint install on my old laptop with 2gb of ram, and it can manage 10 tabs fine(thats because of 1.3 g swap.) And its even the heavy flagship cinnamon enviroment.


I like to have everything open and available. Literally, pretty much anything I’d use on a regular basis is open within moments after rebooting - something I do maybe every couple of weeks. This browser has 70 open tabs, another browser has 90 open tabs. A third browser only has like 8 open tabs. I do different things in different browsers. Most of the RAM is taken up by browsers, one of which is also usually streaming a video or audio, and virtual machines.

So, I can’t live within the lower RAM constraints - at least not comfortably. Fortunately, it’s a problem that’s easily resolved. Memory is cheap and plentiful.

Also, until something faster comes along, all my devices will have M.2 NVMe SSDs. Man, are they impressively fast.

I also have an m2 nvme ssd. Web browsers are ram hungry but javascript makes things worse.


If you want a really awesome browser extension that helps negate that (but has a pretty high learning curve), look up ‘uMatrix’ (from the same guy that does uBlock Origin). It’s like an old school firewall, except it’s for your browser. You’ll block stuff like scripts by default and then whitelist them as you need/want to make sites function. Once you’ve configured it for the sites you regularly use, it’s pretty easy - but there is a learning curve.

OP may also be interested in uMatrix, as it’ll save a bunch of memory when used properly.


You could install gkrellm. I use it to monitor stuff, (it’s a sort of conky replacement).

You can see the memory at the bottom.

Set up an alert with a pop-up command e.g
zenity --info --text=“Memory Limit!”

(you have to actually change the limit in order to add the alert).

Then, when it senses the limit, it goes red and triggers the popup.


@KGII you’re kind of right. Applied Ublock Origin and it seems to reduce the heftiness of the webpages i normally use. Thanks. :slightly_smiling_face:


If you put the effort into learning uMatrix, you’ll save even more memory. Basically, it stops (or allows) things like CSS, scripting, or even images - not just from the website but from any third party sites linked to it. So, you’re not loading things like Clarity or Google Analytics code. You’re not loading third party ad scripts or images. It’s really quite powerful.

Another trick for dealing with low memory is to enable RAM compression. I used to use full-on, super-hefty Ubuntu on a laptop with only 4 GB of RAM and a 16 GB eMMC chip, and despite my not-horribly-resource-intensive usage habits, I still ended up with my system stalling out like you’re describing. I didn’t want to enable a swapfile for the sake of not frying out my eMMC chip too quickly, but I also needed to be able to comfortably use the laptop. Enabling RAM compression solved everything.

Assuming you’re not using any zram devices for other purposes, you can enable RAM compression like so:

sudo su -
modprobe zram
zramctl --find --size=3G
mkswap /dev/zram0
swapon /dev/zram0

This isn’t a total miracle solution - a system with 4 GB of RAM can only do so much - but it is very useful if you’re trying to avoid using a swapfile for some reason. You will also have to run these commands after every time you boot or reboot the computer. You can probably use a shell script and a systemd OneShot unit to automatically do this on boot, but I’m not totally sure if I know how exactly to do that, so I’ll refrain from posting more info about that until I know what I’m doing.


Maybe uMatrix is not so recommendable any more.

This repository has been archived by the owner. It is now read-only.

Something like this is what I had in mind. Although seems like it hasn’t been updated in a long time, no?

Yeah, he’s stopped developing it a couple of times and come back to it a couple of times - once to fix a bug. The current version was working just fine the last I knew. I disagree with the author of your first link. While you can do much of what it does with other extensions - none are as refined and you’d need multiple extensions to do so. I’d not put it in the ‘don’t bother pile’ yet, 'cause it’s still working just fine.

I did clone the repo when he first stopped working on it. I’ve considered studying what it does and asking to take it over.


This is interesting. Definitely worth keeping in mind.

I’ll try swap file for now and see how that goes, and may give zram a try in the future.

I also avoided swap because of not wearing out my SSD, but it seems it shouldn’t be such a problem after all. Especially if I adjust the settings to use swapping as little as possible.

I found this to start zram on boot you might find interesting: Zram swap on Arch Linux ☯ Daniel Wayne Armstrong


Assuming it’s a modern SSD, that’s not as much of a problem as it once was. They last for a zillion writes and the MTBF is pretty solid. They’re not impervious, but they’re pretty robust and reliable for years worth of writes. If you know who Backblaze is (they pretty much store everything for everyone), here’s an interesting article:

Anyhow, I’d not worry too much about using swap. Your drive will still last for years. They’re much more robust than they used to be. I have swap enabled -even though I have gobs of RAM.

Slight edit: I forgot, this one system doesn’t have swap enabled. I forgot to enable it during installation or something like that. But, the rest all do. I just wanted to be complete.

Thanks for this. I’m going to give swap file a try.

I haven’t had many crashed because of only browser usage, since I’m pretty good at keeping tabs to a minimum. I usually have problems when using VSCode, which usually means I’ll need to have a browser open as well.

From what I have found, a 4GB swap file would be good, with low swappiness and higher cache pressure to use swap only when absolutely necessary.

Something like:


What do you think?

BTW, I’m using 20.04 LTS

1 Like

I do have the almost cheapest SSD I could find :stuck_out_tongue_winking_eye:

It’s the only thing I have replaced on this cheap old laptop which I bought used for about $80 USD. The point of this laptop is to have something to take out with me and not worry if something bad happens to it :wink:

1 Like

I see nothing wrong with that. That won’t swap much. Though swap sometimes confuses me. It’s not just a place the OS stuffs stuff when you’re low on RAM. Even with 32 GB of RAM I still see some swap usage. So, it’s a bit more complicated than that. I’d say be open minded. You can adjust it temporarily before hard-coding it.

And Team Group SSDs are dirt cheap and have so far been reliable, should you end up needing a replacement. I am not in any way affiliated, I’ve just had really good luck with them.