Skip to content

Commit f896b68

Browse files
israbbaniIbrahim Rabbanijjyao
authored
[core] Creating non-linux implementation for sysfs_cgroup_driver. (#56483)
Signed-off-by: Ibrahim Rabbani <[email protected]> Signed-off-by: israbbani <[email protected]> Co-authored-by: Ibrahim Rabbani <[email protected]> Co-authored-by: Jiajun Yao <[email protected]>
1 parent 8259540 commit f896b68

File tree

4 files changed

+101
-32
lines changed

4 files changed

+101
-32
lines changed

src/ray/common/cgroup2/BUILD.bazel

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ ray_cc_library(
1212
":is_linux": ["cgroup_manager.cc"],
1313
"//conditions:default": ["noop_cgroup_manager.cc"],
1414
}),
15-
hdrs = ["cgroup_manager.h"],
15+
hdrs = [
16+
"cgroup_manager.h",
17+
"scoped_cgroup_operation.h",
18+
],
1619
visibility = ["//visibility:public"],
1720
deps = [
1821
":cgroup_driver_interface",
@@ -21,7 +24,6 @@ ray_cc_library(
2124
"//src/ray/common:status_or",
2225
] + select({
2326
":is_linux": [
24-
":scoped_cgroup_operation",
2527
"//src/ray/util:logging",
2628
"@com_google_absl//absl/strings",
2729
],
@@ -55,35 +57,28 @@ ray_cc_library(
5557

5658
ray_cc_library(
5759
name = "sysfs_cgroup_driver",
58-
srcs = ["sysfs_cgroup_driver.cc"],
60+
srcs = select({
61+
":is_linux": ["sysfs_cgroup_driver.cc"],
62+
"//conditions:default": ["noop_sysfs_cgroup_driver.cc"],
63+
}),
5964
hdrs = [
6065
"sysfs_cgroup_driver.h",
6166
],
62-
target_compatible_with = [
63-
"@platforms//os:linux",
64-
],
6567
visibility = ["//visibility:public"],
6668
deps = [
6769
":cgroup_driver_interface",
6870
"//src/ray/common:status",
6971
"//src/ray/common:status_or",
70-
"//src/ray/util:logging",
71-
"@com_google_absl//absl/strings",
72-
],
72+
] + select({
73+
":is_linux": [
74+
"//src/ray/util:logging",
75+
"@com_google_absl//absl/strings",
76+
],
77+
"//conditions:default": [],
78+
}),
7379
)
7480

7581
# Private Targets.
76-
ray_cc_library(
77-
name = "scoped_cgroup_operation",
78-
hdrs = [
79-
"scoped_cgroup_operation.h",
80-
],
81-
target_compatible_with = [
82-
"@platforms//os:linux",
83-
],
84-
visibility = [":__subpackages__"],
85-
)
86-
8782
ray_cc_library(
8883
name = "fake_cgroup_driver",
8984
hdrs = [
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2025 The Ray Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <string>
16+
#include <unordered_set>
17+
18+
#include "ray/common/cgroup2/sysfs_cgroup_driver.h"
19+
#include "ray/common/status.h"
20+
#include "ray/common/status_or.h"
21+
22+
namespace ray {
23+
Status SysFsCgroupDriver::CheckCgroupv2Enabled() { return Status::OK(); }
24+
25+
Status SysFsCgroupDriver::CheckCgroup(const std::string &cgroup_path) {
26+
return Status::OK();
27+
}
28+
29+
Status SysFsCgroupDriver::CreateCgroup(const std::string &cgroup_path) {
30+
return Status::OK();
31+
}
32+
33+
Status SysFsCgroupDriver::DeleteCgroup(const std::string &cgroup_path) {
34+
return Status::OK();
35+
}
36+
37+
StatusOr<std::unordered_set<std::string>> SysFsCgroupDriver::GetAvailableControllers(
38+
const std::string &cgroup_dir) {
39+
return std::unordered_set<std::string>{};
40+
}
41+
42+
StatusOr<std::unordered_set<std::string>> SysFsCgroupDriver::GetEnabledControllers(
43+
const std::string &cgroup_dir) {
44+
return std::unordered_set<std::string>{};
45+
}
46+
47+
Status SysFsCgroupDriver::MoveAllProcesses(const std::string &from,
48+
const std::string &to) {
49+
return Status::OK();
50+
}
51+
52+
Status SysFsCgroupDriver::EnableController(const std::string &cgroup_path,
53+
const std::string &controller) {
54+
return Status::OK();
55+
}
56+
57+
Status SysFsCgroupDriver::DisableController(const std::string &cgroup_path,
58+
const std::string &controller) {
59+
return Status::OK();
60+
}
61+
62+
Status SysFsCgroupDriver::AddConstraint(const std::string &cgroup_path,
63+
const std::string &controller,
64+
const std::string &constraint,
65+
const std::string &constraint_value) {
66+
return Status::OK();
67+
}
68+
69+
StatusOr<std::unordered_set<std::string>> SysFsCgroupDriver::ReadControllerFile(
70+
const std::string &controller_file_path) {
71+
return std::unordered_set<std::string>{};
72+
}
73+
74+
} // namespace ray

src/ray/common/cgroup2/sysfs_cgroup_driver.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
#include "ray/common/status.h"
3838
#include "ray/common/status_or.h"
3939

40+
// Used to identify if a filesystem is mounted using cgroupv2.
41+
// See: https://docs.kernel.org/admin-guide/cgroup-v2.html#mounting
42+
#ifndef CGROUP2_SUPER_MAGIC
43+
#define CGROUP2_SUPER_MAGIC 0x63677270
44+
#endif
45+
4046
namespace ray {
4147
Status SysFsCgroupDriver::CheckCgroupv2Enabled() {
4248
FILE *fp = setmntent(mount_file_path_.c_str(), "r");

src/ray/common/cgroup2/sysfs_cgroup_driver.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// limitations under the License.
1414
#pragma once
1515

16-
#include <linux/magic.h>
17-
#include <mntent.h>
16+
// TODO(#54703): SysFsCgroupDriver should not be a public target.
17+
// It will be hidden behind a CgroupManagerFactory which will create
18+
// an appropriate depending on configuration and platform.
19+
// #include <mntent.h>
1820

1921
#include <string>
2022
#include <unordered_set>
@@ -24,12 +26,6 @@
2426
#include "ray/common/status.h"
2527
#include "ray/common/status_or.h"
2628

27-
// Used to identify if a filesystem is mounted using cgroupv2.
28-
// See: https://docs.kernel.org/admin-guide/cgroup-v2.html#mounting
29-
#ifndef CGROUP2_SUPER_MAGIC
30-
#define CGROUP2_SUPER_MAGIC 0x63677270
31-
#endif
32-
3329
namespace ray {
3430

3531
/**
@@ -46,12 +42,9 @@ namespace ray {
4642
class SysFsCgroupDriver : public CgroupDriverInterface {
4743
public:
4844
/**
49-
* MOUNTED is defined in mntent.h (and typically refers to /etc/mtab)
50-
* @see https://www.gnu.org/software/libc/manual/2.24/html_node/Mount-Information.html
51-
*
5245
* @param mount_file_path only used for testing.
5346
*/
54-
explicit SysFsCgroupDriver(std::string mount_file_path = MOUNTED)
47+
explicit SysFsCgroupDriver(std::string mount_file_path = kMountFilePath)
5548
: mount_file_path_(std::move(mount_file_path)) {}
5649

5750
~SysFsCgroupDriver() override = default;
@@ -280,5 +273,6 @@ class SysFsCgroupDriver : public CgroupDriverInterface {
280273
static constexpr std::string_view kCgroupSubtreeControlFilename =
281274
"cgroup.subtree_control";
282275
static constexpr std::string_view kCgroupControllersFilename = "cgroup.controllers";
276+
static inline std::string kMountFilePath = "/etc/mtab";
283277
};
284278
} // namespace ray

0 commit comments

Comments
 (0)