Skip to content
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

Use Zygote process #775

Merged
merged 4 commits into from
Jan 21, 2025
Merged

Use Zygote process #775

merged 4 commits into from
Jan 21, 2025

Conversation

jprendes
Copy link
Collaborator

@jprendes jprendes commented Dec 19, 2024

This PR introduces a zygote process (a very small process cloned early on during shim startup), from which new containers are created. This effectively decouples the global state of the shim from the state of the container process.

Fixes #755 and #357

@jprendes jprendes force-pushed the zygote branch 2 times, most recently from 61cad63 to db471b3 Compare December 20, 2024 15:32
@jprendes jprendes force-pushed the zygote branch 2 times, most recently from a495cb8 to eff8a9d Compare December 27, 2024 22:24
@jprendes jprendes force-pushed the zygote branch 3 times, most recently from 75c928e to 1654ca5 Compare January 16, 2025 14:16
@jprendes
Copy link
Collaborator Author

This build on the changes from #774
For a diff without the changes in #774 see https://github.com/jprendes/runwasi/compare/remove-engine..zygote

The benchmark results show no change in performance w.r.t. the scheduled nightly runs:

@jprendes jprendes marked this pull request as ready for review January 16, 2025 14:49
Signed-off-by: Jorge Prendes <[email protected]>
Signed-off-by: Jorge Prendes <[email protected]>
Signed-off-by: Jorge Prendes <[email protected]>
}

let container = builder.as_init(&bundle).with_systemd(false).build()?;
let (root, state) = Zygote::global()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, nice interface to use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see the memory usage of this zygote process vs. the cloned shim process running containers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory usage as reported by VmPeak in /proc/xxx/status

Without zygote

Shim peak memory usage was: 3341772 kB

With zygote:

Shim peak memory usage was: 3342252 kB
Zygote peak memory usage was: 31056 kB

I am a bit surprised by the memory usage of the shim, I expected it to consume less memory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisiting the numbers, for wasmtime the shim peaks at ~19000 kB of resident memory with or without the zygote.
The zygote itself peaks at 5500kB of resident memory.

Signed-off-by: Jorge Prendes <[email protected]>
Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great work! Looking forward to seeing less sporadic CI failures 🚀

Do I understand correctly that the container creation would look like:

->shim 
     ->zygote (cloned from shim)
          -> container 1 (message sent from shim to zygote; cloned from zygote)
          -> container 2 (message sent from shim to zygote; cloned from zygote)

@jprendes
Copy link
Collaborator Author

Yes, that's correct.

We could still see issues if we ever "pollute" the zygote. We do create an engine inside the zygote before cloning the process, and if that has global state, starts threads, etc, it can be a problem.

Currently the engine struct for all our shims are very simple, so that's not an issue.

I'm thinking on addressing that as part of the split engine-precompiler.

@jprendes jprendes mentioned this pull request Jan 21, 2025
Copy link
Member

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Mossaka Mossaka merged commit afe5c9c into containerd:main Jan 21, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with handling signals in containers
4 participants