Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
0
answers
30
views
Why does zswap decompress memory pages before writing them on disk?
I was wondering why zswap decompresses memory pages before writing them to disk instead of keeping them compressed, since apparently doing that increases both CPU load and I/O.
I was wondering why zswap decompresses memory pages before writing them to disk instead of keeping them compressed, since apparently doing that increases both CPU load and I/O.
Scrooge McDuck
(1102 rep)
Mar 26, 2025, 11:03 PM
• Last activity: Mar 26, 2025, 11:16 PM
1
votes
0
answers
351
views
Accurately monitoring RAM and swap usage while running zswap compression
I'm running zswap on 6.2.0-39-generic (Ubuntu 22.04, HWE). My understanding is that zswap intercepts pages marked for swap, compresses them (if possible) and stores them in a compressed section of the physical RAM up to a certain, user-specific point. In my case, zswap is set to use a maximum of 25%...
I'm running zswap on 6.2.0-39-generic (Ubuntu 22.04, HWE).
My understanding is that zswap intercepts pages marked for swap, compresses them (if possible) and stores them in a compressed section of the physical RAM up to a certain, user-specific point. In my case, zswap is set to use a maximum of 25% of the RAM.
However, if I stress my system (which has 256GB of RAM and a 256GB /swapfile):
stress --vm-bytes 250G --vm-keep -m 1
When viewed through the activity monitor, or free -h etc., firstly my RAM fills and then my "swap" begins to fills - way more than would be necessary to store 250GB.
free -h
reports:
total used free shared buff/cache available
Mem: 251Gi 249Gi 1.9Gi 35Mi 523Mi 598Mi
Swap: 255Gi 128Gi 127Gi
However sudo grep -R . /sys/kernel/debug/zswap/ reports:
sudo grep -R . /sys/kernel/debug/zswap/
/sys/kernel/debug/zswap/same_filled_pages:10982
/sys/kernel/debug/zswap/stored_pages:33556168
/sys/kernel/debug/zswap/pool_total_size:45804953600
/sys/kernel/debug/zswap/duplicate_entry:0
/sys/kernel/debug/zswap/written_back_pages:0
/sys/kernel/debug/zswap/reject_compress_poor:0
/sys/kernel/debug/zswap/reject_kmemcache_fail:0
/sys/kernel/debug/zswap/reject_alloc_fail:0
/sys/kernel/debug/zswap/reject_reclaim_fail:0
/sys/kernel/debug/zswap/pool_limit_hit:0
33556168*4096 = ~128GB - which matches swap usage reported by free -h.
So, is the system reporting the uncompressed file size as 'swap' still despite it being compressed by zswap and still on the RAM?
Basically, how can I get an intuitive and reportable sense of:
1. Total physical RAM used (uncompressed)
2. Total physical RAM used (compressed via zswap)
3. Total swap-on-disk used
4. Total swap-on-disk remaining/free to use
Also posted here: https://www.reddit.com/r/kernel/comments/18iykle/accurately_monitoring_ram_and_swap_usage_while/
user3012926
(11 rep)
Dec 15, 2023, 01:33 PM
1
votes
2
answers
2122
views
Effect of enabling zswap on zram without any disk swap
I have set up a system that has 4 GB RAM with 1.5 GiB of zram. It also has zswap enabled. I don't have any swap partition on the secondary storage. As I have noticed, the performance is good on my systems. Is the zswap being used on zram? Can using zswap on zram lead to any performance issues?
I have set up a system that has 4 GB RAM with 1.5 GiB of zram. It also has zswap enabled. I don't have any swap partition on the secondary storage.
As I have noticed, the performance is good on my systems.
Is the zswap being used on zram? Can using zswap on zram lead to any performance issues?
15 Volts
(2149 rep)
Nov 29, 2019, 07:11 AM
• Last activity: May 21, 2023, 02:35 AM
27
votes
2
answers
12355
views
Get current zswap memory usage and statistics
The [zswap documentation](https://www.kernel.org/doc/Documentation/vm/zswap.txt) says: > Zswap seeks to be simple in its policies. Sysfs attributes allow for one user controlled policy: * max_pool_percent - The maximum percentage of memory that the compressed pool can occupy. This specifies the *max...
The [zswap documentation](https://www.kernel.org/doc/Documentation/vm/zswap.txt) says:
> Zswap seeks to be simple in its policies. Sysfs attributes allow for one user
controlled policy:
* max_pool_percent - The maximum percentage of memory that the compressed
pool can occupy.
This specifies the *maximum* percentage of memory the compressed pool can occupy.
How do I find out:
* The *current* percentage of memory occupied by the compressed pool
* How much of this pool is in use
* Compression ratios, hit rates, and other useful info
Tom Hale
(32892 rep)
Nov 25, 2017, 08:12 AM
• Last activity: Oct 11, 2022, 05:41 AM
1
votes
1
answers
996
views
Which process (kernel thread) is doing the actual compression for zswap?
I can imagine actually two locations: 1. In the kernel space belonging to the process whose ram is being swapped in/out 2. From `[kswapd0]` However, digging into the kswapd source (`mm/vmscan.c`, `init/main.c`), I could find: kswapd is single-threaded, and is started on a single thread. (Except on N...
I can imagine actually two locations:
1. In the kernel space belonging to the process whose ram is being swapped in/out
2. From
[kswapd0]
However, digging into the kswapd source (mm/vmscan.c
, init/main.c
), I could find: kswapd is single-threaded, and is started on a single thread. (Except on NUMA systems, where all the memory regions have a different kswapd. But most ordinary PCs are not NUMA systems.)
However, from now we have a problem. We can assume, that the disk is far slower than the memory, this is why we don't need a multi-threaded kswapd to handle the disk I/O. But not this is the case if we need to utilize also the internal zswap layer. Particularly from stronger compression rates (deflate), cpu can, and likely will be a bottleneck.
But kswapd is single-threaded.
Is it true?
Is being any multi-threaded kswapd planned? Is it really needed?
----
P.s. I found this thread on the linux kernel mailing list. It is about a rejected patch suggestion, what could have enabled multi-threaded kswapd on non-NUMA systems. They are talking about everything, except this zswap problem. Maybe it is unrelated.
P.s.2. Context:
1. I have a highly ram-overcommitted Linux system (processes are using far more ram than physically is available).
2. The count of the simultanously running processes is far lower than the CPU cores.
3. I am using intensively zswap.
4. In this environment, it would highly useful to use *all the available CPU cores for compress/decompress memory pages*. My current best estimation is that the page compression/decompression is being done by [kswapd0]
, which is a single kernel thread. I am investigating the options to utilize all the CPU cores for compression/decompression. Essentially, it would be a way to transform the left-over CPU capacity to compensate the lack of the physical memory.
peterh
(10448 rep)
Apr 2, 2019, 04:18 PM
• Last activity: Oct 17, 2020, 12:57 PM
0
votes
1
answers
1306
views
CentOS 7 can Zswap be used? How to monitor Zswap? Is this a good idea?
Does CentOS 7 support Zswap? If so, how do I enable it and how to test to see if its working? Is this a good idea for a CentOS server? Enable attempt: chmod 777 /sys/module/zswap/parameters/enabled;echo 1 > /sys/module/zswap/parameters/enabled; echo 40 > /sys/module/zswap/parameters/max_pool_percent...
Does CentOS 7 support Zswap? If so, how do I enable it and how to test to see if its working? Is this a good idea for a CentOS server?
Enable attempt:
chmod 777 /sys/module/zswap/parameters/enabled;echo 1 > /sys/module/zswap/parameters/enabled; echo 40 > /sys/module/zswap/parameters/max_pool_percent
Tests I've tried to see if zswap is enabled and working:
grep -R . /sys/kernel/debug/zswap/
Returns:
grep: /sys/kernel/debug/zswap/: No such file or directory
Below returns nothing:
dmesg | grep -i zswap
Parameters do exist:
grep -R . /sys/module/zswap/parameters
Returns:
/sys/module/zswap/parameters/zpool:zbud
/sys/module/zswap/parameters/max_pool_percent:40
/sys/module/zswap/parameters/enabled:Y
/sys/module/zswap/parameters/compressor:lzo
Can pcp-pmda-zswap be used to monitor swap?
My best guess is.. CentOS doesn't officially support zswap, as it should be loaded in dmesg... but I may be wrong.
Jeff Luyet
(309 rep)
Dec 20, 2019, 10:18 PM
• Last activity: Feb 20, 2020, 11:30 PM
5
votes
1
answers
1722
views
Compress swap pages written to disk
[This answer](https://unix.stackexchange.com/a/192155/143394) says that zswap decompresses pages before writing them to non-RAM swap. Is there any way to compress the pages written to disk, ideally with lz4? I hope to: * Reduce SSD write wear * Reduce swap disk allocation * Speed up swap IO (hopeful...
[This answer](https://unix.stackexchange.com/a/192155/143394) says that zswap decompresses pages before writing them to non-RAM swap.
Is there any way to compress the pages written to disk, ideally with lz4?
I hope to:
* Reduce SSD write wear
* Reduce swap disk allocation
* Speed up swap IO (hopefully fewer blocks are written/read to/from disk)
Tom Hale
(32892 rep)
Nov 25, 2017, 07:34 AM
• Last activity: May 24, 2019, 11:59 AM
9
votes
1
answers
5293
views
Prevent zram LRU inversion with zswap and max_pool_percent = 100
The major disadvantage of using zram is [LRU inversion](https://together.jolla.com/question/75162/replacing-zram-with-zswap/): > older pages get into the higher-priority zram and quickly fill it, while newer pages are swapped in and out of the slower [...] swap The [zswap documentation](https://www....
The major disadvantage of using zram is [LRU inversion](https://together.jolla.com/question/75162/replacing-zram-with-zswap/) :
> older pages get into the higher-priority zram and quickly fill it, while newer pages are swapped in and out of the slower [...] swap
The [zswap documentation](https://www.kernel.org/doc/Documentation/vm/zswap.txt) says that zswap does not suffer from this:
> Zswap receives pages for compression through the Frontswap API and is able to
evict pages from its own compressed pool on an LRU basis and write them back to
the backing swap device in the case that the compressed pool is full.
Could I have all the benefits of zram and a completely compressed RAM by setting
max_pool_percent
to 100
?
> Zswap seeks to be simple in its policies. Sysfs attributes allow for one user
controlled policy:
* max_pool_percent - The maximum percentage of memory that the compressed
pool can occupy.
No default max_pool_percent
is specified here, but the [Arch Wiki page](https://wiki.archlinux.org/index.php/Zswap#Customize_the_maximum_allowed_size) says that it is 20
.
Apart from the performance implications of decompressing, is there any danger / downside in setting max_pool_percent
to 100
?
Would it operate like using an improved swap-backed zram?
Tom Hale
(32892 rep)
Nov 25, 2017, 06:37 AM
• Last activity: Feb 19, 2019, 05:48 PM
1
votes
1
answers
485
views
When is zswap used?
I would like to reduce the wear of my SSD. I'm trying to understand the mechanics of zswap: Is zswap only used after the uncompresed swap is full? If no, what is the allocation policy?
I would like to reduce the wear of my SSD.
I'm trying to understand the mechanics of zswap:
Is zswap only used after the uncompresed swap is full?
If no, what is the allocation policy?
Tom Hale
(32892 rep)
Nov 25, 2017, 06:48 AM
• Last activity: Nov 26, 2017, 04:45 AM
Showing page 1 of 9 total questions