HOW-TO: get a speed gain by using zswap

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

HOW-TO: get a speed gain by using zswap

Post by Pjotr »

How-to with explanations on my website:
https://easylinuxtipsproject.blogspot.c ... html#ID1.2
(item 1.2)

On my machines, I was agreeably surprised by the speed gain that I noticed. Have fun! :)
Last edited by Pjotr on Wed Jan 19, 2022 3:15 pm, edited 2 times in total.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: HOW-TO: get a speed gain by using zswap

Post by Flemur »

Pjotr wrote: Mon Jan 10, 2022 7:43 am First set swappiness to 25, then edit /etc/default/grub by replacing GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" with GRUB_CMDLINE_LINUX_DEFAULT="quiet splash zswap.enabled=1 zswap.compressor=lz4. Then run sudo update-grub and reboot.
You probably want a " (closing quote) after zswap.compressor=lz4
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

Flemur wrote: Mon Jan 10, 2022 9:25 am You probably want a " (closing quote) after zswap.compressor=lz4
Oops. :P

Thanks for the alert; I've corrected it immediately.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

By default, zswap is using zbud (compression factor: 2). It's also possible to switch to z3fold (compression factor: 3).

But reports about z3fold differ: I've read a well-documented report that states that z3fold actually makes zswap run a lot slower than zbud. So I don't recommend adding z3fold into the mix.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
DPM
Level 4
Level 4
Posts: 430
Joined: Thu Sep 24, 2020 9:21 am

Re: HOW-TO: get a speed gain by using zswap

Post by DPM »

Pjotr wrote: Mon Jan 10, 2022 7:43 amFirst set swappiness to 25
Going by the rate of how your recommendation has increased, that should be at default settings for Linux Mint 22 (in 2024). 8)
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

DPM wrote: Wed Jan 12, 2022 6:05 pm
Pjotr wrote: Mon Jan 10, 2022 7:43 amFirst set swappiness to 25
Going by the rate of how your recommendation has increased, that should be at default settings for Linux Mint 22 (in 2024). 8)
LOL. Who knows. :lol:

But the increase from 20 to 25 in my swappiness recommendation, was purely instigated by my wish to avoid confusion with the default 20 percent of zswap, not by technical considerations....
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

I've modified and expanded the how-to, in order to include z3fold and an increase to 40 % for zswap on machines with relatively low RAM (4 GB or less):
https://easylinuxtipsproject.blogspot.c ... html#ID1.2

Reason: on second thought, the speed difference between zbud (faster) and z3fold (slower) on old machines, is irrelevant.... Because those old machines nearly always have slow, spinning platter disks, so every avoidance of using the swap on the HDD is invariably pure gain.

Also, on machines with little RAM, 40 % zswap makes more sense than 20 %. Example: if you have a machine with merely 2 GB physical RAM and 40 % zswap, you "suddenly" have 1,2 (2 - 0,8) + 2,4 (3 x 0,8) = 3,6 GB RAM available. Because z3fold has a compression factor of 3.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
MikeNovember
Level 7
Level 7
Posts: 1856
Joined: Fri Feb 28, 2020 7:37 am
Location: Nice, Paris, France

Re: HOW-TO: get a speed gain by using zswap

Post by MikeNovember »

Hi,

Is zswap very different from zram, is it better ?

Regards,

MN
_____________________________
Linux Mint 21.3 Mate host with Ubuntu Pro enabled, VMware Workstation Player with Windows 10 Pro guest, ASUS G74SX (i7-2670QM, 16 GB RAM, GTX560M with 3GB RAM, 1TB SSD).
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

MikeNovember wrote: Thu Jan 20, 2022 4:53 am Is zswap very different from zram, is it better ?
Yes and yes. They're more or less opposites; using them at the same time is counterproductive. I experimented with zRam in the past, but it caused instability. With zswap I don't have those problems.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by smurphos »

What problems did you have with ZRAM? Been using it for 18 months on my main machine (with no physical SWAP) with no issues.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

smurphos wrote: Thu Jan 20, 2022 6:20 am What problems did you have with ZRAM? Been using it for 18 months on my main machine (with no physical SWAP) with no issues.
I'm afraid I can't quite recall it; I think it's at least five years ago that I last dabbled with zRam.... General instability. Sudden crashes of applications, possibly even an X failure. Overall nasty.... Never felt the inclination to mess with bloody zRam ever since. :twisted:

