Score:0

Make Firefox crash if out of memory instead of freezing the system

br flag

When out of memory on some heavy websites (like multi-tabbed reddit or just 1-tab mega.nz, given that my Macbook Air has only 4 GB) Firefox not just freezes, but it makes the whole system freeze, while, under the same circumstances, Opera crashes and the system stays ok.

When Firefox does that, there is no way I can fix it without reboot (system monitor, console tty not accessible etc).

Is that some tweak behind this difference between Firefox and Opera? Is it on the Ubuntu's side, or just Firefox's ? Can I do something from Kubuntu's own settings so that Firefox would not freeze the system when out of memory, but eventually just crash?

Kubuntu 22.10, Firefox 109, installed from PPA.

guiverc avatar
cn flag
Have you got an appropriate *swapfile* or *swap partition* for your usage? Having too little *swap* (or no swap at all) can kill performance... (My own experience with Lubuntu's defaults for various releases impacts this; I correct by manually setting an appropriate swap size)
br flag
@guiverc - I don't have a swap partition but I should have a swap file. I'll add soon to the question some details.
guiverc avatar
cn flag
Your issue may not relate to *swap*, just my immediate reaction (esp. for Lubuntu)... I've noted a few support requests with `firefox` 109; but I've not noted any issues and thus haven't explored it much yet. (`free -h` will show swap allocated; doesn't matter if *swapfile* or *partition*, just that you have an appropriate size)
br flag
@guiverc - Oh no, I don't even have a swap file, I thought Ubuntu sets one by default. I had one on an older installation (2 GB) but I had the same problem. I'll have to set a swap file and come back.
guiverc avatar
cn flag
FYI: The install options used will dictate if swap file is used/created, or swap partition is used/created... It's possible to install with swap, or without swap - the installer controls this (*swap partition is easier to understand regards setting though; swapfile isn't obvious; at least in my experience*)
br flag
@guiverc - I have now created a swap file of 2 GB. I am sure I had the same in my older installation, where the same problems occurred. The question is in fact why an application like Firefox should freeze the system instead of just itself freeze or crash when a similar one just crashes.
guiverc avatar
cn flag
Firefox is a *snap* package now, and I suspect it's defaults relate to *snapd* with regards memory, swap usage etc... Opera in your comparison isn't (I bet) a *snap* package and thus may differ... `systemd-oomd` I'd expect (*if not disabled*) to correct your situation when it detects the issue & runs (I don't recall using `systemd-oomd` without *swap* though in a high RAM environment, so maybe it doesn't perform well without swap; I don't know) UNLESS you've disabled it. In my experience it performs well (*it ain't perfect, but on average it's a decent benefit*). My opinion here though
br flag
@guiverc - sorry,it's not snap, its ppa... i'll add that detail.
br flag
@guiverc - I'll take some time now to test maybe the swap was in fact the problem. Thank you.
guiverc avatar
cn flag
I said "*without swap though in a RAM environment*" ^, I meant/intended "*without swap though in a high RAM usage environment*", eg. when browsers are wanting more RAM than machine has, not how I fear it read like in a large RAM machine... (ie. I QA-test with 2GB boxes; 4GB boxes, 5GB, 6GB etc... usually lower RAM boxes more often than 8GB or more)
karel avatar
sa flag
Two obvious possible solutions are Firefox Extended Support Release (ESR) and the Firefox snap package. Have you tried either of these, in particular Firefox ESR?
br flag
@karel - I fear that my question (why Opera and Firefox behaved differently) will stay without a sure answer because from my tests the new swap file seems to have made FF avoid freeze altogether - thus "hiding" the problem. (Maybe my old file was not correct or it was missing.) But if need be I'll test ESR. (I have in the past to avoid the new UI). But I will not use the snap version because of various problems with addons, Plasma etc.
karel avatar
sa flag
If Firefox ESR is able to solve your problem with Ubuntu freezing, please inform me of it by commenting so that I can post it as an answer.
Rishon JR avatar
pl flag
You can increase the swapfile size.
pierrely avatar
cn flag
run a loop pause script to add up the memory firefox is using... this link has a good function there for that... then if over whatever you say it is, killall the process. ps -eo rss,pid,euser,args:100 --sort %mem | grep -v grep | grep -i $@ | awk '{printf $1/1024 "MB"; $1=""; print }'
br flag
@pierrely - The problem is that adding a swap files avoids Firefox getting stuck. But I leave it open for reference, maybe I'll test this sometime.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.