You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@mesos.apache.org by "DevinLeamy (via GitHub)" <gi...@apache.org> on 2024/03/19 14:37:32 UTC
[PR] [cgroups2] Introduces the cpu namespace and cpu::weight() API [mesos]
DevinLeamy opened a new pull request, #522:
URL: https://github.com/apache/mesos/pull/522
Introduces the `cpu` namespace for cgroups2, and expose an API to set
the CPU weight for a cgroup.
In cgroups v2, CPU cycles are allocated based on weights that are assigned
to cgroups, using the "cpu.weight" control. Specifically, a cgroup has access
to 100(weight/total_weight)% of CPU access.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [cgroups2] Introduces the cpu namespace and cpu::weight() API [mesos]
Posted by "bmahler (via GitHub)" <gi...@apache.org>.
bmahler closed pull request #522: [cgroups2] Introduces the cpu namespace and cpu::weight() API
URL: https://github.com/apache/mesos/pull/522
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [cgroups2] Introduces the cpu namespace and cpu::weight() API [mesos]
Posted by "bmahler (via GitHub)" <gi...@apache.org>.
bmahler commented on code in PR #522:
URL: https://github.com/apache/mesos/pull/522#discussion_r1532377374
##########
src/linux/cgroups2.cpp:
##########
@@ -150,6 +150,18 @@ Try<string> read(const string& cgroup, const string& control)
}
+template <>
+Try<uint64_t> read(const string& cgroup, const string& control)
+{
+ Try<string> content = read<string>(cgroup, control);
+ if (content.isError()) {
+ return Error(content.error());
+ }
+
+ return std::stoull(strings::trim(*content));
Review Comment:
note that this can fail and throw an exception which we would need to catch since we don't use exceptions!
we use numify.hpp from stout for this instead, which does expose a Try for us already:
```
return numify<uint64_t>(strings::trim(content));
```
##########
src/linux/cgroups2.cpp:
##########
@@ -382,4 +404,42 @@ Try<set<string>> enabled(const string& cgroup)
} // namespace controllers {
+namespace cpu {
+
+namespace control {
+
+const std::string IDLE = "cpu.idle";
+const std::string MAX = "cpu.max";
+const std::string MAX_BURST = "cpu.max.burst";
+const std::string PRESSURE = "cpu.pressure";
+const std::string STATS = "cpu.stat";
+const std::string UCLAMP_MAX = "cpu.uclamp.max";
+const std::string UCLAMP_MIN = "cpu.uclamp.min";
+const std::string WEIGHT = "cpu.weight";
+const std::string WEIGHT_NICE = "cpu.weight.nice";
+
+} // namespace control {
+
+Try<Nothing> weight(const string& cgroup, uint32_t weight)
+{
+ if (cgroup == ROOT_CGROUP) {
+ return Error("Operation does not exist for the root cgroup");
+ }
+
+ return cgroups2::write(cgroup, cpu::control::WEIGHT, (uint64_t) weight);
Review Comment:
this is a C style cast, we would use static_cast here to check at compile time that it works, however we probably don't need to be casting since we don't have an integer type that holds the needed range anyway
##########
src/linux/cgroups2.cpp:
##########
@@ -382,4 +404,42 @@ Try<set<string>> enabled(const string& cgroup)
} // namespace controllers {
+namespace cpu {
+
+namespace control {
+
+const std::string IDLE = "cpu.idle";
+const std::string MAX = "cpu.max";
+const std::string MAX_BURST = "cpu.max.burst";
+const std::string PRESSURE = "cpu.pressure";
+const std::string STATS = "cpu.stat";
+const std::string UCLAMP_MAX = "cpu.uclamp.max";
+const std::string UCLAMP_MIN = "cpu.uclamp.min";
+const std::string WEIGHT = "cpu.weight";
+const std::string WEIGHT_NICE = "cpu.weight.nice";
+
+} // namespace control {
+
+Try<Nothing> weight(const string& cgroup, uint32_t weight)
+{
+ if (cgroup == ROOT_CGROUP) {
+ return Error("Operation does not exist for the root cgroup");
Review Comment:
maybe "not supported" is more idiomatic here
##########
src/linux/cgroups2.hpp:
##########
@@ -95,6 +95,19 @@ Try<std::set<std::string>> enabled(const std::string& cgroup);
} // namespace controllers {
+namespace cpu {
+
+// Set the weight for a cgroup.
+// Cannot be used for the root cgroup.
+Try<Nothing> weight(const std::string& cgroup, uint32_t weight);
Review Comment:
let's document the valid weight range which is [1, 10000], since we can't use an integer type that exactly fits it, also means that if we were to take smaller ints than 64 bits, then 16 would be more appropriate..?
##########
src/linux/cgroups2.hpp:
##########
@@ -95,6 +95,19 @@ Try<std::set<std::string>> enabled(const std::string& cgroup);
} // namespace controllers {
+namespace cpu {
+
+// Set the weight for a cgroup.
+// Cannot be used for the root cgroup.
+Try<Nothing> weight(const std::string& cgroup, uint32_t weight);
+
+
+// Determine the weight a cgroup.
Review Comment:
Ditto here.
##########
src/linux/cgroups2.cpp:
##########
@@ -382,4 +404,42 @@ Try<set<string>> enabled(const string& cgroup)
} // namespace controllers {
+namespace cpu {
+
+namespace control {
+
+const std::string IDLE = "cpu.idle";
+const std::string MAX = "cpu.max";
+const std::string MAX_BURST = "cpu.max.burst";
+const std::string PRESSURE = "cpu.pressure";
+const std::string STATS = "cpu.stat";
+const std::string UCLAMP_MAX = "cpu.uclamp.max";
+const std::string UCLAMP_MIN = "cpu.uclamp.min";
+const std::string WEIGHT = "cpu.weight";
+const std::string WEIGHT_NICE = "cpu.weight.nice";
+
+} // namespace control {
+
+Try<Nothing> weight(const string& cgroup, uint32_t weight)
+{
+ if (cgroup == ROOT_CGROUP) {
+ return Error("Operation does not exist for the root cgroup");
+ }
+
+ return cgroups2::write(cgroup, cpu::control::WEIGHT, (uint64_t) weight);
Review Comment:
this is a C style cast, we would use static_cast here to check at compile time that it works, however we probably don't need to be casting since we don't have an integer type that holds the needed range anyway
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@mesos.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org