But what works for you, is of course fine for you.... :wink:
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
Venus Flytrap
Level 2
Level 2
Posts: 92
Joined: Thu Sep 30, 2021 6:32 am
Location: Canada

Re: HOW-TO: get a speed gain by using zswap

Post by Venus Flytrap »

Pjotr wrote: Wed Jan 12, 2022 6:16 pm
DPM wrote: Wed Jan 12, 2022 6:05 pm
Pjotr wrote: Mon Jan 10, 2022 7:43 amFirst set swappiness to 25
Going by the rate of how your recommendation has increased, that should be at default settings for Linux Mint 22 (in 2024). 8)
LOL. Who knows. :lol:
But the increase from 20 to 25 in my swappiness recommendation, was purely instigated by my wish to avoid confusion with the default 20 percent of zswap, not by technical considerations....
I'll keep my swappiness to the original 20 then! :wink: It seems to work best on my ancient 4GB RAM computer. I have updated the zswap to use the z3fold compression. I'll be interested to see if I notice any difference with it compared to the zbud. Thanks for all the great advice here. Cheers.
System: Mint Cinnamon 21.1. CPU: Intel E7600. RAM: 4GB. Video: ATI HD 4830. SSD: Kingston KC600 512GB (boot-drive) & Kingston A400, 480GB (backup). Display: ASUS VA24DQ 23.8"
Menard
Level 7
Level 7
Posts: 1729
Joined: Wed May 08, 2019 5:14 am
Location: Angers (France)

Re: HOW-TO: get a speed gain by using zswap

Post by Menard »

Let's go :)
Linux Mint 20.3 Cinnamon - K 5.15 - Desktop - english
AMD APU A8 7600 - DDR3 1833 MHz 8 GB x2 Dual Channel
--

If you think tough men are dangerous, wait until you see what weak men are capable of.
Menard
Level 7
Level 7
Posts: 1729
Joined: Wed May 08, 2019 5:14 am
Location: Angers (France)

Re: HOW-TO: get a speed gain by using zswap

Post by Menard »

What I noticed with this compared with before ...

1 - Great stability until 90% even 95% RAM used, because before it was difficult at 80% BUT
2 - It touched 100% and then it ended by a total freeze of the display (or else ?) so that I had to reboot with Alt+ as ctrl+alt+del didn't work :?
but it was a test, I tried to function with 4 internet browsers, but in normal state only 2 are needed for me

At the moment when I wanted to unload some Firefox tabs, too late, it freezed
Linux Mint 20.3 Cinnamon - K 5.15 - Desktop - english
AMD APU A8 7600 - DDR3 1833 MHz 8 GB x2 Dual Channel
--

If you think tough men are dangerous, wait until you see what weak men are capable of.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

Menard wrote: Wed Jun 08, 2022 10:57 am What I noticed with this compared with before ...

1 - Great stability until 90% even 95% RAM used, because before it was difficult at 80% BUT
2 - It touched 100% and then it ended by a total freeze of the display (or else ?) so that I had to reboot with Alt+ as ctrl+alt+del didn't work :?
but it was a test, I tried to function with 4 internet browsers, but in normal state only 2 are needed for me

At the moment when I wanted to unload some Firefox tabs, too late, it freezed
OK.... Can you give the output of inxi -Fxpmrz?
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Menard
Level 7
Level 7
Posts: 1729
Joined: Wed May 08, 2019 5:14 am
Location: Angers (France)

Re: HOW-TO: get a speed gain by using zswap

Post by Menard »

Code: Select all

