Zswap compression

I’ve been Zswap-enabled! Never going back to just plain swapping. Incredible how much of a difference a little tweak can make to an operating system.

2 Likes

Had to look it up, but I don’t swap.
What does zswap do?

Zswap is a kernel feature that provides a compressed RAM cache for swap memory pages. Pages which would otherwise typically be swapped out to hard disk are instead compressed and stored into a memory pool in RAM.Oct 31, 2023

4 Likes

I thought the whole idea of swap was to provide somewhere to put memory pages that could no longer be held in memory.
Now this zswap wants to put the swap space in memory. Does that not defeat the purpose of swap?
I know kernels swap before they critically need to. Is it for that?

1 Like

We’ve had a discussion on here before - I think @Rosika was going to try it out - and I was running it on one of my Raspberry Pi4 boxes…

2 Likes

dmesg grep zswap
0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.5.0-45-generic root=UUID=554ecbcb-5947-4cfe-a949- ro quiet splash zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4

[ 0.021446] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.5.0-45-generic root=UUID=554ecbcb–ro quiet splash zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4
[ 0.974634] zswap: loaded using pool lz4/z3fold
I removed some of the UUID

1 Like

No neville. This is compressing the memory data, I choose to use lz4 compression. This saves memory. Helps to prevent memory leaks. More secure way to store caching pages to memory by storing in compressed memory. Memory can read compressed data faster.

2 Likes

Compression will add to the cpu load. That might be OK on a machine with plenty of cores.

3 Likes

@daniel.m.tripp :

Hi Dan, :wave:

how good of you to remember.

Yes, there was a discussion here on the forum regarding this topic.

I think there´s also some good explanation regarding the differences between zram, zswap and zcache here:

I finally opted for zram, as Linux Lite´s own tweak app (Lite Tweaks) offers an activate/disable toggle switch for that:

(last item on the list).

Cheers from Rosika :slightly_smiling_face:

4 Likes

Cant argue with that, however what processor is not duel or quad.
The absolute number one: turn on zswap

1.You’ll often achieve a considerable speed gain by turning on zswap. This is especially so on older machines, but on modern machines there will also be a speed gain, even though it’ll be smaller. It’s therefore advisable to turn it on in all cases. Below, I’ll explain how to do that.

2 Likes

At one stage on the mac we did not have enough memory so ran a startup item ram doubler (extension). Yes you gained memory but it slowed some services down on compression and decompression. Guess this is something similar.

For me you cannot beat real memory.

Disk swapping for memory cashe does not work.

2 Likes

I’m running zram one of my Pi Zero 2W (debian bookworm armhf/arm7l [i.e. 32 bit ARM]) - for 2 years now (since August 2022).

I guess I should also enable it on my other Pi Zero 2W - which is mounted in a gimmicky “Beepy” chassis (low power screen and Blackberry keyboard and battery).

Nearly everything else I have has 4 or more GB of RAM - but on a Pi Zero - with only 0.5 GB of RAM - it’s helpful… I think I tried it on my Pi4 when it was running Stretch - but - it’s now running Ubuntu 22.04 “server”.

If I remember correctly - Resilio Sync was eating great chunks of my 512 MB RAM on the Pi Zero 2W…

2 Likes

Yes, and ram is quite cheap today. It pays to get the highest speed ram your machine can support.

4 Likes

Unless it’s soldered on like Apple are doing with ALL their devices…

You can buy 8 GB of DDR4 or 5 “SODIMM” for probably $300 - but - Apple want you to pay $1000+ to double the RAM in a MacBook (or even their desktop systems)…

I shouldn’t whinge - my personal MacBook Pro M1 with 8 GB of RAM still seems adequate, even 3 years later… My company supplied MBP Pro, has 16 GB of RAM - and - I get constant popups that I need to close some apps - I suspect its some of the dodgy “Crowdstrike-ish” big brother apps running on it… As well as Crowdstrike, t’s got a stack of other things on it - like some Zscaler thingie (I thought they just did load balancers), “BloxOne Endpoint” and a bunch of other dodgy little pieces of crap that pop up from time to time… They think they’re being useful, but they’re just making everything less efficient…

3 Likes

Yes memory is cheap for older machines, but many new ones come with everything soldered in place so no after market upgrades possible no sockets no easy removal and replace.

With the new mac if you specify more at purchase you pay a fortune extra

2 Likes

16GiB 3200mhz, 17 7700k oc to 4.3. I clearly see the difference with zswap enabled or disable. Mouse is fast, monitor is brighter, power is more stable. The whole system runs like a dream. Media, editing multiply doc at the same time, the difference is huge.
I prepared my Linux setup for zswap features. I had completed at setup. I created a separate partition for swap during the setup process.

ZSwap Configuration
same_filled_pages_enabled Y
enabled Y
max_pool_percent 20
compressor lz4
non_same_filled_pages_enabled Y
zpool zbud
exclusive_loads N
accept_threshold_percent 90

Partition:
ID-1: / size: 228.12 GiB used: 116.1 GiB (50.9%) fs: ext4 dev: /dev/nvme0n1p2
ID-2: /boot/efi size: 523 MiB used: 6.1 MiB (1.2%) fs: vfat dev: /dev/nvme0n1p1
ID-3: /home size: 468.38 GiB used: 255.22 GiB (54.5%) fs: ext4 dev: /dev/nvme1n1p1
ID-4: /var size: 227.71 GiB used: 8.88 GiB (3.9%) fs: ext4 dev: /dev/nvme0n1p3
Swap:
ID-1: swap-1 type: file size: 2 GiB used: 0 KiB (0.0%) priority: -2 file: /swapfile

1 Like

2Gb is tiny. I have 100Gb. I have nearly filled it running large numerical jobs.

2 Likes

Hi Neville, :wave:

That´s huge, right? :astonished:
For “running large numerical jobs” however you may need it.

The swap I defined for my system is 3 GB altogether:
I have a swapfile and zRAM:

rosika@rosika-Lenovo-H520e ~> swapon -s
Filename				Type		Size		Used		Priority
/dev/zram0                              partition	1961180		0		5
/swapfile                               file		1048572		0		-2

Seems to be good enough for me.
Yet I don´t do these enormous scientific calculations. :wink:

Many greetings from Rosika :slightly_smiling_face:

3 Likes

Yes, I admit what I do is unusual.
If you start a large process that takes all of ram then wants more, swap space is vital.
I used to have 2 100Gb swap spaces on 2 separate disks. I lost that when one of my HD’s failed. I dont want to put a swap space on the SSD… swapping is too active… it woild wear the SSD.

3 Likes

Hi Neville, :wave:

Wow, what a setup. :wink:

I get it. Yes, that certainly makes sense.

Cheers from Rosika :slightly_smiling_face:

3 Likes

I have it set to run from ram. When you compress this data its min.