cross-posted from: https://lemmy.world/post/20962151

Hello Linux folks, i would like to share one little hack which i have found.

On fedora, zram-generator comes installed and configured by default with lz4 algorithm i believe, and no disk swap, if you have 8gb of ram or more, that is fine, but if you have 4gb or less, systemd-oomd either kills you games when they use too much memory, or you face an OOMD and get your system frozen.

When configuring fedora, normally i would create an in-disk swap, so that my computer wouldn’t freeze but face a MASSIVE slowdown when on way too high memory usage, i also set zram-generator to use the zstd algorithm so that zram compression rate is higher but slightly slower, like that i can use my low memory more efficiently with a lower risk of OOMD.

I was watching a bringus studios video once, where he tried to run counter-strike 2 on a ps4 using linux and proton; the game would always use too much memory and that would freeze the system before it got a change to actually launch, the strange ps4 linux was using in-disk swap, and so, increasing swapiness to 100 bringus tried to leverage that to make the game run. He was sucessful. In disk swap is very slow, so the performance was crap, but that does not matter…

So i saw that, and had the idea to combine it with zram-swap to avoid the in-disk swap penalty, also using zstd as the algorithm to make the most out of the memory, and it was a massive sucess! Some games which would make my system very unstable or straight up freeze on certain launch attempts started launching and working just fine! and without dumb in-disk swap slowdowns!

While running modded Victoria 2 i have noticed my system is using about 3.3 to 3.4GB of swap, and about 3.5 gb of ram, so about 100 to 200MB of real uncompressed memory usage, assuming zstd is running at level 1 of compression, and achieving at least 3.0 as compression rate, in thesis, my system has now the equivalent to 10GB of ram, well about it’s weight! even more impressing considering how low are the numbers we are working here!

tldr: setting your swapiness=100 while using zstd as your zram-generator compression algorithm, and no in-disk swap will help your system use the most out of your ram with negligible performance penalty

  • mox@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    13
    ·
    edit-2
    30 days ago

    You might also like to know:

    • If game crashes cause your system to freeze, it might not be the crash itself, but systemd hogging all the system resources while it writes a massive core dump to a file or journal (which can take a long time). You can disable this behavior with Storage=none and ProcessSizeMax=0 in /etc/systemd/coredump.conf.
    • Debian-based systems have a useful zram config skeleton in /etc/default/zramswap if you install the zram-tools package.
    • The Arch Linux wiki has more info on zram tuning, including swappiness and other kernel related parameters.
    • The /sbin/zramctl command will tell you how zram is doing.
  • Ace! _SL/S@ani.social
    link
    fedilink
    English
    arrow-up
    5
    ·
    30 days ago

    I absotutely love zram. Makes my 32gb ram feel endless even when splurging it on things no sane person would ever need

    Was kinda complicated to use a swapfile as backing device though