diff --git a/src/ray/common/cgroup2/BUILD.bazel b/src/ray/common/cgroup2/BUILD.bazel index a3f39c7040ad..b2becaa0575b 100644 --- a/src/ray/common/cgroup2/BUILD.bazel +++ b/src/ray/common/cgroup2/BUILD.bazel @@ -12,7 +12,10 @@ ray_cc_library( ":is_linux": ["cgroup_manager.cc"], "//conditions:default": ["noop_cgroup_manager.cc"], }), - hdrs = ["cgroup_manager.h"], + hdrs = [ + "cgroup_manager.h", + "scoped_cgroup_operation.h", + ], visibility = ["//visibility:public"], deps = [ ":cgroup_driver_interface", @@ -21,7 +24,6 @@ ray_cc_library( "//src/ray/common:status_or", ] + select({ ":is_linux": [ - ":scoped_cgroup_operation", "//src/ray/util:logging", "@com_google_absl//absl/strings", ], @@ -55,35 +57,28 @@ ray_cc_library( ray_cc_library( name = "sysfs_cgroup_driver", - srcs = ["sysfs_cgroup_driver.cc"], + srcs = select({ + ":is_linux": ["sysfs_cgroup_driver.cc"], + "//conditions:default": ["noop_sysfs_cgroup_driver.cc"], + }), hdrs = [ "sysfs_cgroup_driver.h", ], - target_compatible_with = [ - "@platforms//os:linux", - ], visibility = ["//visibility:public"], deps = [ ":cgroup_driver_interface", "//src/ray/common:status", "//src/ray/common:status_or", - "//src/ray/util:logging", - "@com_google_absl//absl/strings", - ], + ] + select({ + ":is_linux": [ + "//src/ray/util:logging", + "@com_google_absl//absl/strings", + ], + "//conditions:default": [], + }), ) # Private Targets. -ray_cc_library( - name = "scoped_cgroup_operation", - hdrs = [ - "scoped_cgroup_operation.h", - ], - target_compatible_with = [ - "@platforms//os:linux", - ], - visibility = [":__subpackages__"], -) - ray_cc_library( name = "fake_cgroup_driver", hdrs = [ diff --git a/src/ray/common/cgroup2/noop_sysfs_cgroup_driver.cc b/src/ray/common/cgroup2/noop_sysfs_cgroup_driver.cc new file mode 100644 index 000000000000..b448f021a8ad --- /dev/null +++ b/src/ray/common/cgroup2/noop_sysfs_cgroup_driver.cc @@ -0,0 +1,74 @@ +// Copyright 2025 The Ray Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "ray/common/cgroup2/sysfs_cgroup_driver.h" +#include "ray/common/status.h" +#include "ray/common/status_or.h" + +namespace ray { +Status SysFsCgroupDriver::CheckCgroupv2Enabled() { return Status::OK(); } + +Status SysFsCgroupDriver::CheckCgroup(const std::string &cgroup_path) { + return Status::OK(); +} + +Status SysFsCgroupDriver::CreateCgroup(const std::string &cgroup_path) { + return Status::OK(); +} + +Status SysFsCgroupDriver::DeleteCgroup(const std::string &cgroup_path) { + return Status::OK(); +} + +StatusOr> SysFsCgroupDriver::GetAvailableControllers( + const std::string &cgroup_dir) { + return std::unordered_set{}; +} + +StatusOr> SysFsCgroupDriver::GetEnabledControllers( + const std::string &cgroup_dir) { + return std::unordered_set{}; +} + +Status SysFsCgroupDriver::MoveAllProcesses(const std::string &from, + const std::string &to) { + return Status::OK(); +} + +Status SysFsCgroupDriver::EnableController(const std::string &cgroup_path, + const std::string &controller) { + return Status::OK(); +} + +Status SysFsCgroupDriver::DisableController(const std::string &cgroup_path, + const std::string &controller) { + return Status::OK(); +} + +Status SysFsCgroupDriver::AddConstraint(const std::string &cgroup_path, + const std::string &controller, + const std::string &constraint, + const std::string &constraint_value) { + return Status::OK(); +} + +StatusOr> SysFsCgroupDriver::ReadControllerFile( + const std::string &controller_file_path) { + return std::unordered_set{}; +} + +} // namespace ray diff --git a/src/ray/common/cgroup2/sysfs_cgroup_driver.cc b/src/ray/common/cgroup2/sysfs_cgroup_driver.cc index b36960c6127c..afa5be6ce544 100644 --- a/src/ray/common/cgroup2/sysfs_cgroup_driver.cc +++ b/src/ray/common/cgroup2/sysfs_cgroup_driver.cc @@ -37,6 +37,12 @@ #include "ray/common/status.h" #include "ray/common/status_or.h" +// Used to identify if a filesystem is mounted using cgroupv2. +// See: https://docs.kernel.org/admin-guide/cgroup-v2.html#mounting +#ifndef CGROUP2_SUPER_MAGIC +#define CGROUP2_SUPER_MAGIC 0x63677270 +#endif + namespace ray { Status SysFsCgroupDriver::CheckCgroupv2Enabled() { FILE *fp = setmntent(mount_file_path_.c_str(), "r"); diff --git a/src/ray/common/cgroup2/sysfs_cgroup_driver.h b/src/ray/common/cgroup2/sysfs_cgroup_driver.h index de5104caeec6..6b01fbe4886f 100644 --- a/src/ray/common/cgroup2/sysfs_cgroup_driver.h +++ b/src/ray/common/cgroup2/sysfs_cgroup_driver.h @@ -13,8 +13,10 @@ // limitations under the License. #pragma once -#include -#include +// TODO(#54703): SysFsCgroupDriver should not be a public target. +// It will be hidden behind a CgroupManagerFactory which will create +// an appropriate depending on configuration and platform. +// #include #include #include @@ -24,12 +26,6 @@ #include "ray/common/status.h" #include "ray/common/status_or.h" -// Used to identify if a filesystem is mounted using cgroupv2. -// See: https://docs.kernel.org/admin-guide/cgroup-v2.html#mounting -#ifndef CGROUP2_SUPER_MAGIC -#define CGROUP2_SUPER_MAGIC 0x63677270 -#endif - namespace ray { /** @@ -46,12 +42,9 @@ namespace ray { class SysFsCgroupDriver : public CgroupDriverInterface { public: /** - * MOUNTED is defined in mntent.h (and typically refers to /etc/mtab) - * @see https://www.gnu.org/software/libc/manual/2.24/html_node/Mount-Information.html - * * @param mount_file_path only used for testing. */ - explicit SysFsCgroupDriver(std::string mount_file_path = MOUNTED) + explicit SysFsCgroupDriver(std::string mount_file_path = kMountFilePath) : mount_file_path_(std::move(mount_file_path)) {} ~SysFsCgroupDriver() override = default; @@ -280,5 +273,6 @@ class SysFsCgroupDriver : public CgroupDriverInterface { static constexpr std::string_view kCgroupSubtreeControlFilename = "cgroup.subtree_control"; static constexpr std::string_view kCgroupControllersFilename = "cgroup.controllers"; + static inline std::string kMountFilePath = "/etc/mtab"; }; } // namespace ray