inxi -Fxpmrz
System: Kernel: 5.4.0-107-generic x86_64 bits: 64 compiler: gcc v: 9.4.0 Desktop: Cinnamon 5.2.7
Distro: Linux Mint 20.3 Una base: Ubuntu 20.04 focal
Machine: Type: Desktop Mobo: MSI model: A88XM-E35 V2 (MS-7721) v: 6.0 serial: <filter> UEFI [Legacy]: American Megatrends
v: 6.5 date: 08/10/2016
Memory: RAM: total: 6.81 GiB used: 1.83 GiB (26.8%)
RAM Report: permissions: Unable to run dmidecode. Root privileges required.
CPU: Topology: Quad Core model: AMD A8-7600 Radeon R7 10 Compute Cores 4C+6G bits: 64 type: MCP arch: Steamroller rev: 1
L2 cache: 2048 KiB
flags: avx lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 24755
Speed: 1680 MHz min/max: 1400/3100 MHz Core speeds (MHz): 1: 1765 2: 1666 3: 1397 4: 1397
Graphics: Device-1: Advanced Micro Devices [AMD/ATI] Kaveri [Radeon R7 Graphics] vendor: Micro-Star MSI driver: radeon
v: kernel bus ID: 00:01.0
Display: x11 server: X.Org 1.20.13 driver: ati,radeon unloaded: fbdev,modesetting,vesa resolution: 1920x1080~60Hz
OpenGL: renderer: AMD KAVERI (DRM 2.50.0 5.4.0-107-generic LLVM 12.0.0) v: 4.5 Mesa 21.2.6 direct render: Yes
Audio: Device-1: Advanced Micro Devices [AMD/ATI] Kaveri HDMI/DP Audio vendor: Micro-Star MSI driver: snd_hda_intel
v: kernel bus ID: 00:01.1
Device-2: Advanced Micro Devices [AMD] FCH Azalia vendor: Micro-Star MSI driver: snd_hda_intel v: kernel
bus ID: 00:14.2
Sound Server: ALSA v: k5.4.0-107-generic
Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: Micro-Star MSI driver: r8169 v: kernel
port: e000 bus ID: 01:00.0
IF: enp1s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Drives: Local Storage: total: 931.52 GiB used: 786.29 GiB (84.4%)
ID-1: /dev/sda type: USB vendor: Seagate model: BUP Slim BK size: 465.76 GiB
ID-2: /dev/sdb vendor: Seagate model: ST3500630A size: 465.76 GiB
Partition: ID-1: / size: 29.40 GiB used: 14.59 GiB (49.6%) fs: ext4 dev: /dev/sda1
ID-2: /home size: 29.40 GiB used: 22.72 GiB (77.3%) fs: ext4 dev: /dev/sdb2
ID-3: /media/u3/3e7d319e-beaf-494c-8d92-e76e02b2fc4f size: 29.40 GiB used: 10.51 GiB (35.8%) fs: ext4
dev: /dev/sda2
ID-4: /media/u3/NT2 size: 255.76 GiB used: 250.43 GiB (97.9%) fs: ntfs dev: /dev/sda4
ID-5: /mnt/5369961B0C75217E size: 150.00 GiB used: 140.95 GiB (94.0%) fs: ntfs dev: /dev/sda3
ID-6: /mnt/80ACB656ACB64686 size: 150.01 GiB used: 121.71 GiB (81.1%) fs: ntfs dev: /dev/sdb6
ID-7: /mnt/924CFEB44CFE9269 size: 250.74 GiB used: 225.38 GiB (89.9%) fs: ntfs dev: /dev/sdb7
Sensors: System Temperatures: cpu: 3.6 C mobo: N/A gpu: radeon temp: 3 C
Fan Speeds (RPM): N/A
Repos: No active apt repos in: /etc/apt/sources.list
Active apt repos in: /etc/apt/sources.list.d/brave-browser-release.list
1: deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main
Active apt repos in: /etc/apt/sources.list.d/google-chrome.list
1: deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main
Active apt repos in: /etc/apt/sources.list.d/google-earth-pro.list
1: deb [arch=amd64] http://dl.google.com/linux/earth/deb/ stable main
Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list
1: deb http://packages.linuxmint.com una main upstream import backport #id:linuxmint_main
2: deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
3: deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
4: deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
5: deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
6: deb http://archive.canonical.com/ubuntu/ focal partner
Info: Processes: 250 Uptime: 1h 31m Init: systemd runlevel: 5 Compilers: gcc: 9.4.0 Shell: bash v: 5.0.17 inxi: 3.0.38
But for what I noticed in this test, it will be cool for current work, and I have this tool (script) provided by @SimonPeter a RAM alarm, that works well, I have only to think to it or to put it in startup tasks

