-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix(cli): configure v8 isolate with cgroups-constrained memory limit #29078
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
base: main
Are you sure you want to change the base?
fix(cli): configure v8 isolate with cgroups-constrained memory limit #29078
Conversation
This change configures V8 isolates to respect memory limits imposed by cgroups on Linux. It adds support for detecting both cgroups v1 and v2 memory limits, enabling Deno to properly adapt to containerized environments with memory constraints. When cgroups information is unavailable or not applicable, it falls back to using the system's total memory as before.
8ed9d12
to
895d941
Compare
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.
Pull Request Overview
This PR configures V8 isolates to honor memory limits imposed by cgroups on Linux by detecting cgroup v1 and v2 configurations. Key changes include:
- Adding a new Linux-specific logic branch in create_isolate_create_params to use cgroup memory limits.
- Introducing a helper module with functions to parse /proc/self/cgroup and determine the correct memory limit.
- Including tests to validate the cgroup parsing function for both v1 and v2 (and hybrid mode).
Co-authored-by: Copilot <[email protected]> Signed-off-by: Yusuke Tanaka <[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.
generally seems good, I am curious though if there's some crate for parsing the cgroups instead of manually implementing it.
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.
Is there any impact on startup perf? Can we this be feature flagged at compile/runtime instead?
That's a good point, it won't be used in 99% cases - maybe enable it only via env var |
Looks like this crate https://docs.rs/cgroups-rs/0.3.4/cgroups_rs/index.html provides what we want. I'll replace the manual implementation with it.
OK, let's do that |
This change configures V8 isolates to respect memory limits imposed by cgroups on Linux.
It adds support for detecting both cgroups v1 and v2 memory limits, enabling Deno to properly adapt to containerized environments with memory constraints. When cgroups information is unavailable or not applicable, it falls back to using the system's total memory as before.
Closes #29077
Test
For testing, I created a ubuntu VM with 1Gi memory. Within this VM, set up a cgroup with 512Mi memory limit, then ran the following script to see how much heap size limit the V8 isolate had.
Ubuntu 20.04
In this version of ubuntu, hybrid mode is enabled by default.
Create a new cgroup with 512Mi memory limit and run the above script in this cgroup:
This indicates that the isolate was informed of cgroup-constrained memory limit (512Mi) and hence got ~270M heap limit.
Ubuntu 22.04
In this version of ubuntu, cgroup v2 is used.
Run the above script using
systemd-run
:Again the isolate got ~270M heap limit properly.
Note that it should have had bigger heap limit if the entire system memory, i.e. 1Gi, had been passed to V8. In fact, if we run the same script outside the cgroup, it does display larger
heap_size_limit
like below: