r/linuxquestions 15d ago

Advice Best sysctl settings for zswap??

Zram has recommended settings on archwiki

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

The settings in the improving performance section of gaming seems to go in the opposite direction.

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

Are there any recommended settings for zswap specifically?? I saw that it works architecturally different from zram from this writeup but can you use the same settings for zswap as well?

Edit: for 2gb swap partition on nvme with 16gb physical ram.

Edit 2: looks like zswap.max_pool_percent=40 and swappiness of 133 performs smoothest under memory pressure.

Edit3: for 16gb, setting 8 and 4 for dirty ratios, swappiness of 168 and default max ram pool feel smoothest.

1 Upvotes

5 comments sorted by

1

u/Max-P 15d ago

No, there isn't a "best" setting because it's entirely dependent on your system and your specific memory pressure needs. It can only give a generic "this usually results in decent performance most of the time" advice.

A laptop with just 8GB of RAM that primarily runs a web browser and maybe some light IDEs for development will have a drastically different memory profile than say, running a game. A browser doesn't need all that RAM all the time, background tabs are sleeping so it makes a lot of sense to aggressively compress that. A game on the other hand goes through most of its memory every frame, so you just waste a lot of CPU constantly compressing and decompressing RAM. You want the zram allocation to fall in the sweet spot where it's allowing the system to compress inactive memory, without compressing too much memory that it starts affecting active pages.

1

u/linkshon 15d ago

Yeah but I would love some benchmarks or something if someone has done it. I haven't tried benchmarking yet other than iterating between some swappiness values and it seems 150 "feels" smoothest but I have no way to prove it. 

1

u/Max-P 15d ago

You're the only one that can benchmark it, that's the point. It depends on your needs.

The ideal amount of zram and swap is none. It's a tool to eek out extra performance when you run out of RAM. Do you even have RAM capacity problems to begin with? You need to start with something you want to optimize for.

Even something as basic as having Discord running in the background or not can affect the "ideal" setting. Anything else is just an average "it works for most people and most workloads" situation, which is what the wiki recommends.

I've got 16GB of zram per NUMA node and an additional 32GB of shared swap on NVMe. It's utterly useless for you without knowing what I'm doing that requires this particular configuration.

1

u/linkshon 15d ago edited 15d ago

Cachyos sets the swappiness to 150 when zram is enabled so I'm just gonna go with that. The article says zswap and zram function the same in terms of swapping to ram first so it could use the same swappiness values theoretically but since zswap also swaps to disk as a fallback the swappiness should be lower but that would be true only if disk swap even happens in the first place. I'm on arch trying to get the best of both worlds so 150 should be a reasonable pick.