Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into HEAD
- Loading branch information
Showing
884 changed files
with
21,893 additions
and
7,696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
|
||
|
||
### CI modificators (add a leading space to apply): | ||
### CI modificators (add a leading space to apply) ### | ||
|
||
## To avoid a merge commit in CI: | ||
#no_merge_commit | ||
|
||
## To discard CI cache: | ||
#no_ci_cache | ||
|
||
## To not test (only style check): | ||
#do_not_test | ||
|
||
## To run specified set of tests in CI: | ||
#ci_set_<SET_NAME> | ||
#ci_set_reduced | ||
#ci_set_arm | ||
#ci_set_integration | ||
|
||
## To run specified job in CI: | ||
#job_<JOB NAME> | ||
#job_stateless_tests_release | ||
#job_package_debug | ||
#job_integration_tests_asan | ||
|
||
## To run only specified batches for multi-batch job(s) | ||
#batch_2 | ||
#btach_1_2_3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <base/cgroupsv2.h> | ||
|
||
#include <base/defines.h> | ||
|
||
#include <fstream> | ||
#include <sstream> | ||
|
||
|
||
bool cgroupsV2Enabled() | ||
{ | ||
#if defined(OS_LINUX) | ||
/// This file exists iff the host has cgroups v2 enabled. | ||
auto controllers_file = default_cgroups_mount / "cgroup.controllers"; | ||
if (!std::filesystem::exists(controllers_file)) | ||
return false; | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
bool cgroupsV2MemoryControllerEnabled() | ||
{ | ||
#if defined(OS_LINUX) | ||
chassert(cgroupsV2Enabled()); | ||
/// According to https://docs.kernel.org/admin-guide/cgroup-v2.html: | ||
/// - file 'cgroup.controllers' defines which controllers *can* be enabled | ||
/// - file 'cgroup.subtree_control' defines which controllers *are* enabled | ||
/// Caveat: nested groups may disable controllers. For simplicity, check only the top-level group. | ||
std::ifstream subtree_control_file(default_cgroups_mount / "cgroup.subtree_control"); | ||
if (!subtree_control_file.is_open()) | ||
return false; | ||
std::string controllers; | ||
std::getline(subtree_control_file, controllers); | ||
if (controllers.find("memory") == std::string::npos) | ||
return false; | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
std::string cgroupV2OfProcess() | ||
{ | ||
#if defined(OS_LINUX) | ||
chassert(cgroupsV2Enabled()); | ||
/// All PIDs assigned to a cgroup are in /sys/fs/cgroups/{cgroup_name}/cgroup.procs | ||
/// A simpler way to get the membership is: | ||
std::ifstream cgroup_name_file("/proc/self/cgroup"); | ||
if (!cgroup_name_file.is_open()) | ||
return ""; | ||
/// With cgroups v2, there will be a *single* line with prefix "0::/" | ||
/// (see https://docs.kernel.org/admin-guide/cgroup-v2.html) | ||
std::string cgroup; | ||
std::getline(cgroup_name_file, cgroup); | ||
static const std::string v2_prefix = "0::/"; | ||
if (!cgroup.starts_with(v2_prefix)) | ||
return ""; | ||
cgroup = cgroup.substr(v2_prefix.length()); | ||
return cgroup; | ||
#else | ||
return ""; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <string> | ||
|
||
#if defined(OS_LINUX) | ||
/// I think it is possible to mount the cgroups hierarchy somewhere else (e.g. when in containers). | ||
/// /sys/fs/cgroup was still symlinked to the actual mount in the cases that I have seen. | ||
static inline const std::filesystem::path default_cgroups_mount = "/sys/fs/cgroup"; | ||
#endif | ||
|
||
/// Is cgroups v2 enabled on the system? | ||
bool cgroupsV2Enabled(); | ||
|
||
/// Is the memory controller of cgroups v2 enabled on the system? | ||
/// Assumes that cgroupsV2Enabled() is enabled. | ||
bool cgroupsV2MemoryControllerEnabled(); | ||
|
||
/// Which cgroup does the process belong to? | ||
/// Returns an empty string if the cgroup cannot be determined. | ||
/// Assumes that cgroupsV2Enabled() is enabled. | ||
std::string cgroupV2OfProcess(); |
Oops, something went wrong.