this post was submitted on 17 Oct 2024
76 points (93.2% liked)

Linux

48331 readers
394 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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 your 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 successful. In disk swap is very slow, so the performance was crap, but that does not matter...

So i 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 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 above it's weight! even more impressive 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

all 40 comments
sorted by: hot top controversial new old
[–] moonpiedumplings@programming.dev 42 points 1 month ago (2 children)

Not infinite ram. I'd say double ram, plus there is a noticable, but quick delay when switching to an application that was compressed by ram. But it's much, much faster than switching to an app that was swapped to disk.

Cachyos (arch based distro) does this hy default.

[–] richardisaguy@lemmy.world 57 points 1 month ago

don't be silly, of course it's not infinite ram, the only way to get infinite ram is if you download it.

[–] gregor@gregtech.eu 6 points 1 month ago (2 children)

CachyOS mentioned! CachyOS btw

[–] Crozekiel@lemmy.zip 19 points 1 month ago (2 children)

Am I the only one that pronounces it swa-penis and giggles every single time?

[–] Eyck_of_denesle@lemmy.zip 7 points 1 month ago

Peter griffin what you are you doing here?

[–] mactan@lemmy.ml 19 points 1 month ago (1 children)

archwiki tuning has a listing with swappiness set up to 180 (yes apparently the number can go over 100)

[–] bruhduh@lemmy.world 8 points 1 month ago* (last edited 1 month ago)

Number is priority level, 100 is equal priority as real ram, over 100 is higher priority than real ram, less than 100 is less priority than real ram, and as far as I'm aware, max number is 200 and minimal number is 0

[–] bjoern_tantau@swg-empire.de 17 points 1 month ago (1 children)

Yeah, with zram I was able to actually play Cities Skylines on my Steam Deck.

[–] midnightblue@lemmy.ca 1 points 1 month ago (1 children)

The Steam Deck has shared RAM for the CPU and GPU, right?

[–] bjoern_tantau@swg-empire.de 1 points 1 month ago

Yeah. I didn't dare giving 100 % RAM to zram.

[–] hellofriend@lemmy.world 15 points 1 month ago (1 children)
[–] richardisaguy@lemmy.world 4 points 1 month ago

very gaming indeed

[–] ryannathans@aussie.zone 6 points 1 month ago* (last edited 1 month ago) (1 children)

The improvement you are describing is the default out of the box experience on pop os

[–] SynopsisTantilize@lemm.ee 2 points 1 month ago (1 children)

Any other distro really....except Ubuntu

[–] midnightblue@lemmy.ca 1 points 1 month ago (1 children)

Or Arch if you don't explicitly set it up yourself lol

[–] SynopsisTantilize@lemm.ee 1 points 1 month ago (1 children)

Oh. Right. Yea that one too lol

[–] midnightblue@lemmy.ca 1 points 1 month ago

Or Gentoo, Void, Alpine, I could go on and on

But these distros hardly set up anything for you out of the box, they're meant to be configured manually

But I can see Arch including an option for this in their install script at some point in the near future

[–] possiblylinux127@lemmy.zip 6 points 1 month ago (1 children)

Wouldn't it be easier to just put 8gb of ram in the system?

[–] richardisaguy@lemmy.world 3 points 1 month ago (2 children)

In my country that would cost me 20 dollars, what an absurd!

[–] possiblylinux127@lemmy.zip -1 points 1 month ago (1 children)

You could get a used stick from an junk dealer. Maybe I'm missing something but $20 doesn't seem like a lot. It is higher than I'd expect but not unreasonable

[–] Eyck_of_denesle@lemmy.zip 10 points 1 month ago

Every dollar/cent counts for some of us.

[–] fratermus@lemmy.sdf.org -1 points 1 month ago

In my country that would cost me 20 dollars

The first RAM I bought (SIPP for a 386-16 IIRC) was $50/MB. Jay-sus.

[–] mvirts@lemmy.world 4 points 1 month ago

Considering how much faster my CPU is than my ram, even though they are both 12 years old, I should do this 😹

Great post!

[–] lnxtx@feddit.nl 2 points 1 month ago (1 children)

[...] with negligible performance penalty

Which CPU do you have?

[–] richardisaguy@lemmy.world 6 points 1 month ago* (last edited 1 month ago) (1 children)

11th Gen Intel Core i3-1115G4 @ 4x 4.1GHz according to screenfetch, in practice i get at most 3.9ghz on cold days, and 3.4 on the other ones; the cpu is running at 70°C on idle right now.

~~send help, global warming and the local corporations are turning my nice little city into an unbearable hell~~

edit: screenfetch doesn't seem to be accurate with temps, i'm getting 46°C at idle

[–] entropicdrift@lemmy.sdf.org 6 points 1 month ago (1 children)

Am I right to assume you've got a laptop? Otherwise 70C is a terrible temp to hit at idle

[–] kixik@lemmy.ml 2 points 1 month ago* (last edited 1 month ago) (1 children)

Is it because Fedora doesn't enable zswap by default?

https://wiki.archlinux.org/title/Improving_performance#zram_or_zswap

https://wiki.archlinux.org/title/Zswap

https://wiki.archlinux.org/title/Zram

One down side of zram is that you won't be able to hibernate to swap, if that's a requirement. On consoles this might be totally irrelevant though.

[–] richardisaguy@lemmy.world 1 points 1 month ago

they do, but it uses the lz4 algorithm by default, which doesn't offer the highest compression rate, also the swapiness is not 100 by default.

[–] midnightblue@lemmy.ca 2 points 1 month ago (2 children)

Now I'm curious: Could something similar also be done for VRAM?

[–] richardisaguy@lemmy.world 2 points 1 month ago

i dont think so

[–] secret300@lemmy.sdf.org 1 points 1 month ago

I tried to look to see if vram could have something like zram on it but from what I found it's either not possible or not logical to do so because it's different from regular ram

[–] Lojcs@lemm.ee 2 points 1 month ago (1 children)

Do you need a swappiness over 1 if you don't have another swap device?

[–] richardisaguy@lemmy.world 1 points 1 month ago (1 children)

swapiness =/= priority, if your swapiness is at 1, the kernel is never going to use the device, if the number is high(like 100) every opportunity the kernel sees to put stuff in the swap, it is going to.

[–] Lojcs@lemm.ee 2 points 1 month ago (1 children)

Will it not use it even after the ram fills up? I wouldn't want the compressed part be prioritised anyways

[–] richardisaguy@lemmy.world 2 points 1 month ago

it won't let your ram fill up, i'm quite sure that when you get a high enough memory usage the kernel just starts dumping stuff into swap anyway

[–] Andromxda@lemmy.dbzer0.com 1 points 1 month ago

When do you think will Valve enable this by default in SteamOS? It would greatly help the little Steam Deck with playing more performance-intensive titles.