-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable setting cgroup v2 mode in std edition #114
Conversation
By specifying the LIMA_ALPINE_CGROUP_MODE environment variable at machine startup, the mode of cgroup is changed according to the specified value. The default is `hybrid`. Signed-off-by: Ueda Naoaki <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to make the cgroup mode configurable, but would make some changes to your PR.
@@ -24,6 +24,7 @@ ${DOCKER} run --rm \ | |||
-v "${PWD}/cri-dockerd-${CRI_DOCKERD_VERSION}-${ARCH}.LICENSE:/home/build/cri-dockerd.license:ro" \ | |||
-v "${PWD}/sshd.pam:/home/build/sshd.pam:ro" \ | |||
$(env | grep ^LIMA_ | xargs -n 1 printf -- '-e %s ') \ | |||
-e "LIMA_INSTALL_CGROUP_CONF=${LIMA_INSTALL_CGROUP_CONF}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed; the line above is exporting all LIMA_*
environment variables into the container automatically. The 3 variables below are exceptions because they are renaming variables that don't start with LIMA_*
on the host.
@@ -10,3 +10,5 @@ LIMA_INSTALL_LOGROTATE=true | |||
LIMA_INSTALL_OPENSSH_SFTP_SERVER=true | |||
LIMA_INSTALL_SSHFS=true | |||
LIMA_INSTALL_TINI=true | |||
|
|||
LIMA_INSTALL_CGROUP_CONF=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of 2 variables (LIMA_INSTALL_CGROUP_CONF
and LIMA_ALPINE_CGROUP_MODE
) I would prefer to have just a single variable LIMA_CGROUP_MODE
that is set to the mode value, e.g.
LIMA_INSTALL_CGROUP_CONF=true | |
LIMA_CGROUP_MODE=hybrid |
But given that this is the default, this setting should not be made in edition/std
at all. Instead there should be a line in edition/min
that just documents that the variable exists:
export LIMA_CGROUP_MODE=
Note that I removed the ALPINE_
substring from the variable name; it feels redundant to me, as every setting in this repo is about building an Alpine image.
if [ "${LIMA_INSTALL_CGROUP_CONF}" == "true" ]; then | ||
mkdir -p "${tmp}/etc/conf.d" | ||
echo 'rc_cgroup_mode=${LIMA_ALPINE_CGROUP_MODE:-hybrid}' >> ${tmp}/etc/conf.d/cgroups | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ "${LIMA_INSTALL_CGROUP_CONF}" == "true" ]; then | |
mkdir -p "${tmp}/etc/conf.d" | |
echo 'rc_cgroup_mode=${LIMA_ALPINE_CGROUP_MODE:-hybrid}' >> ${tmp}/etc/conf.d/cgroups | |
fi | |
if [ -n "${LIMA_CGROUP_MODE}" ]; then | |
mkdir -p "${tmp}/etc/conf.d" | |
echo 'rc_cgroup_mode=${LIMA_CGROUP_MODE}' >> ${tmp}/etc/conf.d/cgroups | |
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review and suggestion. I apologize for my insufficient explanation.
In this PR, the intention is not to specify the cgroup mode at the time of the Alpine image build, but rather to make it possible to set the cgroup mode at the time of lima boot. Specifically, I intended to start the lima machine as rc_cgroup_mode=unified
when the lima template is set as follows:
env:
LIMA_ALPINE_CGROUP_MODE: unified
In other words, this PR creates a file /etc/conf.d/cgroups
with the content:
rc_cgroup_mode=${LIMA_ALPINE_CGROUP_MODE:-hybrid}
So that at the time of lima machine startup:
- If the
LIMA_ALPINE_CGROUP_MODE
environment variable is NOT set in the lima template, cgroup will be (default value) hybrid - If the
LIMA_ALPINE_CGROUP_MODE
environment variable is set in the lima template, cgroup will be set to that value.
With the above, at machine startup, cgroups can be selected using environment variables in a lima template, eliminating the need to prepare separate Alpine images for each cgroup mode.
(I included the string ALPINE_
because it becomes an option at lima startup, but I think it's actually redundant as you said...)
Based on the above intentions, would you say the modification is appropriate? Or is the modification policy inappropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have uploaded the images, which can be used to test the above behavior, at the following location:
https://github.com/na0x2c6/alpine-lima/releases/tag/v0.2.32-std-cgroup-experimental
I apologize for requesting a re-review without making any modifications. I commented because I failed to adequately explain the intent of the modifications. I would appreciate it if you could check it. |
Sorry, this PR somehow dropped from my radar. But looking at it again, don't you get the same effect from: provision:
- mode: system
script: |
echo rc_cgroup_mode=unified >/etc/conf.d/cgroups
rc-service cgroups restart In which case this PR wouldn't be needed. Or am I missing something again? |
Thank you for your reply. The scripts defined in the lima template are applied after mounting the cgroup here, so the cgroup v1 will be mounted on the first boot. Once it is mounted, it is not easy to unmount it because some processes are started with cgroup v1: $ ls /sys/fs/cgroup/*/*/tasks
/sys/fs/cgroup/openrc/acpid/tasks /sys/fs/cgroup/openrc/lima-guestagent/tasks /sys/fs/cgroup/openrc/sshd/tasks
# show PIDs in cgroup v1
$ cat /sys/fs/cgroup/*/*/tasks
2418
2594
2596
2602
...
In other words, once cgroup v1 is mounted, ( lima-vm/lima#1878 is a question about whether there is a way to bypass the above problem. ) Actually, I wanted to use cgroup v2 because I am using rootless podman. Also, I have been using the alpine template because I couldn't start Fedora with the So, to be honest, there is currently not much motivation to use cgroup v2 in the alpine image. If this PR seems helpful for future purposes, I would be happy to make the necessary modifications. However, if there is no specific reason to incorporate it, I would like to close it. I am grateful for the development of this excellent image. Thank you for taking the time to review. |
Thank you for your contribution, but I don't want to apply this PR (anymore). Alpine 3.19 defaults to using cgroup v2. It is possible to revert back to v1 by editing I believe this is good enough. Please let me know if you disagree! |
Well, actually, that was a bit hasty: In Rancher Desktop we switch back to We select the cgroup mode with an environment variable in env:
RC_CGROUP_MODE: hybrid And use this provisioning script to switch, when necessary: https://github.com/rancher-sandbox/rancher-desktop/blob/62807cbc4cff6c1099b966b6496f9770e050cb93/pkg/rancher-desktop/assets/lima-config.yaml#L41-L53 |
I understand. I don't think it's a problem at all either. Thank you for confirming my issue/PR. |
Hello.
I previously mentioned briefly about enabling cgroup v2 in the Alpine image at lima-vm/lima#1878. I have made modifications to allow changing the mode through environment variables during machine startup.
The default mode is hybrid mode, so I believe it does not affect the existing functionality. I would appreciate it if you could consider incorporating this modification if possible.
This modification was made with reference to the comment I received at lima-vm/lima#1878 (reply in thread). Thank you!
The pre-built image can be found at the following location:
https://github.com/na0x2c6/alpine-lima/releases/tag/v0.2.32-std-cgroup-experimental
The lima template that is currently being used is available here.
Thanks.