Advice for adding swap to container PVE on zfs

ntblade

Renowned Member
Apr 29, 2011
19
1
68
Hi all,
I'm experimenting with kasm and I want to install it on a container. I created a test container and added 1G swap but:
Bash:
alpine-privileged:~# free -h
              total        used        free      shared  buff/cache   available
Mem:          31.3G       27.2G        4.1G       50.1M      368.0K        4.0G
Swap:             0           0           0
I then read that zfs and swap can be troublesome so, I created a test pve ve with a 32Gi disk and reserved 4Gi at the end for swap:
Bash:
ls -lah /dev/disk/by-uuid/
swapon 8764af0b-6722-744e-8945-a971ddea1fe3
nano /etc/fstab 
free -h
               total        used        free      shared  buff/cache   available
Mem:           7.8Gi       1.3Gi       6.3Gi        46Mi       148Mi       6.3Gi
Swap:          4.0Gi          0B       4.0Gi
I the created another container in the pve vm and added 512M for swap but this time I get:
Bash:
kasm-test:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.8G        1.5G        6.3G       46.7M      624.0K      510.6M
Swap:          4.0G           0        4.0G
So, the conatainer seems to see all of the pve swap. I'm confused as to how I should allocate swap in lxc. Is the pve swap shared by the containers? Any help is much appreciated

Thanks

NTB
 
Hi,
LXC containers run in namespaces on the host kernel, so the host will be the one to manage swap. Use a VM if you want to isolate from the host kernel.
 
Hi,
LXC containers run in namespaces on the host kernel, so the host will be the one to manage swap. Use a VM if you want to isolate from the host kernel.
Thanks for the reply Chris. I don't really need the isolation as this is just an experiment for home use but what I don't understand is why I allocated 512M of swap but the container "sees" 4G. Also, I'm not too familiar with namespaces :confused:

Thanks
 
Thanks for the reply Chris. I don't really need the isolation as this is just an experiment for home use but what I don't understand is why I allocated 512M of swap but the container "sees" 4G. Also, I'm not too familiar with namespaces :confused:

Thanks
As stated, swap is managed by the host kernel (the PVE VM in your case). To allow the container to use swap from the host, you can adjust the memory settings as described here https://oxymoron.blochwave.org:8006/pve-docs/chapter-pct.html#pct_memory
 
Last edited:
When running something in a LXC you are running it on the PVE host, just in another namespace. So LXCs and PVE host share the kernel and the hardware. Thats why you see your hosts hardware utilization when running free -h inside the LXC, as both use the same hardware. Virtualized hardware, where free -h would show the utilization of the virtual hardware, you only get when using a VM.
 
When running something in a LXC you are running it on the PVE host, just in another namespace. So LXCs and PVE host share the kernel and the hardware. Thats why you see your hosts hardware utilization when running free -h inside the LXC, as both use the same hardware. Virtualized hardware, where free -h would show the utilization of the virtual hardware, you only get when using a VM.
Thanks. I did already know that I just didn't asscociate it with namespaces. Thanks for clarifying!
 

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!