alpine-lima icon indicating copy to clipboard operation
alpine-lima copied to clipboard

Feature request: Enable ZRAM swap in this image?

Open noobgramming opened this issue 3 years ago • 3 comments

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?

noobgramming avatar Jan 18 '22 21:01 noobgramming

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?

jandubois avatar Jan 18 '22 21:01 jandubois

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

noobgramming avatar Jan 18 '22 21:01 noobgramming

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/

afbjorklund avatar Jan 19 '22 07:01 afbjorklund