Issue of memory for a container

You can use ZRAM swap, and disk swap also, that way when your Zram swap gets full it will swap to disk. ZRAM will also help against SSD wear. Not really a problem on a spinning disk, but those are also super slow and would bog down your Container if you are using too much swap.

I have a small fanless mini-pc that I have Proxmox running a router VM, and many LXC containers.

I have this command watch '( zramctl --output-all ; echo -e "\n\n" ; free -h ; echo -e "\n\n" ; swapon --show ; )' that will live update all the memory information on my Proxmox host. Here is a sample of the output:
Code:
 zramctl --output-all ; echo -e "\n\n" ; free -h ; echo -e "\n\n" ; swapon --show
NAME       DISKSIZE DATA  COMPR ALGORITHM STREAMS ZERO-PAGES  TOTAL MEM-LIMIT MEM-USED MIGRATED COMP-RATIO MOUNTPOINT
/dev/zram0     4.6G   3G 791.4M zstd                    4908 858.2M        0B   860.3M    12.1K     3.5291 [SWAP]



               total        used        free      shared  buff/cache   available
Mem:           7.7Gi       6.9Gi       357Mi       320Mi       1.2Gi       819Mi
Swap:           28Gi       3.2Gi        24Gi



NAME       TYPE       SIZE USED  PRIO
/dev/sdb4  partition 23.6G   0B    10
/dev/zram0 partition  4.6G 3.2G 32767
root@pve:~# uptime
 11:43:04 up 2 days,  8:35,  1 user,  load average: 2.99, 3.01, 2.78
root@pve:~# uname -a
Linux pve 6.18.0-1-jaminmc-tcp-pve #1 SMP PREEMPT_DYNAMIC PMX 6.18.0-1 (2026-01-14T16:25Z) x86_64 GNU/Linux
Using the zstd compression, I get good ram compression, and Even with a Debian 13 LXC with an Xfce desktop connected with xrdp, I have the LXC with 2048 ram, and 2048 swap. Using Brave in it, playing youtube, and a 5 other tabs open, Let alone 2 pihole servers, an Omada Controller, and a podman LXC running some docker apps, and I am still not hitting my disk swap. Eventually it does hit the disk swap, but I rebooted 2 days ago when I installed my 6.18 test kernel.
 
  • Like
Reactions: Johannes S
I searched but I don't find a HowTo for Zswap on Proxmox.

Try to look into the wiki: https://pve.proxmox.com/wiki/Zram ;-)

Edit: that page seems to over-complicating things. For me the single command apt install zram-tools was sufficient. That gave me:

Code:
~# zramctl
NAME       ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4          23.5G   4K   64B   20K         [SWAP]

Of course it uses the default settings from /etc/default/zramswap which is probably NOT what you want. The above "23.5G" is for a system with 48 GiB Ram because of these defaults:
Code:
~# grep -B 3 PERCENT /etc/default/zramswap
# Specifies the amount of RAM that should be used for zram
# based on a percentage the total amount of available memory
# This takes precedence and overrides SIZE below
PERCENT=50

Make sure to edit that file to fit your needs :-)
 
Last edited:
Try to look into the wiki: https://pve.proxmox.com/wiki/Zram ;-)
This isn't about zswap though, zswap and zram (although they serve a related but not completely identical usecase) are actually quite different things as explained in the references from Impact.

The most relevant difference is that zswap actually needs a physical swap device or swapfile while zram doesn't. Whether this is a good thing or not depends on your usecases. For example inside a VM normally I don't want to have pysical swap except for some cornercases but still want to have zram to save on memory and to allow the kernel to have a swap device for it's memory management ( see https://chrisdown.name/2018/01/02/in-defence-of-swap.html ). I also wouldn't use it on my Proxmox Host since I don't want to have a own partition or decice just for swap and swap on zfs volumes is problematic (see https://pve.proxmox.com/pve-docs/chapter-sysadmin.html#zfs_swap ) But on a notebook or a LVM backed ProxmoxVe host the story might be quite different. For example you always need physical swap to use hibernate under Linux. So then it might be worth to use zswap to have something of both.
 
  • Like
Reactions: UdoB
Thanks all.
I will test zswap now, in some week.
Zram was not succesfull for me (some instabilities, and they disappear after unstallation of zram). And I saw this : https://forum.proxmox.com/threads/how-to-configure-zram-on-zfs.151747/
That is why I move swap on a ssd disk

And sure I will not use Zswap and Zram together as it requests very strict tuning

And I find (https://medium.com/@kriswwhite/adva...pressed-swap-with-zswap-and-zram-bc18a0f7a451)

Configuring Zswap Parameters (Optional)

You can adjust additional zswap parameters as needed:

  • zswap.max_pool_percent: Maximum percentage of RAM that zswap can use.
  • zswap.compressor: Compression algorithm (e.g., lz4, zstd).
  • zswap.zpool: Memory allocator (e.g., zbud, z3fold). Note : z3fold seems to be better
To configure these, add the desired parameters to the kernel command line:

Code:
zswap.enabled=1 zswap.max_pool_percent=20 zswap.compressor=lz4 zswap.zpool=z3fold

BR
 
Last edited:
  • Like
Reactions: UdoB