Skip to content

Conversation

@israbbani
Copy link
Contributor

@israbbani israbbani commented Sep 3, 2025

This is the first PR introduces the CgroupManagerInterface. This will be used by the Raylet to manage the cgroup hierarchy. The implementation will be completed in subsequent PRs.

This PR stacks on #55063.

For more details about the resource isolation project see #54703.

The cgroup hierarchy for Ray will be:

    base_cgroup_path (e.g. /sys/fs/cgroup)
            |
    ray_node_<node_id>
      |           |
    system     application

The current implementation will only support

  • the cpu and memory controllers
  • cpu.weights and memory.min constraints.

I've signposted design decisions with comments in the code. Here's a summary:

  • CgroupManager::Create is a factory function. It is required because it can return a Status before creating an instance of CgroupManager if cgroupv2 is not setup correctly.
  • CgroupManager takes ownership of a CgroupDriverInterface for dependency injection.
  • CgroupManager uses ScopedCgroupOperations to register all side-effects to the cgroup hierarchy so graceful cleanup can apply them in reverse.

There are placeholders in the code for future work:

  1. CgroupDriverInterface needs to implement a few more methods (DeleteCgroup, DisableController) to allow for full cleanup in CgroupManager.
  2. CgroupManager needs additional tests for cleanup.
  3. CgroupManagerInterface needs to expose APIs for moving processes into a cgroup.

israbbani and others added 30 commits July 24, 2025 20:39
to perform cgroup operations.

Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
instead of clone for older kernel headers < 5.7 (which is what we have
in CI)

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
Signed-off-by: irabbani <[email protected]>
@israbbani israbbani requested a review from a team as a code owner September 4, 2025 00:04
@israbbani israbbani added the core Issues that should be addressed in Ray Core label Sep 4, 2025
Base automatically changed from irabbani/cgroups-2 to master September 4, 2025 04:54
@israbbani
Copy link
Contributor Author

Test failures look unrelated (from serve)

hdrs = [
"cgroup_manager_interface.h",
],
target_compatible_with = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

🫶

int64_t max_cpu_weight = supported_constraints_.at(kCPUWeightConstraint).Max();
int64_t application_cgroup_cpu_weight = max_cpu_weight - system_reserved_cpu_weight;

RAY_LOG(INFO) << absl::StrFormat(
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems a little noisy for an info level, but only once per raylet startup so should be ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As an SRE, I found log lines like this one very useful when debugging issues. As a rule of thumb I think we should log the configuration each component starts up with (especially if it's only created once in the lifecycle of the application).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good. This one is nice that all of the info is logged in one place. We have some other startup logs that are noisy because we log each bit in a separate log line from different components.

#include "ray/common/cgroup2/scoped_cgroup_operation.h"
#include "ray/common/status_or.h"

namespace ray {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe should have a namespace cgroup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to trying it. I haven't really wrapped my head around what best practices should be around namespaces. I've added an item to #54703. I'll play around with it at the end.

3. move all processes from the system cgroup into the base cgroup.
4. delete the node, system, and application cgroups respectively.
Cleanup is best-effort. If any step fails, it will log a warning.
Copy link
Collaborator

Choose a reason for hiding this comment

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

why's this? to avoid crashing before other cleanup can happen at a higher level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I figured we'd want to attempt the rest of the graceful shutdown process of the raylet even if cgroup cleanup didn't succeed fully.

enabled_controllers_ == other.enabled_controllers_;
}
};
class FakeCgroupDriver : public CgroupDriverInterface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤌

@edoakes
Copy link
Collaborator

edoakes commented Sep 4, 2025

minor comments; ping for merge

@israbbani
Copy link
Contributor Author

@edoakes ready for merge. Thanks!

@jjyao jjyao merged commit 5e85227 into master Sep 5, 2025
5 checks passed
@jjyao jjyao deleted the irabbani/cgroups-3 branch September 5, 2025 17:57
edoakes added a commit that referenced this pull request Sep 6, 2025
…anager. (#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on #56186.

For more details about the resource isolation project see
#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
sampan-s-nayak pushed a commit to sampan-s-nayak/ray that referenced this pull request Sep 8, 2025
…rarchy and clean it up (ray-project#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: sampan <[email protected]>
sampan-s-nayak pushed a commit to sampan-s-nayak/ray that referenced this pull request Sep 8, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: sampan <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
…rarchy and clean it up (ray-project#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: jugalshah291 <[email protected]>
wyhong3103 pushed a commit to wyhong3103/ray that referenced this pull request Sep 12, 2025
…rarchy and clean it up (ray-project#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: yenhong.wong <[email protected]>
wyhong3103 pushed a commit to wyhong3103/ray that referenced this pull request Sep 12, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: yenhong.wong <[email protected]>
ZacAttack pushed a commit to ZacAttack/ray that referenced this pull request Sep 24, 2025
…rarchy and clean it up (ray-project#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: zac <[email protected]>
ZacAttack pushed a commit to ZacAttack/ray that referenced this pull request Sep 24, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: zac <[email protected]>
dstrodtman pushed a commit that referenced this pull request Oct 6, 2025
…rarchy and clean it up (#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…rarchy and clean it up (ray-project#56186)

Signed-off-by: irabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…anager. (ray-project#56246)

This PR continues to implement the CgroupManager. CgroupManager will be
used by the Raylet to manage the cgroup hierarchy. The implementation
will be completed in subsequent PRs.

This PR stacks on ray-project#56186.

For more details about the resource isolation project see
ray-project#54703.

In this PR:
* CgroupManager now bound checks constraints (e.g. cpu.weight is within
[1,10000].
* CgroupDriver no longer bound checks constraints.

---------

Signed-off-by: Ibrahim Rabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants