Probably reasonable assumption for a desktop, but in the end it will result in an actual number that is dependent on the workload and how the rest of the system is configured. So from that point of view one can also easily argue for ram/2 or 2*ram.
Similar benefits (at similar costs) can be achieved using zswap or zram. The two are generally similar in intent although not operation: zswap operates as a compressed RAM cache and neither requires (nor permits) extensive userspace configuration, whereas zram is a kernel module which can be used to create a compressed block device in RAM. zswap works in conjunction with a swap device while zram does not require a backing swap device.
To my understanding zram does not need anything else.
It doesn’t.
But it is not an either or situation as I understood your statement here:
This doesn’t apply to zswap as it needs the backing of another swap device, be it file or partition.
It doesn’t apply to zram because you can have both zram and another swap device, be it file or partition, for whatever reason. One being that you want to hibernate.
It doesn’t apply to swap file or swap partition either because nothing prevents you to have a set up with two or more swap devices, be it files and partitions.
It only applies to zram and zwap. If you want zram, then you would need to disable zswap with a kernel boot parameter.
That’s the best summary to that topic (for me at least).
tl;dr
Should swap partitions be avoided on nVME or other SSD storage media ? Not really, as the effect is negligible unless cat /proc/sys/vm/swappiness returns a value of 100. Or, better said - if the swap partition is only used infrequently or even unused most of the time, it won’t harm the solid state media that much.
- zswap additionally decreases the writes to the storage media significantly, as it is an compressed cache for the swap file
- zram on the other hand is a different approach, it’s compressing the data stored in RAM
Lessons (to be learned)
- Don’t use zram and zswap at the same time, as the compressions may cause interferences.
During the initial install which I’ve chosen last year, I’ve installed on a btrfs partition and kept a swap partition. It seems like zswap has been enabled during install, as I can’t recall it to have it enabled explicitly.
Guess I’ll continue with that setup.
Zswap is enabled by default in the kernel. You don’t need to explicitly enable it.
$ zgrep CONFIG_ZSWAP_DEFAULT_ON /proc/config.gz
CONFIG_ZSWAP_DEFAULT_ON=y
However, if you chose Zram, then you would need to disable it explicitly by adding zswap.enabled=0 to your kernel boot parameters.
Interesting option, but just to be complete, since we are hording good info in this thread: The zram-generator re-compression settings as configured by CachyOS also seems to fall into the “configured but never actually triggered” bucket. So it wont do anything on its own.
I don’t see an issue with my current setup, the swap partition is in fact barely used and as zswap has been active anyway…
The durability of nVMEs in terms of read/write operations has improved significantly in the recent years. Would be a different story in case I’ld setup a SBC which only has a mircoSD interface as a boot media and should act as a server with many read/write operations to be expected. In such a use case I’ld avoid the use of a swap partition in favor of zram I guess.
You refer to the lz4 (type=huge) part? Why won’t it be doing anything on its own?
From what I see (without looking at the actual code):
Zram manual. First two code blocks making the configuration, third block for triggering the re-compression.
zram-generator manual on compression-algorithm speaks about the configuration only.
Setting up a job to actually trigger that configuration is up to the user, see conversation on this zram-generator issue.
PS: But I may be wrong on that, since I haven’t looked into it as deeply as writeback. So input welcome.
Just my tl;dr 2 cents
Zram is awesome, since we are basically using Arch, and so we usually are supposed to set up everything ourself, and a swap partition or file is a considerable hurdle for new users. Zram is: Just download this, edit that file if you feel adventurous, but not required … boom: Swap! Works 99% of the time. Great performance too. - Just don’t forget to disable zswap.
On the other hand: While zram has great options that mimic zswap+swap functionality, the learning curve moves from easy to hardcore fast, and there are no established “just download this” solutions for those. Also: hibernation.
open question:
if my Arch Zswap is enabled by default (it’s true I checked it), and I went ahead and created a traditional swap partition when I installed…and the Arch manual ^^ there says basically “they will live in holy harmony”…
…then I’m set, right? Leave well enough alone?
oh man this is a fantastic thread to sort out all the variations.
Still unsure of the scenarios where all these variations would be applied (for instance/for example) but like I said…
I don’t game or watch movies or stream or data mine coins I’m just a basic work/internet/hang out here guy.
This has been an education.
Yes. This is my understanding. Though you could still tweak some aspects of the zswap as can be seen here: https://wiki.archlinux.org/title/Zswap#Customizing_zswap
I admit that I haven’t looked into it to discern exactly which options are best suited for what use cases and workloads.
If you don’t want a swap partition (or file) then I would say zram is the way to go. Just put a simple configuration file in /etc/systemd, disable zswap in the kernel and you are set.
that’s an idea. Life without a traditional swap will move me out of my comfort zone, but I love moving myself out of the comfort zone sometimes.
Try it. And have a terminal open with watch free -m running to monitor what your memory and swap usage look like every 2 second.
I’ve been mulling this over about an hour. Think I will try it tomorrow. [Now if I can repurposed that partition and add it to Arch ext4…but that’s a gparted project for another day..]
Now that I’m getting into localized LLM’s, I’m seeing my zram used more.
Watching mem and swap (zram + file) usage in real time.
mem=8G, swapfile=8G, zram=mem/2, compression=lzo-rle
Swapfile wont do anything with zram from your screenshot. On my 13 years old notebook i only use zram with the configs from the wiki
1.2 and 2.3
It is not doing anything now but I have it for hibernation.
Understood
