Enable ZSwap to increase performance

here is my result (a bit different )

[ 3.324142] zswap: loaded using pool lz4/zbud

I don’t know if its activated. BTW thanks

Yes it’s activated.
You’re welcomed.

1 Like

Step 5 is unnecessary (it is unrelated).

Thank you for point it out. I’m updating the post.

It seems I can't edit my post. Can the moderators please help?

Hi @SSalekin. I think it hit a time limit I can’t control but was able to edit. Let me know if I goofed anything.:slight_smile:

[quote=“SSalekin, post:8, topic:11302, full:true”]Yes it’s activated. You’re welcomed.[/quote]Actually, not necessarily. That line just says it has been loaded. But, basically, zswap is always loaded. Whether or not it is actually enabled is a different story.


cat /sys/module/zswap/parameters/enabled

Y = Enabled
N = Disabled

For example, in my case:

dmesg | grep -i zswap


[ 2.846273] zswap: loaded using pool lzo/zbud


cat /sys/module/zswap/parameters/enabled



And no, I do not need it enabled. Just demonstrating that it can be loaded without being enabled. :wink:

I’m glad you’ve pointed that out. My English is to blame here. When I said Yes it's activated, I meant LZ4, not ZSWAP. But I see it’s misleading. I will update my post mentioning it. Thank you so much :grinning:

Thank you :slight_smile:

I still can’t see the edit option myself. So, can you please replace step 7 of the post with these lines please? Thank you.

7. Check if ZSWAP is enabled by running (Mentioned by @1Q7FE6zp)

cat /sys/module/zswap/parameters/enabled

If ZSWAP is enabled, you should see Y in return.

To check if LZ4 compressor is being used run

dmesg | grep -i zswap

Check the last line of the response. If the result says

[ 0.715381] zswap: loaded using pool lz4/zbud

Then voila ! You’ve successfully enabled ZSWAP.


My answer was somewhat wrong and misleading,

[ 3.324142] zswap: loaded using pool lz4/zbud

This line means that zswap is using LZ4 successfully, but doesn’t make sure zswap itself is activated. (pointed out by @1Q7FE6zp)

Please see this to check if zswap is running.

Again, I apologise for the misleading answer.

At one time, all tips were supposed to be a Wiki so I made it that way for editing. How about now? I ran into an unfortunate formatting of number lists with the attempt.

Thank you. I can see the edit button now. Also, thanks for updating the post.

I executed the commands in the post above, but after reboot and checking the zram enable (commend=cat /sys/module/zswap/parameters/enabled), it gave me (output=N)

I executed the following commands and got the outputs as below:

  1. cat /boot/config-uname -r | grep -i zswap
    output =CONFIG_ZSWAP=y

  2. gksu pluma /etc/default/grub <<====
    gave me an empty file. I did not find GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

  3. add GRUB_CMDLINE_LINUX_DEFAULT=“quiet splash zswap.enabled=1 zswap.compressor=lz4”
    this works OK

  4. sudo update-grub
    output =command 'update-grub' not found

  5. Enable lz4 (for very fast compression/decompression)
    this works OK

  6. sudo reboot

Note: I'm using ubuntu-mate 18.04 in raspberry pi3 B+

Hi. Could you add to the thread "how to disable or uninstall ZSwap", please? I've installed it and I feel no difference. I could say that, maybe, the system behave is worse than before... Just turning down the part:

is enough?

Well, and updating GRUB:

Update Grub by running

sudo update-grub

And restarting, yeah?

But thank you for the theme. Is good to know that this exists.

You would basically reverse the steps you did to install it. Turing it off would be as simple as undoing the changes you made in GRUB and removing the lines you appended onto /etc/initramfs-tools/modules. Once you reboot, then uninstall ZSwap and it's done.

1 Like

Yeeeeh! You're right! I forgot to do the thing about the modules. Thank you. Now is ok.

About the performance, yeah I never noticed a difference either, and it in fact made my system perform worse. I am sure in the correct scenario the opposite would be true, but in my particular use case this isn't doing.

I suspect, because I can't be certain, that this solution was doing "something". I think it was achieving a more relaxed system, but I'm not sure. Now, I have changed strategy :smile: I have installed LxQt instead Mate and modified swappines to 25, instead 60.

So far, the system is a bit more fast, but I'm just starting. I have to try more things, more times. We will see...

Is there a way to customize how big in gigs the zram will be?

Yes, look into file /usr/bin/init-zram-swapping (you can search it with listing the package files using dpkg -L zram-config) , this is the script that creates the zram swap devices. In this file there's this line:

mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))

The part that you can tweak is / 2 . So by default it takes total amount of memory and divides it by 2 and takes that as the total reserved for Zram .

So if you want to make Zram use all the memory just remove that part.
There's this answer on StackExchange that one should set this to 150% of total memory , so * 3 / 2 and then also set vm.swappiness=200 in /etc/sysctl.conf :

Though my experience is that the default value suits me well.
I've also set my disk swap to the same priority 5 that Zram has it set by default, so in /etc/fstab I have pri=5 in the disk/ssd swap device arguments . That way the resource consumption is a bit more balanced between CPU load due to Zram and SSD throughput due to disk swap.