Zorin OS zswap performance improvement

I have been daily driving Zorin OS over two months, here is my laptop specs:

OS: Zorin OS 16.2 x86_64
Kernel: 5.15.0-67-generic
CPU: Intel i5-8250U (8) @ 3.400GHz
GPU: Intel UHD Graphics 620
Memory: 8GiB
Disk: 256GB NVMe

At first I was pleasantly impressed by the speed and performance of the OS, then I notice that the system starts getting slow and glichy over time. After troubleshooting and testing, I saw that the swap partition gets fulled up pretty quickly from daily use, mainly heavy web browsing, when that happens, the CPU spikes and the system start struggling finding spare memory.

The swap space is on nvme m.2 drive, I don't notice performance issue when the system use the swap space, but when that space fills up, then I notice the performance degradation.

So, I started optimizing the OS, removing unwanted apps, disabling unnecessary services at startup (specially gnome-software). I added another 2 Gb swap file (default swap partition size on Zorin OS is 1Gb), adjusted the system swapiness and cache pressure, but the problem persisted, even the extra 2Gb swap file get filled up quickly and system start getting slow over time, especially because I don't restart my laptop that much(that wont change).

I believe this issue is more prevalent on laptop sub 8 Gb RAM, I started to looking into zram and zswap. To over simplify, zram takes a portion of ram and tuned into swap space with compression 2:1, zswap is kinda similar (ratio 3:1) but spill over into a swap disk space when the ram portion gets filled up.

I tested fedora kde spin which has zram by default, the portion of swap ram gets filled up quickly since there is swap content that don't compress well. The same issue happens with zram as well, the system gets slow and unresponsive over time.

I setup zswap on Zorin OS, zswap is part of the Linux kernel by default, I was greatly impressed by the improvement in performance and the stability of the system. I tested opening 80+ tabs (dynamic websites) on brave browser and opening a couple of tabs on firefox at same time, apart from a spike in CPU (not even the CPU fan ran), system stayed stable and responsive.

I also notice the swap disk space don't fill up as much, just a small spill over over from RAM compressed swap to disk swap space.

Overall, I highly recommend activating zswap for improving system performance, specially for laptop with a limited RAM size.

Since Zorin OS strive on reviving old laptops (mine 4 years old) and provide excellent user experience, this should be at least an option on the OS installation wizard or adjusting the default swap partition size according to RAM size. (Windows OS default 8Gb RAM ≈ 8Gb page file size).

P.S. I linked to relevant articles and tutorials through out the post.

2 Likes

I believe you have this backwards. Swap files/partitions use the disk drive to store RAM items that are older to make room in RAM for other applications.

In an SSD you see no performance hit because they are as fast as RAM. If you want to save writes to your SSD, you would increase the amount of RAM your system has.

Having a high swappiness will utilize your SSD more, but will increase your performance because more RAM will be available to the application needing it.

1 Like

Ah, my confusion was what the percentage represented. I was under the impression it referred to the amount of RAM used, but rather it represents the amount of free RAM. My mistake.

1 Like

Solid State Drives don't need a swap file period. There is danger of degradation of the drive using swap.

3 Likes

After reading all the above, I must agree. SWAP is more for older machines for redefining purposes.

1 Like

There is more to the swapiness value then the over simplification that @hjv mentioned, which is overall correct in a sense were the lower the swapiness value the less the kernel will be prone to use the swap space.

There is this great article explaining in detail this topic which quote:

The most common incorrect description of swappiness is that it sets a threshold for RAM usage, and when the amount of used RAM hits that threshold, swapping starts.

@hjv @Unrealkaz9999
For laptops with 8 GBs of RAM or lower they will run out of virtual memory period. When that happens, the system becomes slow and unresponsive which makes a horrible user experience.

Also in a low virtual memory situation without a swap space the kernel is contently committing page files from RAM to the disk dus increasing disk IOs.

zswap compress 3:1 the swap space into a portion of RAM, that reduce the use for disk swap space greatly, but still needed for page files that don't compress very well.