But really in my test I was surprised by a very safe behaviour of my system, far beyond the level where (when ?) commonly it is almost broken ... and this for a far more work load
Linux Mint 20.3 Cinnamon - K 5.15 - Desktop - english
AMD APU A8 7600 - DDR3 1833 MHz 8 GB x2 Dual Channel
--

If you think tough men are dangerous, wait until you see what weak men are capable of.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

Well, I can see that your partitions are very full, in some cases much too full. This can also be the cause of system malfunctions.

I recommend to reduce the contents of your partitions, so that each partition is filled for maximally 75-80 %. This has to do with the way that the filesystem EXT4 works:
https://easylinuxtipsproject.blogspot.c ... 1.html#ID4
(item 4)

Here are some safe cleaning tips:
https://easylinuxtipsproject.blogspot.c ... -mint.html

Furthermore, as you have AMD graphics, you might benefit from a kernel from a newer series:
Update Manager - panel: View - Linux kernels
Install the latest kernel of the 5.15 series. Then reboot and test.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Menard
Level 7
Level 7
Posts: 1729
Joined: Wed May 08, 2019 5:14 am
Location: Angers (France)

Re: HOW-TO: get a speed gain by using zswap

Post by Menard »

For me that's totally nonsense , for one reason, that if Linux is not happy with my partitions I can unmount them all excepted the root and home partitions and we will see if it continues to generate problems ... I see no problems here that coulds justifye to me to bother with partitions, a partition is made to be fulled to the last bit
Linux Mint 20.3 Cinnamon - K 5.15 - Desktop - english
AMD APU A8 7600 - DDR3 1833 MHz 8 GB x2 Dual Channel
--

If you think tough men are dangerous, wait until you see what weak men are capable of.
User avatar
Pjotr
Level 24
Level 24
Posts: 20118
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: HOW-TO: get a speed gain by using zswap

Post by Pjotr »

Menard wrote: Thu Jun 09, 2022 10:00 am For me that's totally nonsense , for one reason, that if Linux is not happy with my partitions I can unmount them all excepted the root and home partitions and we will see if it continues to generate problems ... I see no problems here that coulds justifye to me to bother with partitions, a partition is made to be fulled to the last bit
It's a free world; each man should as he pleases. Bonne chance. :lol:
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
Marie SWE
Level 5
Level 5
Posts: 713
Joined: Wed Feb 28, 2018 7:32 pm
Location: Sweden

Re: HOW-TO: get a speed gain by using zswap

Post by Marie SWE »

I want to backup Pjotr post and statement.

System partitions should never be filled not even in windows..
Data storage partitions those don't matter in the same way, as it only effect reed/write times to/from/between those drives.
a filled system disk will effect the system performance in more ways then one. That goes for both Linux and Windows.

'
Edit.
The reason you Menard and all else that experiences this to get a total freeze when your memory is used to 99 to 100% is called swapdeath or I/O trashing.
This is a kind of "bug" in the linux kernel that was first discovered in 1997 or if it was 1998. They never solved that problem as it only effect low end computers. Servers has a lot more memory and faster drives to handle this phenomenon.
So if you start your terminal and monitor your disk activity when you reaches 99/100% memory and starts sudo iotop -d 2 -P then you will see how the swap I/O is on 99% usage even that your cpu is idle. This is what causes the system to freeze as disk I/O has maximum priority in the system.
If you temporary disable swap and your system reach 100% the system will not freeze up as the OOM killer will kick in and kill that program that is the cause. With swap enabled OOM killer will not kick in as the swap is consider as more usable memory.

To solve this problem the linux kernel developers just using the word... add more RAM as it is cheap.
Linux kernel is primary a server system and a server system does not use RAM in the same way as a desktop does.
The solution is to develop a special kernel for desktop use to handle memory and swap in another way that are more desktop friendly. and that will not happen as Linux desktop is just a little tiny niche of users and it's not worth the time to develop two different kernels.
if you want my attention...quote me so I get a notification
Nothing is impossible, the impossible just takes a little longer to solve..
It is like it is.. because you do as you do.. if you hadn't done it as you did.. it wouldn't have become as it is. ;)
Post Reply

Return to “Tutorials”