You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider actual RAM load for scheduling actions #26794
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?
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?
kirschem-fernride-legacy commented on Aug 19, 2025
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.)
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.
kirschem-fernride-legacy commented on Aug 28, 2025
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?
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.
Activity
jmmv commentedon Aug 19, 2025
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?
kirschem-fernride-legacy commentedon Aug 19, 2025
@jmmv Good point. I would assume that Bazel is typically the main workload on any given build machine. Regarding the phrasing above
I guess my main point is is former: Running actions might actually exceed their estimated RAM resources
jmmv commentedon Aug 20, 2025
I think a more "fair" way to go about this would be to say:
--local_ram_resourcesspecifies 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.)
zhengwei143 commentedon Aug 26, 2025
IIRC, and I'm simplifying,
--experimental_cpu_load_schedulinguses 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_limitsand--experimental_sandbox_enforce_resources_regexpto sandbox the actions (assuming you're using linux). I don't think the former is necessarily hooked up to--local_ram_resourcesto restrict total usage though.kirschem-fernride-legacy commentedon Aug 28, 2025
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?
zhengwei143 commentedon Aug 28, 2025
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_limitsto set a reasonable default limit for all and only encourage the use of--experimental_sandbox_enforce_resources_regexpwhere necessary.jimy-byerley commentedon Mar 10, 2026
Any news on this feature request ?
I'm having a lot of problems with OOM due to header only libraries
sluongng commentedon Mar 18, 2026
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.