[TUTORIAL] Using a zram disk as compressed swap device on Proxmox-VE

Chris

Proxmox Staff Member
Staff member
Jan 2, 2019
2,251
310
128
Hello PVE users,
for those of you who are interested in creating and using a zram based compressed swap disk, there is a now a short step by step guide on how to set this up in Proxmox VE. Here is the link: https://pve.proxmox.com/wiki/Zram

Regards,
Chris
 
  • Like
Reactions: borekon and fireon
And I think that zram could be used as a slog device for zfs!
I would not use volatile storage (zram is in ram after all) as device which is meant to keep synced writes save in case of powerloss?
 
Yes, but in may use cases is OK. Any server in a DC have UPS so the risk is very low. But IOPS on zram is very good!
I guess it'd be easier to set sync to disabled in that case... - you have the roughly same risk - in case of powerloss application which rely on synced writes (databases,...) will be confused/corrupt and your pool probably will not be importable anymore
 
in case of powerloss application which rely on synced writes (databases,...) will be confused/corrupt

No corruption for db. Any db will be able to replay transactions from their transaction log.

and your pool probably will not be importable anymore

No, zfs do not work like this. zfs write anything in transactions. The data who is in slog it is also in ARC. When let say power is lost, you will lose what is in ARC
and what is in slog and was not flushed to disks. So no partial write will be done in zfs => after power is ok, the pool is in a consistent state.

The slog is used only to tell to the application that data is committed to disk (a faster disk). But slog data is never flushed to the disk , because is already in ARC who will put the data to disks.

Slog is used ONLY if power is lost and are some data are not commited to the disk. This process is started after the pool is online.

I can say that I have used this scenario with zfs(slog in ram), no UPS and mysql for 2 years. Power lost was at least one in a week, but after boot mysql was able to detect errors and to self repair.
 
Strange. What is the difference to https://apt.iteas.at
Code:
apt install zram-confg
systemctl start zram-config.service
Look likes it is the same.
Code:
NAME       ALGORITHM DISKSIZE  DATA  COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo             2G  8,6M   889K  3,2M       4 [SWAP]
/dev/zram1 lzo             2G  8,9M 967,3K  3,1M       4 [SWAP]
/dev/zram2 lzo             2G  9,2M     1M  3,2M       4 [SWAP]
/dev/zram3 lzo             2G  9,3M     1M    3M       4 [SWAP]
 
  • Like
Reactions: dcsapak
Strange. What is the difference to https://apt.iteas.at
Code:
apt install zram-confg
systemctl start zram-config.service
Look likes it is the same.
Code:
NAME       ALGORITHM DISKSIZE  DATA  COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lzo             2G  8,6M   889K  3,2M       4 [SWAP]
/dev/zram1 lzo             2G  8,9M 967,3K  3,1M       4 [SWAP]
/dev/zram2 lzo             2G  9,2M     1M  3,2M       4 [SWAP]
/dev/zram3 lzo             2G  9,3M     1M    3M       4 [SWAP]
Hi fireon,
I am aware of this package, it does in principle the same thing just without you having to configure all that much ;). There will be a zram-tools package in Debian 10. By default it creates as many zram disks as there are cores, which I think is a relict from the fact that zram didn't support multiple stream in the beginning. This is now different and by default there are created as many streams as cores, so 1 zram disk is enough as far as I understand.
 
Is there any benefit to doing this on a high ram (128GB+) system?
zram creates compressed ram disks, so you trade RAM for CPU usage. In general, if you have a lot of RAM and never have to swap, you will gain nothing from a zram swap device. But there might be other use cases where a compressed RAM disk might be interesting (temp files, caching, ...)
 
  • Like
Reactions: fireon
zram creates compressed ram disks, so you trade RAM for CPU usage.

and save storage I/Os in the process. Any fast compression is multiple factors faster than a single disk I/O.

In general, if you have a lot of RAM and never have to swap, you will gain nothing from a zram swap device.

But will you loose something by using it? I don't think so. Using just the ubuntu or buster package above, you don't even have to configure anything, just install and enjoy. It has been in our preseed installations for years now.
 
  • Like
Reactions: fireon and Chris

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!