Skip to content

fix(pool): vm pools to respect cgroupsv2 memory limit - #10721

Merged
hi-ogawa merged 1 commit into
vitest-dev:mainfrom
milas:milas/cgroups-memlimit
Jul 15, 2026
Merged

hi-ogawa merged 1 commit into
vitest-dev:mainfrom
milas:milas/cgroups-memlimit

Conversation

@milas

@milas milas commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

When determining memory based on a percentage of the total available, use the constrained memory value if present to avoid OOM in scenarios where the process has been restricted to less memory than the host physically has.

For example, if running tests in a Kubernetes pod, the container resource requets/limits are used to configure the cgroupsv2 namespace. Exceeding this will result in being OOM killed.

Vitest might see that it's scheduled on a node with 128GiB of RAM even though the container itself has been limited to 4GiB.

It will then allow each worker to have 1/N * 128Gi instead of 1/N * 4Gi of memory.
This can quickly result in an OOM situation, requiring manually setting the vmMemoryLimit and maxWorkers in the conf.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
    • ⬆️ Adding tests is unfortunately not straightforward here, requires mocking process stuff. I'm happy to give it a shot if given guidance on preferred approach from a maintainer.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.
    • ⬆️ I don't think this warrants a change in the current docs, but I'm happy to clarify that it does respect cgroupsv2 now if desired.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
    • ⬆️ I marked this as feat but feel free to retitle as fix if desired!

@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e9386f6
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a4bff27fa5bf100082a3fa7
😎 Deploy Preview https://deploy-preview-10721--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

When determining memory based on a percentage of the total available,
use the constrained memory value if present to avoid OOM in scenarios
where the process has been restricted to less memory than the host
physically has.
@milas
milas force-pushed the milas/cgroups-memlimit branch from e9386f6 to ec36219 Compare July 6, 2026 19:31
@AriPerkkio AriPerkkio changed the title feat: respect cgroupsv2 memory limit for percentage calculations fix(pool): vm pools to respect cgroupsv2 memory limit Jul 15, 2026

@AriPerkkio AriPerkkio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. @hi-ogawa are you familiar with process.constrainedMemory?

@AriPerkkio
AriPerkkio requested a review from hi-ogawa July 15, 2026 07:52

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't know the API but it makes sense to me. Just skimmed doc https://nodejs.org/api/process.html#processconstrainedmemory

@hi-ogawa
hi-ogawa merged commit 3923cab into vitest-dev:main Jul 15, 2026
26 of 27 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo