Skip to content

Conversation

@israbbani
Copy link
Contributor

@israbbani israbbani commented Sep 4, 2025

This PR stacks on #56246.

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

This PR implements RAII cleanup in CgroupManager. If the CgroupManager is destroyed, it will undo all cgroup-related side-effects in reverse order. There are four kinds of side-effects

  1. Creating Cgroups (reversed by deleting them)
  2. Moving Processes between Cgroups (reversed by moving them back)
  3. Enabling Controllers (reversed by disabling them)
  4. Adding Resource Constraints (reversed by reverting to default resource constraints)

A few notes about clean up:

  1. Clean up is currently best-effort meaning that if any part of it fails, it will log a warning and continue to attempt the rest of it.
  2. Clean up has to be done in order. For example, a cgroup cannot be deleted before its children are deleted. So cleanup proceeds from the leaf nodes up to the root note of the cgroup tree.
  3. The testing for cleanup needs to not only detect that clean up happened, but that it happened in the correct order.

I've left comments in the PR outlining the most suspect aspects of the design. Happy to incorporate feedback.

israbbani 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>
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>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
@israbbani israbbani marked this pull request as ready for review September 5, 2025 16:56
@israbbani israbbani requested a review from a team as a code owner September 5, 2025 16:56
Base automatically changed from irabbani/cgroups-5 to master September 8, 2025 17:40
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
…et and core worker (#56285)

This PR stacks on #56260.

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

This PR removes previous code for integrating resource isolation with
the raylet and core worker. It's a prerequisite for integrating the
CgroupManager with the raylet.

This PR is cleanup only and there is no behavior change.

---------

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
// CgroupDriver::DeleteCgroup.
void CgroupManager::RegisterDeleteCgroup(const std::string &cgroup_path) {
cleanup_operations_.emplace_back([cgroup = cgroup_path]() {
RAY_LOG(INFO) << absl::StrFormat("Deleting all cgroup %s.", cgroup);
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why remove the log? (I won't insist on bringing the log back, just curious to the motivation)

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 left it in by mistake from the previous PR. I was using it to debug a test.

cleanup_operations_.emplace_back([this, from_cgroup = from, to_cgroup = to]() {
Status s = this->cgroup_driver_->MoveAllProcesses(from_cgroup, to_cgroup);
if (!s.ok()) {
RAY_LOG(WARNING) << absl::StrFormat(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: WARNING vs. ERROR?

Also, what is the potential implication of this failing? If we're unable to move processes into their appropriate cgroup, then.... what, they'll just run without the resource limits we'd otherwise like imposted? Should we keep running in that scenario or bail out?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this line of questioning applies to delete too, but.... process move seems more concerning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is during clean up. When CgroupManager starts up with a base_cgroup, it moves all processes in that cgroup into the <base_cgroup_path>/system/leaf cgroup. This is reversing by moving those processes back into the base_cgroup.

The reason for doing this is that the default cgroup path, and the most commonly anticipated pattern, will be to run this with /sys/fs/cgroup inside a container which is the root cgroup for the container.

However, the root cgroup for the container is not the actual root cgroup of the operating system. This means that it is subject to the No Internal Processes constraint. It cannot have child cgroups and a controller enabled if it has processes inside it.

The implication for clean up is that the cgroup hierarchy will not be deleted properly. This is mostly fine when it's running inside a container. Given this, maybe ERROR makes more sense?

Copy link
Contributor

@ZacAttack ZacAttack left a comment

Choose a reason for hiding this comment

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

Synced offline, this looks good

This PR stacks on #56285.

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

This PR integrates the CgroupManager with the raylet startup in
`main.cc`. It includes
- A cross-platform cgroup_manager bazel target that selectively compiles
dependencies for linux/non-linux platforms. I prefer this design because
it keeps targets small and compile times low and removes unnecessary
ifdefs from the code.
- Adds the following command-line args to the raylet binary
   - enable_resource_isolation
   - cgroup_path
   - system_reserved_cpu_weight
   - system_reserved_memory_bytes

I've left comments on the PR to highlight parts that could use some
feedback/discussion.

---------

Signed-off-by: irabbani <irabbani@anyscale.com>
Signed-off-by: Ibrahim Rabbani <irabbani@anyscale.com>
@jjyao jjyao enabled auto-merge (squash) September 11, 2025 21:06
@jjyao jjyao merged commit f900567 into master Sep 11, 2025
6 checks passed
@jjyao jjyao deleted the irabbani/cgroups-6 branch September 11, 2025 22:22
TimothySeah added a commit to TimothySeah/ray that referenced this pull request Sep 13, 2025
…p hierarchy in reverse order when destroyed. (ray-project#56260)"

This reverts commit f900567.
edoakes added a commit to edoakes/ray that referenced this pull request Sep 14, 2025
…p hierarchy in reverse order when destroyed. (ray-project#56260)"

This reverts commit f900567.
edoakes added a commit to edoakes/ray that referenced this pull request Sep 14, 2025
…re cgroup hierarchy in reverse order when destroyed. (ray-project#56260)""

This reverts commit c4c774e.
edoakes added a commit to edoakes/ray that referenced this pull request Sep 14, 2025
…re cgroup hierarchy in reverse order when destroyed. (ray-project#56260)""

This reverts commit c4c774e.
ZacAttack pushed a commit to ZacAttack/ray that referenced this pull request Sep 24, 2025
…chy in reverse order when destroyed. (ray-project#56260)

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>
marcostephan pushed a commit to marcostephan/ray that referenced this pull request Sep 24, 2025
…chy in reverse order when destroyed. (ray-project#56260)

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: Marco Stephan <marco@magic.dev>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
…chy in reverse order when destroyed. (ray-project#56260)

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>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
…chy in reverse order when destroyed. (ray-project#56260)

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
…chy in reverse order when destroyed. (ray-project#56260)

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>
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.

5 participants