zswap will in fact reduce SSD degradation, since the kernel will keep more page files into the zswap space instead of getting them of the SSD dus reducing disk IOs.

The best way to know if your system needs a swap space is adding a swap file (2 GBs for example) adjusting swapiness to 10 and check if that space fills up over time, if it does you might want to setup zswap.
If the swap don't get used up, disable that swap space and delete the file.
I linked to the relevant tutorials to accomplish this on my original post.

Please, read more on this topic before going to misleading conclusions.

We'll just leave the conversation about Swap/etc memory. for now.

To help with your situation, it is best to get software that preform "Benchmark" test's.

Q: how old is the machine?
Q: Has the machine ever been serviced?
Q: Is you BIOS/UEFI firmware upto date?

I see you leave your machine on, do you often wake the machine from sleep or do you not use sleep/hybination?

First please show results of

sudo dmidecode | less

Also

free -m

Also the output of

cat /proc/sys/vm/swappiness

Also can you tell us the Brand/Model or Motherboard you have.?

My mistake, I thought I posted in the Tutorials & guides section of the forum. Maybe a mod can move this thread to that section.

My original post was about my experience setting up zswap and its positive impact on system performance.

I should have posted more technical writing showing how to setup zswap on Zorin OS instead of linking to tutorials on external websites. I can edit the post if that would make more suited for Tutorials & guides section. @337harvey

Anyways, thank you for your help offer.

Yes was moved, i assume for several reasons,
From my point of view ( remember these posts maybe see all over the internet) your insinuating that Zorin needs Zswap to fix your issue, when this is not correct, for your situation i see that your just putting a "Bandage" to help with an underlying issue/s

Please if you wish to create a topic in Tutorial's Explaining Zswap, Please do so, it would be appreciated .:+1:

Hence The Topic was moved to try & help you fix the underlying issue. :+1:

If you wish for help,Please provide the above detail's .
Thank you.

I would even suggest the Topic Title be changed to something like:
"Laptop (Model) slowing down & freezing"
Just a thought. :slight_smile:

I was using linux on a 4GB virtual machine on Windows OS all time, and I had plenty memory to for web browsing and side desktop applications, even web browsing inside the linux virtual machine and using linux applications.
The Pagefile size on Windows was 8 GB, for comparaison, a swap usage on a Mac OS.

Switching to Zorin OS, the default swap partition is 1 GB, that is extremely low for an 8 GBs RAM laptop, which makes for a unpleasant user experience.

Even adding more swap space that was not enough, that space fills up over time and system start being slow and unresponsive looking to free up memory.

I troubleshooted this issue a lot for the last couple of weeks, whenever the swap space is nearing to be full, the system start acting slow and CPU fan start running. Emptying the swap space sudo swapoff -a && swapon -a and the system returns to be stable for a while.

zswap fixed this issue in two ways, faster access to swap space since it's located in RAM which makes the system very responsive and a larger swap space makes the system more stable since it's not contently looking to free up memory.

The only thing I find odd, is the used swap space don't usually return to 0 even if I closed all applications.

On average, I am opening 30+ tabs on brave browser, plus a couple low CPU low memory desktop applications.

I have a Lenovo ThinkPad T480s 4 years old as I mentioned, latest BIOS/Firmware 2023 (updated with Zorin OS), never serviced. never put my laptop to sleep/hibernation (I don't think that's an option on Zorin OS), I don't suspend my laptop either.

free -h
              total        used        free      shared  buff/cache   available
Mem:          7.5Gi       5.0Gi       161Mi       908Mi       2.4Gi       1.4Gi
Swap:         3.0Gi       1.4Gi       1.6Gi
cat /proc/sys/vm/swappiness
10

I have stress tested my setup with zswap opening +80 tabs on brave plus multiple CPU and RAM demanding desktop applications. it went quite well.

Now, I am really curious to know what makes you think that zswap fix is a ''Bandage" and what's your theory/ies on what would be the the underlying issue/s?

