Forum › Forums › New users › New Users and General Questions › Using zswap instead of zram
- This topic has 19 replies, 6 voices, and was last updated May 22-9:51 pm by banned.
-
AuthorPosts
-
January 19, 2018 at 12:26 pm #5516Member
mroot
I found an alternative to zram you can use if you have a swap partition available. It has some advantages. I used to think zram and zswap were mainly for low ram computers but I recently ran into a situation where I needed 6 gigs of ram and 6 gigs of swap. This led me to rethink having zram and zswap enabled even when you have quite a bit of memory. You might find the links below helpful.
A comparison of zswap and zram
Arch distro documentation on zswap
-mroot
January 20, 2018 at 12:43 am #5528Memberandfree
::From A guide to enabling zswap:
For whom it wont work
…
People with less than 1ghz CPU speedSo, it’s OK about this CPU?
Single core Mobile Intel Celeron (-UP-)
arch: Netburst Willamette rev.7 cache: 256 KB
flags: (pae sse sse2) bmips: 3189 speed: 1594 MHz (max)I decided to test it.
$ cat /boot/config-‘uname -r‘ | grep -i zswap CONFIG_ZSWAP=y[ATTENTION! The correct form of the command above contains backticks (`) and not single quotes (‘), but I couldn’t copy-paste the correct form here, because it causes a BBCodes confusion.]
$ gksu pluma /etc/default/grubNothing done. I opened grub as admin with this command:
$ sudo geany /etc/default/grubThe default line is not
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
The default line is
GRUB_CMDLINE_LINUX_DEFAULT=”vga=791 quiet”
So, should I change it like this or not?
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash zswap.enabled=1 zswap.compressor=lz4″
- This reply was modified 5 years, 3 months ago by andfree.
- This reply was modified 5 years, 3 months ago by andfree.
- This reply was modified 5 years, 3 months ago by andfree.
January 20, 2018 at 1:55 am #5536Moderator
caprea
::The cpu should be O.K.
antix has no splash
So put the new parameters after the parameters that already existGRUB_CMDLINE_LINUX_DEFAULT=”vga=791 quiet zswap.enabled=1 zswap.compressor=lz4”January 20, 2018 at 2:22 am #5538Memberandfree
::put the new parameters after the parameters that already exist
GRUB_CMDLINE_LINUX_DEFAULT=”vga=791 quiet zswap.enabled=1 zswap.compressor=lz4”
Thanks. I suppose everything went well.
$ cat /sys/module/zswap/parameters/enabled Y$ dmesg | grep -i zswap [ 0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.10.5-antix.1-486-smp root=UUID=7e2b02e5-fc0d-4fe0-b642-0c02b4b5eea2 ro vga=791 quiet zswap.enabled=1 zswap.compressor=lz4 [ 1.903473] zswap: loaded using pool lz4/zbudI can’t say yet if it’s better than zram.
- This reply was modified 5 years, 3 months ago by andfree.
- This reply was modified 5 years, 3 months ago by andfree.
- This reply was modified 5 years, 3 months ago by andfree.
January 20, 2018 at 2:40 am #5540Moderator
caprea
::Here it lookes like this
helga@antix1:~ $ cat /sys/module/zswap/parameters/enabled Y helga@antix1:~ $ dmesg | grep -i zswap [ 0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.14.12-antix.1-amd64-smp root=UUID=476b1ae8-b679-4cdb-9091-eaf837f63695 ro quiet zswap.enabled=1 zswap.compressor=lz4 [ 0.725878] zswap: loaded using pool lz4/zbudDont wonder about my Kernel command line.I cant use the vga=791 parameter with the 4.14.12-kenel on this laptop.
Did you update-grub and afterwards
sudo su echo lz4 >> /etc/initramfs-tools/modules echo lz4_compress >> /etc/initramfs-tools/modules update-initramfs -uI think somethings missing
- This reply was modified 5 years, 3 months ago by caprea.
January 20, 2018 at 2:54 am #5541Memberandfree
::Did you update-grub and afterwards (…) I think somethings missing
I did, but it seems I missed something in copy-paste. I correct my previous post. Thank you.
January 20, 2018 at 9:57 am #5557Member
mroot
::The author of
A guide to enabling zswap
used pluma as an editor. Pluma isn’t installed on AntiX. Most people would be better off using geany for an editor as shown in this thread or perhaps nano. I hope this helps people trying to use pluma and find it isn’t installed and wonder why the command doesn’t work.
-mroot
- This reply was modified 5 years, 3 months ago by mroot.
June 13, 2020 at 11:06 pm #37434Member
rayluo
::FYI for those who happen to be using antiX liveUSB and not (yet?) use root persistence:
You do NOT need to follow step 2, 3 & 4 in the guide to enable zswap, therefore you do not need to bother with “pluma” or risk messing up with your grub (gasp!).
You can simply type that step 3 content “zswap.enabled=1 zswap.compressor=lz4” at the boot screen as your boot option, and then zswap will be enabled for the current boot session. You can then play with it. If you end up not like it, simply reboot and then everything will go back to normal, without needing to revert those settings.
Note: Actually, the “zswap.compressor=lz4” part won’t make a difference in a non-persisted live USB session, because you won’t be able to do step 5 in the guideline beforehand, unless you use root persistence. The default compression uses LZO, which is slower than LZ4, but presumably still OK.
My current system:
[sudo] password for demo: [ 0.000000] Kernel command line: vga=791 tz=America/Los_Angeles quiet zswap.enabled=1 zswap.compressor=lz4 [ 1.088586] zswap: compressor lz4 not available, using default lzo [ 1.088782] zswap: loaded using pool lzo/zbudJune 15, 2020 at 7:07 pm #37520Member
mroot
::A comparison of lz4 and lzo speeds
lz4 is much much faster in decompression and also quite a bit faster in compression
compression ratio for both is about 2.1
So for a 2 gig ram system if you set the zswap allocation of ram to 50% you essentially end up with a 3 gig ram system although the zswap portion will run at slower speeds due to the time requirements for compression and decompression. It also appears to be dynamic in the sense zswap used ram starts at zero and grows to the allocation limit as needed. In other words if your using 2 gig or less no zswap is used and all the ram is “regular” and has normal speed.
June 15, 2020 at 9:01 pm #37528Member
rayluo
::A comparison of lz4 and lzo speeds
lz4 is much much faster in decompression and also quite a bit faster in compression
compression ratio for both is about 2.1
Thanks very much for this detailed info about LZ4 vs LZO! Good to know!
That being said, I did not feel slow experience during my first full day with zswap via LZO, even when comparing to the previous no-swap experience. And, those quantified result “LZO decompression speed 860 MB/s (less than LZ4’s 4970 MB/s)” might partially explain it: you see, my 2 gig ram computer allocates only a small portion (default is 20%) to be used as zswap. So, each time something needs to be decompressed from zswap, it is likely <860 MB anyway, and it would take less than 1 second.
So for a 2 gig ram system if you set the zswap allocation of ram to 50% you essentially end up with a 3 gig ram system although the zswap portion will run at slower speeds due to the time requirements for compression and decompression.
Do you have a source on this one? It sounds too good to be true. Say, set zswap allocation to 100% and end up with 4 gig ram. 🙂
I would assume normal ram and zswap “pool” are not interchangeable, so a 2 gig ram system with 1 gig allocated to zswap might end up with only 1 gig ram performed as normal ram. But again, that’s my hypothesis only.
It also appears to be dynamic in the sense zswap used ram starts at zero and grows to the allocation limit as needed. In other words if your using 2 gig or less no zswap is used and all the ram is “regular” and has normal speed.
Good to know. I did not notice that in your 3rd document. It also mentions a “zswap.zpool=z3fold” thing which sounds also significant.
By the way, do you know whether there is a way to monitor how well a zswap performs? All the normal “free”, “htop”, etc. do not seem to be aware of the zswap existence.
June 16, 2020 at 8:29 am #37536Member
mroot
::Yes the setting of the zswap allocation to 100% is too good to be true. You have to remember that compressed ram is slower and it also results in increased cpu load since every compression/decompression operation is done by the cpu. I think zswap works best when you have a fast cpu and little ram since the trade off is going to be worthwhile since cpu performance loss is not critical in this case. It also would work well with a slow cpu that has many cores which is typical of servers and that seems to be what zswap was designed for in the first place.
As far as applications- it should be good for servers or web surfing but I would imagine it would be a poor choice for gaming since cpu load is constant and pretty high. I am not sure how the system “sees” normal ram and compressed ram but it appears to me that the system sees compressed ram as regular ram that is”slow”.
Having said this you could set the allocation to 100% and then heavily load the system and see how it works. Loading a 100 tabs in firefox for example might be a good way to test it.
As for monitoring zswap the only reference I have seen is that debugfs can be used to get information about the size of the storage pool and how much is stored in it as well as other stats. I am not familar with debugfs so I really can’t help you there. I don’t know of anything like htop that can monitor zswap either but it might exist. debugfs is mentioned at the bottom of the page in the link below.
https://www.kernel.org/doc/html/latest/vm/zswap.html
I have never worked with z3fold and I don’t know what tradeoffs that might involve. I am hesitant to make changes like that if I don’t know what the trade offs are. I think if you don’t understand the trade offs you are better off staying with default settings since the person who set the defaults should have a better ability to pick good values. I have changed compression to lz4 since it’s faster. I have also altered the allocation percentage but that is it as far as modifications I have done.
You also might consider posting the output of
inxi -Fxzto this thread or the other thread you started as it is easier for people to help you if they have an idea of what you system is since how good the advice they give is system dependent.Of course, the other approach to improve performance is to take a hardware approach. We don’t talk about it much on this forum because we like to keep hardware for a long time (in my case sometimes way way too long lol). But if you can add ram you should consider doing so. Prices for a small ssd have dropped considerably and also would be a good option especially since your having a thrashing problem. I broke down and bought one myself to extend the usable life of my system. Sequential read/writes are greater than 500 Mb/s so you do really notice the difference during boot and when opening a large application. Remember though all hardware has a finite useful life and at some point you will need to replace it with newer hardware. Sometimes it is better to buy newer hardware even though we would like to avoid doing so.
- This reply was modified 2 years, 10 months ago by mroot.
June 16, 2020 at 4:47 pm #37547Member
rayluo
::Yes the setting of the zswap allocation to 100% is too good to be true. You have to remember that compressed ram is slower and it also results in increased cpu load
I mean to say, it is probably not even about zswap is slower and consumes cpu. I suspect that, ram and zswap are different in probably the same way that ram and normal swap are different, and again it is not about speed. Specifically, in a system with 2 gig ram, and 20% of them (i.e. 0.4 gig) are used as zswap, the OS might consider there is only 1.6 gig ram available, and start swapping out pages when the memory consumption is approaching the 1.6 gig threshold. If I understand correctly, zswap is a cache to swap, thus somewhat transparent to OS. The OS does NOT see and operate as if it has 2.4 gig ram. So, setting the zswap allocation to 100% might end up badly (I may still try it though). All that being said, I found no proof to my hypothesis. The output of
freestill shows not 1.6 gig, not 2.4 gig, but still 2 gig ram in my computer.Thanks VERY MUCH for this! It contains much more official information! I learn from it that we can change those parameters at run-time! Theoretically, it would become much easier to experiment, although I would have to learn that debugfs thing first.
PS: I’ll keep this thread generic to zswap. And I’ll follow up with my specific performance topic in the other thread.
June 16, 2020 at 5:50 pm #37549Member
mroot
::Your welcome. Let us know how you experiments go with zswap settings. I have never seen free with zswap show anything but the regular amount of memory- 2 gigs in your case. I don’t think any of the normal things we use to measure memory show the effect of zswap which is unfortunate because I would like to evaluate how well zswap is working.
Here is an analysis of the performance impact of using zswap- it’s a bit technical but you may find it useful.
June 16, 2020 at 7:31 pm #37551Moderator
Brian Masinick
::One other point to highlight:
The reason why we have so many different file systems, memory and disk management types is that each of them are effective for different, specific purposes.
Some are not the best at anything but provide a good compromise and an alternative.
Others make excellent use of the best available resources.
The use cases vary
What’s great is that the choices are available in abundance!
The cost is to either learn what is
best for your system or to experiment with different operating systems and Distribution alternatives.I’ve been doing it for a long time and it brought me to antiX. It works for me very well!
I occasionally try various approaches but the default distro is excellent as is (for me).
--
Brian MasinickJune 17, 2020 at 1:19 pm #37591Member
mroot
::I found two documents made by Seth Jennings- the guy who came up with zswap.
The first is a slideshow he made. In it he explains how it works and has graphs showing the performance benefits.
https://events.static.linuxfound.org/sites/events/files/slides/tmc_sjennings_linuxcon2013.pdf
The second is a youtube video of Jennings presenting the slideshow at a conference. It has more detail and he explains terms in the slideshow. It also helps to better understand the link about performance that I included in my previous email.
https://www.youtube.com/watch?v=jYLzokeRtd0
Raylou- I looked at your
inxi -Fxzoutput from the other thread. It looks like your swap partition is only 256Mb in size. I think you would want to enlarge it if possible for two reasons.First your swap partition is small compared to amount of ram you have. Generally, it’s recommended for a laptop to have a swap partition that is least a bit bigger than the amount of ram you have (2 gigs) so you can use the hibernation function. Generally, larger is better. I think a swap partition in the 2.2 to 4 gigs range is perfectly reasonable if you have space on the hard drive or you can make some space by shrinking another partition.
The second and more important reason is discussed by Jennings in his presentation. Since zswap is a cache it has to be able to address a corresponding address in the swap device. In other words each Mb of cache needs a Mb of swap space it can address and then write to if/when needed. If it doesn’t have that swap space then the zswap cache stops growing and may never reach the allocation limit you set (the default is 20%). So in your case zswap will use 256 Mb of ram instead of growing to 20% of the 2 gigs of ram in your system which is specified by the allocation limit. It also means enlarging the allocation limit will have no effect since the size of the swap partition sets a much lower hard limit.
-
AuthorPosts
- You must be logged in to reply to this topic.