Skip to content

[core] (cgroups 3/n) Creating CgroupManager to setup Ray's cgroup hierarchy and clean it up#56186

Merged
jjyao merged 69 commits intomasterfrom
irabbani/cgroups-3
Sep 5, 2025
Merged

[core] (cgroups 3/n) Creating CgroupManager to setup Ray's cgroup hierarchy and clean it up#56186
jjyao merged 69 commits intomasterfrom
irabbani/cgroups-3

Conversation

@israbbani
Copy link
Copy Markdown
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.

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

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
instead of clone for older kernel headers < 5.7 (which is what we have
in CI)

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
bug
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
fix CI.

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
up
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
@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
Ibrahim Rabbani added 2 commits September 4, 2025 09:28
@israbbani
Copy link
Copy Markdown
Contributor Author

Test failures look unrelated (from serve)

hdrs = [
"cgroup_manager_interface.h",
],
target_compatible_with = [
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.

🫶

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤌

@edoakes
Copy link
Copy Markdown
Collaborator

edoakes commented Sep 4, 2025

minor comments; ping for merge

@israbbani
Copy link
Copy Markdown
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
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 <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: sampan <sampan@anyscale.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: sampan <sampan@anyscale.com>
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 <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: jugalshah291 <shah.jugal291@gmail.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: jugalshah291 <shah.jugal291@gmail.com>
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 <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: yenhong.wong <yenhong.wong@grabtaxi.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: yenhong.wong <yenhong.wong@grabtaxi.com>
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 <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: zac <zac@anyscale.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: zac <zac@anyscale.com>
dstrodtman pushed a commit that referenced this pull request Oct 6, 2025
…rarchy and clean it up (#56186)

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Douglas Strodtman <douglas@anyscale.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Douglas Strodtman <douglas@anyscale.com>
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 <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <israbbani@gmail.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
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 <irabbani@anyscale.com>
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
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.

3 participants