lima-vm / alpine-lima

Create an alpine based image for lima
Apache License 2.0
39 stars 26 forks source link

Feature request: Enable ZRAM swap in this image? #41

Open noobgramming opened 2 years ago

noobgramming commented 2 years ago

Hello! We run lots of Docker containers using Colima, which AFAIK uses this Alpine image.

Our machines struggle with free ram when running many containers, and its my understanding that ZRAM is zero overhead until kernel needs it to free up ram space.

If ZRAM isn't enabled by default, could we perhaps turn it on?

jandubois commented 2 years ago

It is my understanding that zram creates a compressed block device in RAM, so you could use it to host e.g. your /tmp directory or a swap partition. It is not clear to me how it would help with running lots of containers; can you please elaborate?

noobgramming commented 2 years ago

Yes, you can use ZRAM to create a compressed in-memory swap file. The advantage is Linux will start to compress RAM in low-memory scenarios, allowing you to run several times more containers on a machine. And compressed ram is only a few times slower than uncompressed RAM.

When system is not low on memory, the ZRAM swap file is empty so it doesn't use any RAM space. So there's really no disadvantage to using ZRAM swap, it only starts working when its needed. We use it to ward off the OOM killer, but it needs to be enabled in Docker VM to be effective for containers on MacOS.

The most frequent use of ZRAM swap is low memory devices like Raspberry Pi and low end Android phones (its enabled on all low-ram Android phones AFAIK). I think it would also help Docker users that run many containers as well, like me :)

If you want to play with it, this script will configure it on your machine https://github.com/foundObjects/zram-swap

afbjorklund commented 2 years ago

I think Fedora changed to use /dev/zram0, which caused Kubernetes to start failing (it doesn't "support" swap yet)

https://fedoraproject.org/wiki/Changes/SwapOnZRAM

There is a flag to kubelet and kubeadm to enable it, until k8s can handle managing nodes with swap enabled. No big deal.

https://kubernetes.io/blog/2021/08/09/run-nodes-with-swap-alpha/