Zswap is a Linux kernel feature providing a compressed write-back cache for swapped pages. Instead of moving memory pages to a swap device when they are to be swapped out, zswap performs their compression and then stores them into a memory pool dynamically allocated inside system's RAM.
ZSWAP has been merged into the 3.11 mainline linux kernel, but is not turned on by default.
Benefits
ZSWAP will make very efficient use of swap. It will minimizes Disk I/O by both reducing the number of writes and reads required (data is compressed and held in RAM) and by reducing the bandwidth of these I/O operations as the data is in a compressed form. Thus you will not face sudden slowdowns when your system runs out of memory and tries to read/write the swap drive.
For whom it wont work
Who does not have a SWAP partition
People with less than 1ghz CPU speed
People who uses ZRAM
For whom this tweak will work
People who have a dedicated SWAP partition / SWAP file
People with low system memory
Steps to enable ZSWAP
Check if your OS Kernel comes with ZSWAP by running the command below.
If the response is CONFIG_ZSWAP=y, you are OK to proceed.
cat /boot/config-`uname -r` | grep -i zswap
Open grub as admin
gksu pluma /etc/default/grub
Change the line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" to
Iâve used zswap before. Itâs nice for what it is, but I hardly ever use my swap space.
There was only one time on the system I am typing this from right now where swap was used. It was when my system load average was super-high, and my CPU was being hammered when I ran our of RAM and my PC was taking a massive poop all over itself.
@tiox, I envy you. My current machine has only 4 gigs or ram. And I need to keep an instance of postgresql, rails puma server, chromium with developer tools, atom / vs code / sublime text, 2nd browser with api documentations open most of the time. Thatâs when my system starts writing on the swap file, and simple alt-tab takes 2-3 seconds. After adding zswap, my problem has mostly disappeared.
But, I get your point, I shouldâve mentioned âPeople with low system memoryâ on the post.
Well, I donât do much with my Linux system beyond keeping it around for a âPlan Bâ and also using it when I donât want to touch anyoneâs Windows system.
So yeah, general-purpose things. Nothing that would tax my systemâs memory too heavily. But for users with low system memory, or even or users with sufficient system memory every little bit of performance counts. ZSwap probably works better with more memory because there is more swap for it to write to whenever itâs necessary.
Doesnât take a genius to know more is better. But also, as a cost-effective solution for users with little memory to begin with (until they upgrade and max board capacity), itâll work. Also probably nice for embedded system manufacturers because they can (in theory) put ZSwap into the thing and with a little more space taken up on embedded storage they can stretch the memory further.
Not to mention, SFF embedded systems are a boon these days with M.2 and U.2 being easy means to add interchangeable storage, and systems only getting smaller all the time.
[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.
Terminal:
cat /sys/module/zswap/parameters/enabled
Y = Enabled
N = Disabled
For example, in my case:
dmesg | grep -i zswap
Output:
[ 2.846273] zswap: loaded using pool lzo/zbud
But:
cat /sys/module/zswap/parameters/enabled
Output:
N
And no, I do not need it enabled. Just demonstrating that it can be loaded without being enabled.
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
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.
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:
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.