Skip to content

Consider actual RAM load for scheduling actions #26794

Open

Description

Description of the feature request:

To my knowledge, Bazel takes the available amount of RAM for granted, based on --local_ram_resources.
This is certainly not always accurate. Running actions might actually exceed their estimated RAM resources or the system might be stressed by non-bazel processes.

This PR already implements a solution to take the actual CPU load into consideration.

This feature request is about implementing something similar for RAM.

Which category does this issue belong to?

Performance

What underlying problem are you trying to solve with this feature?

Bazel scheduling works based on declarative, static assumptions about available system resources and how much resources an action consumes.

Taking actual system load into consideration would improve scheduling and reduce OOM issues.

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

Related: #17368 (comment)

Activity

  1. added
    untriaged
    on Aug 19, 2025
  2. jmmv commented on Aug 19, 2025

    @jmmv
    Contributor

    How do you prevent starvation? It seems like if Bazel is the only app in the system restricting its own consumption of resources (when no other app does this), Bazel is always going to lose, right?

  3. kirschem-fernride-legacy commented on Aug 19, 2025

    @kirschem-fernride-legacy
    Author

    @jmmv Good point. I would assume that Bazel is typically the main workload on any given build machine. Regarding the phrasing above

    Running actions might actually exceed their estimated RAM resources or the system might be stressed by non-bazel processes.

    I guess my main point is is former: Running actions might actually exceed their estimated RAM resources

  4. added
    team-Performance
    on Aug 19, 2025
  5. jmmv commented on Aug 20, 2025

    @jmmv
    Contributor

    I think a more "fair" way to go about this would be to say: --local_ram_resources specifies the maximum RAM Bazel can use (irrespective of other processes) and then make Bazel track the memory used by actions up to that limit. That way, you wouldn't have other apps starve Bazel, but at the same time you'd limit the concurrency of actions within Bazel in a more accurate way.

    The problem is... memory consumption by actions is pretty spiky. They can consume very little memory for a long time, then spike up, and then terminate. How do you handle these situations, without putting actual resource limits via containers? (I haven't yet read the patch to see how it works.)

  6. removed
    untriaged
    on Aug 26, 2025
  7. zhengwei143 commented on Aug 26, 2025

    @zhengwei143
    Contributor

    IIRC, and I'm simplifying, --experimental_cpu_load_scheduling uses a moving window to estimate CPU usage when a local action comes along, and then makes the decision on whether CPU resources are available.

    If you're looking to ensure that actions don't use more than they actually should, then you could try using --experimental_sandbox_limits and --experimental_sandbox_enforce_resources_regexp to sandbox the actions (assuming you're using linux). I don't think the former is necessarily hooked up to --local_ram_resources to restrict total usage though.

  8. kirschem-fernride-legacy commented on Aug 28, 2025

    @kirschem-fernride-legacy
    Author

    I was not aware of this flag, thanks for mentioning it @zhengwei143 ! I think this would pretty much solve the problem by enforcing developers to explicitly declare required resources.

    One other problem that comes to mind is how to prevent over-provisioning of resources. If a developer puts too little resource constraints, the test will timeout or run into OOM.
    But what prevents everybody from specifying dozens of CPUs and tons of memory?

  9. zhengwei143 commented on Aug 28, 2025

    @zhengwei143
    Contributor

    But what prevents everybody from specifying dozens of CPUs and tons of memory?

    That is out of our control, and is unfortunately, more a matter of policy that code maintainers will need to enforce.

    I would first try using --experimental_sandbox_limits to set a reasonable default limit for all and only encourage the use of --experimental_sandbox_enforce_resources_regexp where necessary.

  10. jimy-byerley commented on Mar 10, 2026

    @jimy-byerley

    Any news on this feature request ?

    I'm having a lot of problems with OOM due to header only libraries

  11. sluongng commented on Mar 18, 2026

    @sluongng
    Contributor

    Commented on a related issue here #10443 (comment)

    I think folks who are interested in this should pursue profile-guided scheduling if RBE is not an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    team-Performancetype: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions