Skip to content

Conversation

@israbbani
Copy link
Contributor

@israbbani israbbani commented Sep 5, 2025

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.

@israbbani israbbani added core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests labels Sep 5, 2025
@israbbani israbbani changed the title [cores (cgroups 8/n) Wiring CgroupManager into the raylet. [core] (cgroups 8/n) Wiring CgroupManager into the raylet. Sep 5, 2025
Comment on lines +269 to +273
#ifndef __linux__
RAY_LOG(WARNING)
<< "Resource isolation with cgroups is only supported in linux. Please set "
"enable_resource_isolation to false. This is likely a misconfiguration.";
#endif
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 thought it would be useful to add a warning when resource isolation is enabled on non-linux platforms. It's likely a misconfiguration.

@israbbani israbbani marked this pull request as ready for review September 6, 2025 18:08
@israbbani israbbani requested a review from a team as a code owner September 6, 2025 18:08
Signed-off-by: irabbani <[email protected]>
Base automatically changed from irabbani/cgroups-7 to irabbani/cgroups-6 September 9, 2025 13:54
DEFINE_string(labels,
"",
"Define the key-value format of node labels, which is a serialized JSON.");
DEFINE_bool(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud, do we need this boolean flag? Could we infer it to be true if cgroup_path and other configs are present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. I see the argument for both. More flags means more configuration possibilities. In this case, I picked an enable_ flag because the config is complex and it simplifies invariant checking and understanding the user's intent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. I'm not particularly opinionated one way or the other, mostly I guess probing to see if there was a reason to this rhyme and it sounds like you had one in mind. So we can keep this for now on the notion that it'll make it easier to extend later should that come along.

<< cgroup_manager.ToString();

#ifndef __linux__
RAY_LOG(WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do a system check to see if cgroups are enabled on the host?

Copy link
Contributor Author

@israbbani israbbani Sep 11, 2025

Choose a reason for hiding this comment

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

This warning is for if the user is trying to enable resource isolation on a non-linux system. So Cgroups will not be enabled.

The line above this will create the appropriate target of CgroupManager based on the platform. If it's linux, it will fail if cgroups are not enabled on the host.

    RAY_CHECK(cgroup_manager.ok())
        << "Failed to start raylet. Could not create CgroupManager because of "
        << cgroup_manager.ToString();

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 misspoke. The following is implemented in 9/n:

The line above this will create the appropriate target of CgroupManager based on the platform.

In this PR, we still do a system check if cgroups are enabled on the host in CgroupManager::Create.

@ZacAttack ZacAttack merged commit 161dd95 into irabbani/cgroups-6 Sep 11, 2025
4 checks passed
@ZacAttack ZacAttack deleted the irabbani/cgroups-8 branch September 11, 2025 18:06
israbbani added a commit that referenced this pull request Sep 11, 2025
@israbbani israbbani restored the irabbani/cgroups-8 branch September 11, 2025 18:22
@israbbani israbbani deleted the irabbani/cgroups-8 branch September 11, 2025 18:47
edoakes added a commit that referenced this pull request Sep 16, 2025
#56352)

This PR stacks on #56297.

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

This PR wires the resource isolation config (introduced here #51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
zma2 pushed a commit to zma2/ray that referenced this pull request Sep 23, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Zhiqiang Ma <[email protected]>
ZacAttack pushed a commit to ZacAttack/ray that referenced this pull request Sep 24, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: zac <[email protected]>
elliot-barn pushed a commit that referenced this pull request Sep 24, 2025
#56352)

This PR stacks on #56297.

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

This PR wires the resource isolation config (introduced here #51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
marcostephan pushed a commit to marcostephan/ray that referenced this pull request Sep 24, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Marco Stephan <[email protected]>
elliot-barn pushed a commit that referenced this pull request Sep 27, 2025
#56352)

This PR stacks on #56297.

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

This PR wires the resource isolation config (introduced here #51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: elliot-barn <[email protected]>
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[email protected]>
Co-authored-by: Edward Oakes <[email protected]>
snorkelopstesting4-web pushed a commit to snorkel-marlin-repos/ray-project_ray_pr_56297_6cb72018-61df-4d07-9fbe-47cf82d32e46 that referenced this pull request Oct 22, 2025
snorkelopsstgtesting1-spec added a commit to snorkel-marlin-repos/ray-project_ray_pr_56297_6cb72018-61df-4d07-9fbe-47cf82d32e46 that referenced this pull request Oct 22, 2025
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
ray-project#56352)

This PR stacks on ray-project#56297.

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

This PR wires the resource isolation config (introduced here ray-project#51865)
from ray cli (ray start) and the ray sdk (ray.init) into the raylet.
Notable changes include:
1. A separate python test target for running test_resource_isolation
related unit and integration tests. This unifies all cgroup related
tests under one buildkite target and removes the need for `--except-tags
cgroup` everywhere else.
2. Modification to the cgroup hierarchy. This was an oversight on my
part. The "no internal processes" constraint says that a non-root cgroup
can either have controllers enabled or have processes. Therefore, the
new hierarchy looks like:
```
  //      base_cgroup_path (e.g. /sys/fs/cgroup)
  //             |
  //     ray_node_<node_id>
  //       |           |
  //     system     application
  //       |           |
  //      leaf        leaf
  //
```
where the leaf nodes contain all processes and the system/application
cgroups apply cpu.weight and memory.min constraints.
3. CgroupManager now has a move ctor/assignment operator that allows
ownership and lifecycle to be managed by the NodeManager.
4. CgroupManager is now owned by NodeManager.
5. An end-to-end integration test in
`python/ray/tests/resource_isolation/test_resource_isolation_integration.py`.
6. Moved all previous integration tests from test_ray_init and test_cli
into test_resource_isolation_integration.py. These tests have TODOs to
finish them up once the rest of cgroup features are implemented.

---------

Signed-off-by: irabbani <[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.

3 participants