View previous topic :: View next topic |
Author |
Message |
kgdrenefort Guru
Joined: 19 Sep 2023 Posts: 315 Location: Somewhere in the 77
|
Posted: Mon Jan 13, 2025 12:03 pm Post subject: Questions about ZRAM, ZSwap |
|
|
Hello,
Today I tried to setup some ZRAM into my main system.
I followed this page: https://wiki.gentoo.org/wiki/Zram
And did actually this step: https://wiki.gentoo.org/wiki/Zram#Using_systemd_zramctl
Which on my system, this was made:
Code: |
Mephistopheles ~ # modprobe zram
Mephistopheles ~ # zramctl /dev/zram0 --size 4G --algorithm lz4
Mephistopheles ~ # swapoff -a
Mephistopheles ~ # mkswap /dev/zram0
Configure l'espace d'échange (swap) en version 1, taille = 4 GiB (4294963200 octets)
pas d'étiquette, UUID=8b1bddbb-8c9a-4adb-80eb-0d3e2528cc88
Mephistopheles ~ # swapon /dev/zram0
|
Previously, I was using a swapfile (/swapfile) of 16GiB, which was as seen disabled (for now) for this process.
Now, I have effectively a 4GiB swap space:
Code: |
meself@Mephistopheles ~ $ LC_ALL=C free -m
total used free shared buff/cache available
Mem: 15905 12687 2612 3976 4910 3217
Swap: 4095 4095 0
|
First question, is the value showed below normal ?
I tried to check if it was effectively used as intented, as showed on the Zram wiki page:
Code: |
$ grep zram /proc/swaps
/dev/zram0 partition 4194300 3391232 -2
|
First, I wonder why the last value is -2, while on the wiki it shows 16383, which seems to represent in the example 16GiB of swap. Here, I should not have something like 4096 ?
I'm a bit perplexe, since I see a swap space in /dev/zram0 as set earlier (see my example above).
I guess something is not understood by me.
---
Second question, isn't this zram actually zswap ?
As explained on the ZSwap page on the wiki: https://wiki.gentoo.org/wiki/Zswap
Quote: | Next to zswap there is something related called zram. Zram can also be used to create a swap device for compressed pages in memory. |
I'm in big doubt, because I followed the ZRam page and ended up with new swap space, as it seems compressed into my RAM.
Could you help me understand this, please ?
Regards,
GASPARD DE RENEFORT Kévin _________________ Traduction wiki, pour praticiper.
Custom logos/biz card/website. |
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3865 Location: Rasi, Finland
|
Posted: Mon Jan 13, 2025 1:28 pm Post subject: |
|
|
Zswap tries to compress memory pages to aviod them being swapped. Zswap requires swap to function.
Zram is, like you have observed, a method of creating a virtual (compressed) storage device, that always* resides in RAM.
That's their difference.
* you can specify a backing device for zram device, so that its contents can (automatically, dynamically) be moved into non-virtual device.
As for the priority: You can pass --priority/-p for swapon command to adjust the priority of said swap device. _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1386 Location: Richmond Hill, Canada
|
Posted: Mon Jan 13, 2025 2:08 pm Post subject: |
|
|
zswap, Kernel Zswap wrote: | Zswap is a lightweight compressed cache for swap pages. It takes pages that are in the process of being swapped out and attempts to compress them into a dynamically allocated RAM-based memory pool. zswap basically trades CPU cycles for potentially reduced swap I/O. This trade-off can also result in a significant performance improvement if reads from the compressed cache are faster than reads from a swap device |
zram, Kernel zram wrote: | The zram module creates RAM-based block devices named /dev/zram<id> (<id> = 0, 1, ...). Pages written to these disks are compressed and stored in memory itself. These disks allow very fast I/O and compression provides good amounts of memory savings. Some of the use cases include /tmp storage, use as swap disks, various caches under /var and maybe many more |
So as you can see, zswap is cache for swap. Pages that need to store in swap could store in zswap first and would be retrieved faster when needed.
zram is just a disk use your computer ram, you can make a swap on top of that disk (ram disk) or you can make a filesystem on the disk and mount for /var/tmp for example.
I use both. I use zram from multiple nodes over NBD then pool them together with LVM and finially make a filesystem on the entire pool and mount it on /var/tmp for my stage4 build process.
I setup zswap for each nodes that is distcc helper in participle in above setup so I can confident that compiler jobs will not run out of memory. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|