Skip to content

Support percentage-based --max-old-space-size option for dynamic memory allocation #57447

@Asaf-Federman

Description

@Asaf-Federman

What is the problem this feature will solve?

Currently, --max-old-space-size requires a fixed memory value in MB. However, in containerized environments (Docker, Kubernetes, etc.), available memory can vary. A percentage-based option would allow Node.js to dynamically adjust its memory usage based on the environment, reducing the risk of OOMKills while optimizing performance.

Why is this needed?

  • Improves compatibility with containerized environments like Kubernetes, where memory limits are dynamic.
  • Prevents over-allocating memory and OOMKills when limits change.
  • Simplifies memory management without requiring external scripts to calculate heap size dynamically.

What is the feature you are proposing to solve the problem?

Introduce a new syntax for --max-old-space-size, allowing it to accept percentages of total system memory (e.g., --max-old-space-size=80%).

For example:
node --max-old-space-size=80% app.js

If the system has 4GB RAM, this would set 3.2GB (80%) as the old space size.
If the system has 1GB RAM, it would set 800MB (80%).

What alternatives have you considered?

  • Users must manually set a fixed value.
  • Some use external scripts (os.totalmem()) to compute the size dynamically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions