You are not logged in.

#1 2025-06-05 21:47:39

Cloud_Strife2020
Member
Registered: 2013-10-31
Posts: 7

Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

Hi everyone,
I'm planning to install Arch on my main laptop for use with Stable Diffusion and gaming, and I’d love some advice on swap/zram/zswap setup, as well as general tips for performance tuning (gaming, memory, GPU-related workloads).

Hardware:
Dell G5 laptop
i7-9750H
32GB RAM
512GB SSD
RTX 2070 Max-Q

I used Arch years ago (~15 years back), so I’m familiar with the basics but catching up on more modern tools and setups.

Memory Management: zram vs zswap vs swap file
I initially thought of using 8GB zram + 32GB swap file, then I came across zswap and got a bit confused.

So, zwap is a function that allows to compress data before pushing it to swap? ( https://www.reddit.com/r/archlinux/comm … p_vs_swap/ )
If we use both zram + zsap we will have this kind of scenario, right?

So in a combined setup, would the memory hierarchy look like this?

24gb RAM - Active data
8gb zram - compressed inactive data
zswap - ??? (compressed inactive data but where physically?)
32gb swap file on ssd - last resort, compressed inactive data

Can zram and zswap be used together?

If so, is there any benefit, or is it redundant?
Where does zswap store compressed pages?
I’d like to hibernate the system — is a 32GB swap file enough for 32GB RAM?
Is there any reason to prefer a swap partition over a swap file for this?
Can zram/zswap be configured after installation, or should it be baked in from the start?

I want to avoid performance drops like I currently have on Windows, where Stable Diffusion sometimes slows down dramatically (2s/it → 80s/it), likely due to pagefile usage on SSD.

Gaming & Kernel Tweaks
I’ll be gaming via Steam/Proton, with HDR and DualSense controller support.
I’m considering using Wayland, probably with Gnome.
I found projects like ALHP and CachyOS kernel that might help with performance.

Maybe there are some things that I'm missing that comes in your mind?

Thanks in advance!

Offline

#2 2025-06-06 01:15:13

cloverskull
Member
Registered: 2018-09-30
Posts: 236

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

Commenting because I'd like to know this as well tongue

I use Wayland with KDE Plasma for everything and aside from one issue I've had with my laptop trackpad periodically, things are great. I really like it, I think it's an excellent DE and strongly prefer it to Gnome, but this is probably just personal preference and nothing to do with gaming.

Regarding RAM, I've been using zram, with zram-generator. I set it up to be half the size of my normal RAM. Here's my /etc/systemd/zram-generator.conf:

❯ cat /etc/systemd/zram-generator.conf         
[zram0]
zram-size = ram / 2
compression-algorithm = zstd

For me this has been fine. I have 32GB physical RAM and then 16GB zram. I do a decent-ish amount of gaming on this laptop (don't tell my company! hehe) and haven't had any issues. I think with 32GB physical RAM, you're probably fine, and I can't foresee a reason you'd want to have so much additional swap space, but I could be wrong.

But I think the important thing here is, to answer your question on 32gb/24gb/8gb/etc and how it would all work with zram, I've had luck using half of my actual RAM as compressed zram and performance has been great. I personally prefer not to create a swap file or partition since I have all this memory on tap already. I did temporarily create a full 32GB swapfile in an effort to get hibernation to work, but gave up on it after getting a bit frustrated tongue and so far so good with every game I've tried running.

Additionally, you may find of interest that I do use ALHP with the x86-64_v3 build. I also have a decent makepkg.conf with some tweaks for performance. That said, I don't go overboard with tweaking things outside of that, because I find the results to be diminished the more I try to do, and the behavior become unpredictable.

What I /can't/ speak to is Stable Diffusion, however I've done quite a bit of AI/ML work using my NVidia GPU and nvidia-docker just fine, and my GPU isn't even all that great. So, food for thought.

Good luck! Hopefully other folks smarter than me chime in with some real advice here lol.

Offline

#3 2025-06-06 06:30:46

seth
Member
Registered: 2012-09-03
Posts: 64,477

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

Do not use zram AND zswap, the wiki article addresses this, https://wiki.archlinux.org/title/Zram
zswap is enabled by default, so make sure to disable it if using zram.
Also zswap *needs* a physical swap (file or partition doesn't matter) as backup.

Both approaches can (literally) explode in your face when the memory gets decompressed (zip-bomb)

The hibernation location can be a swap file or partition, does NOT have to be swapon-ed (ie. you can have a swapfile just lying around or dynamically created for hibernation and an actual, smaller swap partition as zswap backup - the partition has slight performance benefits)
The hibernation image is typically not as large as your RAM, but a storage location matching your RAM size is a pretty safe bet. But it /has/ to be coherent (ie. you cannot combine a swap partition and a swap file or so) and for obvious reasons neither a zram device wink

PSA, remember: swap is to catch spill-over and liberates the FS cache, but if you're constantly running your system on swap, you need more RAM.

Offline

#4 2025-06-06 14:09:42

Cloud_Strife2020
Member
Registered: 2013-10-31
Posts: 7

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

seth wrote:

Do not use zram AND zswap, the wiki article addresses this, https://wiki.archlinux.org/title/Zram
zswap is enabled by default, so make sure to disable it if using zram.
Also zswap *needs* a physical swap (file or partition doesn't matter) as backup.

Both approaches can (literally) explode in your face when the memory gets decompressed (zip-bomb)

The hibernation location can be a swap file or partition, does NOT have to be swapon-ed (ie. you can have a swapfile just lying around or dynamically created for hibernation and an actual, smaller swap partition as zswap backup - the partition has slight performance benefits)
The hibernation image is typically not as large as your RAM, but a storage location matching your RAM size is a pretty safe bet. But it /has/ to be coherent (ie. you cannot combine a swap partition and a swap file or so) and for obvious reasons neither a zram device wink

PSA, remember: swap is to catch spill-over and liberates the FS cache, but if you're constantly running your system on swap, you need more RAM.

Hmm, the wiki says that zram is not compatible with hibernation.
I'll try to go with a 32gb swap file, and zswap on for start.

Thanks! smile

Offline

#5 2025-06-06 14:12:31

seth
Member
Registered: 2012-09-03
Posts: 64,477

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

zram is perfectly compatible w/ hibernation, you just cannot (for obvious reasons) use the zram device (which resides in your RAM) as hibernation storage (cause your RAM will flush) - so you'll have to have some other device (partition or file) for the hibernation image.

Offline

#6 2025-06-06 14:19:23

Cloud_Strife2020
Member
Registered: 2013-10-31
Posts: 7

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

seth wrote:

zram is perfectly compatible w/ hibernation, you just cannot (for obvious reasons) use the zram device (which resides in your RAM) as hibernation storage (cause your RAM will flush) - so you'll have to have some other device (partition or file) for the hibernation image.

Oh, I see, so is correct to say - zram space cannot be used for hibernation, right?
then, I'll try both approaches,  swapfile for hibernation + zram, and swapfile + zswap.

You said that a swap partition has slight performance benefits, which are these benefits?

Offline

#7 2025-06-06 14:34:38

seth
Member
Registered: 2012-09-03
Posts: 64,477

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

is correct to say - zram space cannot be used for hibernation, right?

Right. You cannot use your RAM when the system has powered down for hibernation (that's the main difference between S3 and S4)

which are these benefits?

It's faster? (You skip the filesystem)
The operating term here is "slight" - even on an nvme swap still performs shit compared to RAM (let's not talk about them poor spinners…) so one might argue that the difference becomes neglectable (and for hibernation they are, you'll be able to endure 5 more milliseconds when powering down)
If you constantly swap out, you need more RAM.

nb. that there's also the IRS (Intel Rapid Start "Technology", yeah, sure… we all can see it)

If you care for my 2¢, I S3 the notebook over the day (it's not that much combined S3-time anyway) and then power it down in the evening.
The boot after the loader is hardly any slower than resuming from hibernation, which thus arguably becomes pointless wear on the drive (for NAND, SSD or nvme, writing is expensive and reading is cheap) - you only need to make sure to safe all data before powering down wink

Offline

#8 2025-06-06 15:25:04

Cloud_Strife2020
Member
Registered: 2013-10-31
Posts: 7

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

seth wrote:

is correct to say - zram space cannot be used for hibernation, right?

Right. You cannot use your RAM when the system has powered down for hibernation (that's the main difference between S3 and S4)

which are these benefits?

It's faster? (You skip the filesystem)
The operating term here is "slight" - even on an nvme swap still performs shit compared to RAM (let's not talk about them poor spinners…) so one might argue that the difference becomes neglectable (and for hibernation they are, you'll be able to endure 5 more milliseconds when powering down)
If you constantly swap out, you need more RAM.

nb. that there's also the IRS (Intel Rapid Start "Technology", yeah, sure… we all can see it)

If you care for my 2¢, I S3 the notebook over the day (it's not that much combined S3-time anyway) and then power it down in the evening.
The boot after the loader is hardly any slower than resuming from hibernation, which thus arguably becomes pointless wear on the drive (for NAND, SSD or nvme, writing is expensive and reading is cheap) - you only need to make sure to safe all data before powering down wink

Thank you for the info!
What do you mean by S3 and S4?

I'm used to use hibernation only over night, so I don't need to open all the software (browser, stable diff, folders, ecc.),  but this  really can be  mitigated by setting an autoboot script.

Durring the day I never turn off the machine btw.

I didn't even know that ssd swap is so slow  (logic: ssd are fast --> ssd swap is fast too)
Now I remember some yearrs ago, Microsoft did something that makes your usb flash stick into RAM, I can imagine the speed. Like, the thing that is made to save you, just makes you die slower lol

so, at this point, maybe zram is a better option, in that way you can boost the fast ram quantity, delaying the moment of using the slow nvme swap (let's just put it here just in case), and turn off hibernation.

Last edited by Cloud_Strife2020 (2025-06-06 15:28:17)

Offline

#9 2025-06-06 18:49:01

seth
Member
Registered: 2012-09-03
Posts: 64,477

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

S3 = Suspend to RAM
S4 = Suspend to Disk (hibernation)

I didn't even know that ssd swap is so slow

ssd is not "fast" relative to RAM.
The fastest nvme is about 2/3 of the bottom end of DDR4, realistically you're looking at at least a magnitude difference (10,20,30 times) with an nvme.

Microsoft did something that makes your usb flash stick into RAM

DO NOT USE USB KEYS FOR SWAP! Not only will they be dog slow (even "usb3" ones are barely above usb2 throughput) but because of the lack of a wear leveling controller, they will also die in no time.

so, at this point, maybe zram is a better option, in that way you can boost the fast ram quantity, delaying the moment of using the slow nvme swap

zram swap and zswap follow the same principle idea itr, the difference is really in the details (notably that zswap requires a backup swap, zram can have a secondary swap w/ lower priority) - you can try both, arch currently defaults to zswap anyway so you could start with that, see how it performs, tune it a bit, then use that experience as baseline for a subsequent zram test. The only really important thing is that you don't try to use them together.

Offline

#10 2025-06-06 21:42:58

Cloud_Strife2020
Member
Registered: 2013-10-31
Posts: 7

Re: Returning to Arch – zram, zswap, swap for Stable Diffusion & Gaming

seth wrote:

S3 = Suspend to RAM
S4 = Suspend to Disk (hibernation)

I didn't even know that ssd swap is so slow

ssd is not "fast" relative to RAM.
The fastest nvme is about 2/3 of the bottom end of DDR4, realistically you're looking at at least a magnitude difference (10,20,30 times) with an nvme.

Microsoft did something that makes your usb flash stick into RAM

DO NOT USE USB KEYS FOR SWAP! Not only will they be dog slow (even "usb3" ones are barely above usb2 throughput) but because of the lack of a wear leveling controller, they will also die in no time.

so, at this point, maybe zram is a better option, in that way you can boost the fast ram quantity, delaying the moment of using the slow nvme swap

zram swap and zswap follow the same principle idea itr, the difference is really in the details (notably that zswap requires a backup swap, zram can have a secondary swap w/ lower priority) - you can try both, arch currently defaults to zswap anyway so you could start with that, see how it performs, tune it a bit, then use that experience as baseline for a subsequent zram test. The only really important thing is that you don't try to use them together.

Got it!
thank you very much! smile

Offline

Board footer

Powered by FluxBB