Systemd-swap automatic swap management

Hello dear Manjaro fellows

I’ve very often come across a situation where my PC almost completely freezes, when I for example have 876 tabs opened in firefox and decide to compile something from the AUR. The only method to non-destructively resolve this situation is to switch to an alternate TTY, e.g. Ctrl+Alt+F4 and pkill firefox. That usually takes some time since even the shell is unresponsive and the first many attempts generate a 60s login timeout before I can enter the password.

Usually I decide to create a swapfile right after installation. But there is an even better solution, which I am confident could be a very welcomed default system component: systemd-swap

I found it on the Manjaro wiki:
It’s easy as pie and works like a charm. Install via package manager, tweak two lines in the default config and enable the service.

After discovering Cart Narcs on youtube I just watched my swap grow from 256 MB to 4 GB and shrink down again. I did not notice any hiccup on my system at all. Amazing!

What should be discussed, though, is the remark of the systemd-swap developers on their github repository, which states that users should migrate to zram-generator, also mentioned on the Arch-wiki page about Swap:

What do you think? Should this stay a manual task that every user has to take and decide upon one of the many (partly not well-known) solutions?

I am curious about your opinions!

Yes. It’s not a one-size-fits-all solution.

Thank you for the prompt reply. Can you elaborate on potential pitfalls of this or similar automated swap-managers?

I cannot fathom any reason to decide for a swap partition, -file, or none at all, if one knows of these automated solutions.

Some do not want swap at all. There are also choices between a swap partition, swap file, zswap, zram, etc. I’m sure you’re perfectly capable of doing your own research. Consult the Arch Wiki, it’s all there. :wink:

If you still have questions after all that exhaustive research, you’re welcome to ask them.

1 Like

That seem to be a fad of them, rather that a sane technical choice !

@ayd0r , @Yochanan is absolutely right in that use cases are different (yours being quite specific) although I agree with you on the fact that systemd-swap adjusts to very different situations.

In your case, there are some other tweaks or settings that can be used.
Can you give us your add-ons ?

grep -oP '},"name":"\K[^"]+' ~/.mozilla/firefox/*.*default*/addons.json

Do you use Webrender ?
Did you adjust swappiness ?

cat /proc/sys/vm/swappiness
cat /proc/sys/vm/vfs_cache_pressure

Do you use tlp & auto-cpufreq ?

Now that I think about it, the OOM killer seems to be disabled in Manjaro/GNOME. If that was enabled, having no swap could indeed be a valid choice.
Right now, as it is shipped, Manjaro just becomes unresponsive, similar to a freeze, when out of memory. Or could that be a specific problem of my PC?

I shouldn’t have described the freeze conditions so vividly. You can trivially reproduce it by just opening tabs in a browser of your choice.

Interesting. about:support says WebRender is my Compositor, the setting gfx:webrender:all is false, though. My addons:

uBlock Origin
Youtube Audio
Firefox Multi-Account Containers
GNOME Shell integration
ProxTube - Unblock YouTube
Old Reddit Redirect
Tabs Aside
Dark Mode (WebExtension)

Swappiness is at its default value of 60, vfs_cache_pressure at 100.
I didn’t know about tlp. It has an effective config file with 47 lines. Thank You for the hint @nam1962, that is good to know.
Tweaking the scaling governor from schedutil to ondemand and energy policy from balanced_performance to performance gave me a whooping 0,1% performance increase according to geekbench.
It doesn’t seem that auto-cpufreq is installed by default. I couldn’t find the binary on my system.

Well, I do open a lot of tabs & a lot of FF instances (One pro, one perso, one for personal business, one for testings…) and my 10 years old quad core I3 with 12Go DDR3 can cope with it.

Webrender :

You can also set browser.tabs.unloadOnLowMemory to true

On your FF you can add localcdn and auto tab discard

For swappiness, the goal is to maximize RAM usage, thus:

echo vm.swappiness=5 | sudo tee -a /etc/sysctl.d/99-swappiness.conf
echo vm.vfs_cache_pressure=50 | sudo tee -a /etc/sysctl.d/99-swappiness.conf
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

Auto-cpufreq is in community repositories.

You can add ananicy

After all this, tell us if your PC has less freezes :wink:

Thank you for all the tips. But at some point I stopped customizing my OS unless I run into problems.

Setting up any form of swap solved the problem of a stock Manjaro freezing when out of memory. This is a problem especially for newbies who don’t know about swap, and probably won’t know what to search for. That is what I wanted to discuss.

Trying to reproduce this on a VM, I found out that automatic partitioning has an option for swap. That is very satisfactory and basically fulfills my feature request:
I would propose changing the default to swapfile, though. Otherwise users might think “no swap” is the way most people do it.

On another note:
I could reproduce that the system “freezes up” instead of the OOM killer doing its job on both Manjaro and Ubuntu. This seems to be an upstream issue: Opening enough Youtube tabs on a fresh install will freeze your PC. When I went on and opened even more tabs, the GNOME session crashed and I was back at the login screen.
By the way, canonical doesn’t even give you any say or information in its installer. They decide that you want to use a swapfile in their predefined size. I had to disable it for the test.

3 FF instances,each with 30/40 tabs - TB with 23 mailboxes - shortwave + pulseeffects - Hamsket with WhatsApp, Skype, Tweetdeck, LinkedIn messaging, Trello, Slack, Telegram, Discord, Locals, Elements - Signal - Bauh
This on my 11 years old I3 Asus + the setting I suggested →

~]$ free
               total       utilisé      libre     partagé tamp/cache   disponible
Mem:           11751        6973         905        1277        3873        3190
Partition d'échange:        511         359         152