-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Core] (Resource Isolation 12/n) Switch group killing policy to by time killing policy #62643
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
Changes from 2 commits
a70ff17
b35865a
5c2599f
8245dbb
caf195e
b886146
a7282df
6609b06
7e7031f
c5a67e2
dc8a434
2c14f01
2884c72
e394d33
251a225
83f9f20
4db1afd
2ce6a98
a177a40
4091330
c2655d3
6a99c1c
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| #include "absl/strings/str_format.h" | ||
| #include "absl/strings/str_join.h" | ||
| #include "ray/common/memory_monitor_interface.h" | ||
| #include "ray/common/ray_config.h" | ||
| #include "ray/util/logging.h" | ||
|
|
||
| namespace ray { | ||
|
|
@@ -292,23 +293,61 @@ int64_t MemoryMonitorUtils::NullableMin(int64_t left, int64_t right) { | |
| } | ||
| } | ||
|
|
||
| int64_t MemoryMonitorUtils::GetMemoryThreshold(int64_t total_memory_bytes, | ||
| float usage_threshold, | ||
| int64_t min_memory_free_bytes) { | ||
| int64_t MemoryMonitorUtils::GetMemoryThreshold( | ||
| int64_t total_memory_bytes, | ||
| float usage_threshold, | ||
| int64_t min_memory_free_bytes, | ||
| bool resource_isolation_enabled, | ||
| const CgroupManagerInterface &cgroup_manager) { | ||
| RAY_CHECK_GE(total_memory_bytes, MemoryMonitorInterface::kNull); | ||
| RAY_CHECK_GE(min_memory_free_bytes, MemoryMonitorInterface::kNull); | ||
| RAY_CHECK_GE(usage_threshold, 0); | ||
| RAY_CHECK_LE(usage_threshold, 1); | ||
| RAY_CHECK_GE(usage_threshold, 0) | ||
| << "Invalid configuration: usage_threshold must be >= 0"; | ||
| RAY_CHECK_LE(usage_threshold, 1) | ||
| << "Invalid configuration: usage_threshold must be <= 1"; | ||
|
|
||
| int64_t threshold_fraction = (int64_t)(total_memory_bytes * usage_threshold); | ||
| int64_t resolved_memory_threshold_bytes; | ||
| int64_t threshold_fraction = static_cast<int64_t>(total_memory_bytes * usage_threshold); | ||
|
|
||
| if (min_memory_free_bytes > MemoryMonitorInterface::kNull) { | ||
| int64_t threshold_absolute = total_memory_bytes - min_memory_free_bytes; | ||
| RAY_CHECK_GE(threshold_absolute, 0); | ||
| return std::max(threshold_fraction, threshold_absolute); | ||
| resolved_memory_threshold_bytes = std::max(threshold_fraction, threshold_absolute); | ||
| } else { | ||
| return threshold_fraction; | ||
| resolved_memory_threshold_bytes = threshold_fraction; | ||
| } | ||
|
|
||
| if (resource_isolation_enabled) { | ||
| StatusOr<std::string> result = | ||
| cgroup_manager.GetUserCgroupConstraintValue("memory.max"); | ||
| RAY_CHECK(result.ok()) << absl::StrFormat( | ||
| "Failed to get user cgroup memory limit when setting up memory monitor: %s", | ||
| result.ToString()); | ||
| std::string user_memory_max_bytes_str = | ||
| std::string(absl::StripAsciiWhitespace(result.value())); | ||
| RAY_CHECK(!user_memory_max_bytes_str.empty()) << absl::StrFormat( | ||
| "Failed to get memory.max constraint value from user cgroup %s. " | ||
| "Please check that the cgroup path for resource isolation is correct.", | ||
| cgroup_manager.GetUserCgroupPath()); | ||
|
|
||
|
Contributor
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. When moving the logic from
Contributor
Author
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. Yep, the check for whether the string is empty is unnecessary as the underlying call to fetch the constraint value already asserts this. |
||
| if (!user_memory_max_bytes_str.empty() && | ||
| std::all_of(user_memory_max_bytes_str.begin(), | ||
| user_memory_max_bytes_str.end(), | ||
| ::isdigit)) { | ||
|
Kunchd marked this conversation as resolved.
|
||
| int64_t user_memory_max_bytes = std::stoll(user_memory_max_bytes_str); | ||
| resolved_memory_threshold_bytes = | ||
| user_memory_max_bytes - | ||
| MemoryMonitorInterface::THRESHOLD_MONITOR_REACTION_BUFFER; | ||
| RAY_CHECK_GE(resolved_memory_threshold_bytes, 0) << absl::StrFormat( | ||
| "Available user task memory is less than the kill memory buffer bytes: " | ||
| "%d < %d. Please consider using a host with more memory. If the current host " | ||
| "memory size must be kept, please adjust the kill memory buffer size.", | ||
| user_memory_max_bytes, | ||
| MemoryMonitorInterface::THRESHOLD_MONITOR_REACTION_BUFFER); | ||
|
Kunchd marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| return resolved_memory_threshold_bytes; | ||
| } | ||
|
|
||
| int64_t MemoryMonitorUtils::GetProcessUsedMemoryBytes( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,11 @@ RAY_CONFIG(int64_t, min_memory_free_bytes, (int64_t)-1) | |
| /// killing workers via the worker killing policy. | ||
| RAY_CONFIG(uint64_t, kill_memory_buffer_bytes, 3ULL * 1024 * 1024 * 1024) // 3GB | ||
|
|
||
| /// Whether to use the group-by-owner worker killing policy instead of the | ||
| /// default time-based worker killing policy. When true, workers killed by the | ||
| /// by group killing policy (legacy policy). | ||
|
Kunchd marked this conversation as resolved.
Outdated
|
||
| RAY_CONFIG(bool, WORKER_KILLING_POLICY_BY_GROUP, false) | ||
|
Kunchd marked this conversation as resolved.
Outdated
Contributor
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. Looks like we are changing the default behavior of the killing policy for all the users. Wondering have we communicated the default behavior to the users and should we gradually roll out the change instead of the directly change the config?
Contributor
Author
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. Chatted offline. The new policy behaves very similarly to the existing policy (identical in the common case when the driver is the single source that's submitting the tasks). Additionally, it addresses the issue where the existing policy was not killing aggressively enough to relieve us of memory pressure. We expect the new policy to be a general improvement across the board, but we will modify this PR to make it explicit that there's a behavioral change, and include this in the next version release. We will also leave a comment in the oom log so that users will know how to revert if they experience oom. |
||
|
|
||
| /// The reserved memory bytes for system processes | ||
| /// enforced via cgroup memory.min constraint which guarantees | ||
| /// that the system processes' memory will not be reclaimed under any conditions. | ||
|
|
||
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.
Not related to this PR. I just wonder if all these error messages should come from result.status().message().
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.
The underlying get constraint function should already strip the string for white spaces. I had the line here for defensive purposes, but it's unnecessary as we can assume the returned value will be a properly formatted string.
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.
The remaining error messages are more pertinent to reading the specific value, so I'll keep them.