-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] [3/N] Check cgroupv2 mount status #48833
Changes from 1 commit
a8f84be
6b67af3
f1fe9ab
e120dd5
b3ec336
12e207b
c061931
d9df2da
b5ca626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 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 "ray/raylet/cgroup_v2_utils.h" | ||
|
||
#include <fstream> | ||
#include <string> | ||
|
||
#include "absl/strings/str_split.h" | ||
#include "absl/strings/strip.h" | ||
#include "ray/util/logging.h" | ||
|
||
namespace ray { | ||
|
||
bool IsCgroupV2MountedAsRw() { | ||
// Checking all mountpoints directly and parse textually is the easiest way, compared | ||
// with mounted filesystem attributes. | ||
std::ifstream mounts("/proc/mounts"); | ||
if (!mounts.is_open()) { | ||
return false; | ||
} | ||
|
||
// Mount information is formatted as: | ||
// <fs_spec> <fs_file> <fs_vfstype> <fs_mntopts> <dump-field> <fsck-field> | ||
std::string line; | ||
while (std::getline(mounts, line)) { | ||
std::vector<std::string_view> mount_info_tokens = absl::StrSplit(line, ' '); | ||
RAY_CHECK_EQ(mount_info_tokens.size(), 6UL); | ||
// For cgroupv2, `fs_spec` should be `cgroupv2` and there should be only one mount | ||
// information item. | ||
if (mount_info_tokens[0] != "cgroup2") { | ||
continue; | ||
} | ||
const auto &fs_mntopts = mount_info_tokens[3]; | ||
|
||
// Mount options are formatted as: <opt1,opt2,...>. | ||
std::vector<std::string_view> mount_opts = absl::StrSplit(fs_mntopts, ','); | ||
|
||
// CgroupV2 has only one mount item, directly returns. | ||
return std::any_of(mount_opts.begin(), | ||
mount_opts.end(), | ||
[](const std::string_view cur_opt) { return cur_opt == "rw"; }); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace ray |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 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. | ||
|
||
// Utils for cgroup v2 related. | ||
|
||
#pragma once | ||
|
||
namespace ray { | ||
|
||
// Return whether cgroup V2 is mounted in read and write mode. | ||
bool IsCgroupV2MountedAsRw(); | ||
|
||
} // namespace ray |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 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 "src/ray/raylet/cgroup_v2_utils.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace ray { | ||
|
||
namespace { | ||
|
||
// Precondition: cgroup V2 has already been mounted as rw. | ||
// | ||
// Setup command: | ||
// sudo umount /sys/fs/cgroup/unified | ||
// sudo mount -t cgroup2 cgroup2 /sys/fs/cgroup/unified -o rw | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qq, I am not familiar but what requires to put these step in ray's cicd? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think it should be placed under CI, which is a group of unit test, but for cgroup related feature they should be tested as integration tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why you see me mark test as "manual". |
||
TEST(CgroupV2UtilsTest, CheckCgroupV2Mount) { EXPECT_TRUE(IsCgroupV2MountedAsRw()); } | ||
|
||
} // namespace | ||
|
||
} // namespace ray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: I think you also need to check that the normal user in the container can modify the cgroup path, usually
/sys/fs/cgroup
is owned byroot
user even though it's writable, it is only writable by theroot
.See https://github.com/anyscale/product/pull/32052/files#diff-005124dd6eac41dac5da8cac101b497921e0ee33ca99ec034fbb9fd82ddba508
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good point, to update cgroupv2, mounted as rw is not enough, current user should also have the permission to write. Add a test to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought, another way we could do is we don't do any precheck before actually setting cgroup, which fails directly due to lacking permission.