Thanks for your feedback, I am also always learning and testing to see what works the best.
I have found through multiple testing and troubleshooting is that reducing swapiness value, makes the system more prone to low virtual memory situation (oom). If you think about it you are telling the kernel to swap less i.e. not taking page files out of RAM into swap space.

In the past, swapiness would reduce performance if you using an old hard drive or a sata SSD. zswap takes a portion of the RAM to store the swap space with compression and extra swap space on disk for non compressible page files.

This is enhances the system stability by avoiding oom situation and better performance since faster access to page files stored in RAM swap space.

That worked out very well in my situation and I wanted share my findings with the Zorin OS community :v:

You really hit the nail on the head in this post and I cannot express agreement strongly enough. This has been a thorn in my paw for a long time...

2 Likes

Gday @anongo ,
I believe it's a bandage to an underlying issue,
Firstly Zorin has a default of 2Gb of SWAP, SO you only having 1Gb after install , sends me a "Red Flag".

Eg:
Bad Download or installation device/methods, faulty boot device,
Firmware needs updating,
Does the machine need a service ( clean/etc).
Even faulty hardware. will cause strange things to happen, as per you 1Gb after install.

In brief

  • Zswap creates a file to DRAM ( Not to hard device)
    It is very similar to RAM Drive, the difference is Zswap can compress files & i believe for memory it can remove badly addressed RAM.

  • Zswap/RAM-drive can be an advantage more so with high end machines/built for gaming with large DRAM

  • As Zswap uses your DRAM as it's SWAP file, This can become an issue with low spec machine's ( low DRAM/CPU cores/etc)

  • The best result would be a physical RAM Drive with battery backup. (depends on the ability to upgrade Hardware)

  • I could feather explain but i feel we're getting off the issue of finding the issue/s.

Ok.
The issue of excessive RAM/CPU, ( slowing down )
Can also be a hardware/software/Configuration/Updates/etc

Please make sure you have your machine Backed-Up. ( as this may need a reinstall )

  1. What program did you create the bootable device with?
  2. What Device did you use? usb/sd/external drive/etc?
  3. Did you checksum the download of the Zorin OS?
  4. How old in the machine ( has it been cleaned recently)?
    Just a few things to start the ball rolling
    Thank you.

I am not sure what are you talking about? If it's normal swap then yes, reducing swapiness value to 10 or 5 makes sense on laptops with large enough RAM (depending on workload as well) the kernel would be less prone to use the swap space dus reducing IOs to the swap disk.

For zswap , I am not sure if you have tested or read about it, this is a quote from kernel.org

Some potential benefits:

  • Desktop/laptop users with limited RAM capacities can mitigate the performance impact of swapping.
  • Overcommitted guests that share a common I/O resource can dramatically reduce their swap I/O pressure, avoiding heavy handed I/O throttling by the hypervisor. This allows more work to get done with less impact to the guest workload and guests sharing the I/O subsystem
  • Users with SSDs as swap devices can extend the life of the device by drastically reducing life-shortening writes.

If you have your zswap-backing swap partition on a SSD, you'll want your swappiness value to be low regardless... you don't want to cause bit-burnout of the SSD by writing to it too much. It is not recommended to have your swap partition (or swap file) on a SSD.

If you have your zswap-backing swap partition on a fast spinning-rust drive (and most especially on a drive array or SLOG-backed ZFS setup), you'll want your swappiness value to be high... in this case you can push it all the way up to 200... it'll consider the I/O cost of swapping to be lower than the I/O cost of filesystem paging, so when you've hit your highwater mark for memory usage which triggers swapping or paging, it'll preferentially swap rather than page... and since your zswap is compressed and held in memory (until it fills up, then it's LRU-swapped to a drive), that keeps your system speed high and can significantly increase the perceived amount of memory the system has available to use.

https://forum.zorin.com/t/swap-swappiness-explained/26535/2

It should be noted that those running ZFS (Zettabyte File System) don't need to use zswap... the ZFS ARC (Adaptive Replacement Cache) is compressed and held in memory just as zswap is. That's why I can run with as little as 1.2 GB of memory used (if I turn off my ARC preload code, which preloads files to the ARC so accessing them later is faster).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.