When filling up all memory and swap my experience the most recent years has been that:
Windows and macOS go "oh, let's fix that for you" and then presumably increase the swap size. Opening e.g. 30 YouTube tabs slows things down for a while, but I can generally still use the cursor if I want to abort the process, and after that the rest of the system (not necessarily the offending app) is pretty much as responsive as always.
Ubuntu (21.04) goes "sorry, you can't interact with the computer for the next ten to thirty minutes". On the same hardware and the same browser, I can open 30 YouTube tabs and watch the whole system lock up. All memory and swap is used up, and the cursor is not just slow but locked in place. I can't meaningfully interact with the rest of the system.
The difference seems to be that Ubuntu never resolves the situation, keeps its swap size constant and consequently keeps locking up every five seconds, forever. Until, that is, catastrophic failure occurs and Firefox disappears without a trace — something that virtually never happens in other OSes. The most crucial aspect is that I'm unable to interact with the rest of the system.
I don't know, but I get the impression this would not be an issue if the swap size were increased based on demand. How is that accomplished? Is there better memory management to be had somehow?
After (not so quickly) doing the quick test suggested in the comments where I doubled the size of the swapfile I can conclude that it makes all the difference in the world. The system remained responsive throughout during the same load. I can only conclude that an adaptive swap size would alleviate the described problem.
$ free -h total used free shared buff/cache available Mem: 3.7Gi 3.1Gi 129Mi 374Mi 566Mi 105Mi Swap: 4.0Gi 3.0Gi 988Mi $ sysctl vm.swappiness vm.swappiness = 60 $ swapon -s Filename Type Size Used Priority /swapfile_4G.img file 4194300 3180664 20
A note on hardware
One of the selling points of Ubuntu (among others) is to get continued support and increase the life-span of older hardware, which includes machines with less than average total memory. Not absurdly little memory, as demonstrated by the fact that other OSes can make do just fine, just less than average. Many of these machines are non-upgradable.
4 GB RAM works fine for most use cases. In Ubuntu, in Windows, in macOS. What only seems to work fine in Windows and macOS, however, is when you use up all allocated swap space.
In short, the same instant that the solution to making Ubuntu run decently becomes "buy new hardware" the whole point of running it becomes moot for all these machines. Upgrading the hardware is out of scope for this question.