1 Star 0 Fork 50

zyu_cheng/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
10008-core-add-a-config-item-to-support-setting-the-value-.patch 4.23 KB
一键复制 编辑 原始数据 按行查看 历史
庞庆 提交于 2022-04-19 15:08 . Add optimized patches
From f21d63650318791f29f56dc26f23acb5b53620a6 Mon Sep 17 00:00:00 2001
From:Yuanhong Peng <yummypeng@linux.alibaba.com>
Date: Tue, 19 Apr 2022 14:13:49 +0800
Subject: [PATCH] core: add a config item to support setting the value
---
src/core/main.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/src/core/main.c b/src/core/main.c
index 81dae1c..0712423 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -140,6 +140,7 @@ static NUMAPolicy arg_numa_policy;
static bool reexec_jmp_can = false;
static bool reexec_jmp_inited = false;
static sigjmp_buf reexec_jmp_buf;
+static bool arg_default_cpuset_clone_children = false;
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
const struct rlimit *saved_rlimit_memlock);
@@ -527,6 +528,14 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
return 0;
parse_path_argument_and_warn(value, false, &arg_watchdog_device);
+
+ } else if (proc_cmdline_key_streq(key, "systemd.cpuset_clone_children") && value) {
+
+ r = parse_boolean(value);
+ if (r < 0)
+ log_warning("Failed to parse cpuset_clone_children switch %s. Ignoring.", value);
+ else
+ arg_default_cpuset_clone_children = r;
} else if (streq(key, "quiet") && !value) {
@@ -756,6 +765,7 @@ static int parse_config_file(void) {
{ "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting },
{ "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max },
{ "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, 0, &arg_cad_burst_action },
+ { "Manager", "DefaultCPUSetCloneChildren",config_parse_bool, 0, &arg_default_cpuset_clone_children },
{}
};
@@ -1872,6 +1882,64 @@ static void log_execution_mode(bool *ret_first_boot) {
}
}
+static bool is_use_triple_cgroup(void) {
+ const char * path ="/sys/fs/cgroup/cpuset";
+ _cleanup_strv_free_ char **l = NULL;
+ char buf[128] = {0};
+ int r;
+
+ r = is_symlink(path);
+ if (r <= 0)
+ return false;
+
+ r = readlink(path, buf, sizeof(buf));
+ if (r < 0 || (unsigned int)r >= sizeof(buf))
+ return false;
+
+ buf[r] = '\0';
+ l = strv_split(buf, ",");
+ if (!l)
+ return false;
+
+ strv_sort(l);
+ if (strv_length(l) != 3)
+ return false;
+
+ if (streq(l[0],"cpu") && streq(l[1], "cpuacct") &&
+ streq(l[2], "cpuset")) {
+ log_debug(PACKAGE_STRING " use_triple_cgroup: %s", buf);
+ return true;
+ }
+ return false;
+}
+
+static int ali_handle_cpuset_clone_children(void)
+{
+ const char *file = "/sys/fs/cgroup/cpuset/cgroup.clone_children";
+ _cleanup_free_ char *buf = NULL;
+ int r;
+
+ r = read_one_line_file(file, &buf);
+ if (r < 0) {
+ log_warning_errno(r, "Cannot read %s: %m", file);
+ return r;
+ }
+
+ if (streq(buf, "1") && arg_default_cpuset_clone_children)
+ return 0;
+
+ if (streq(buf, "0") && (!arg_default_cpuset_clone_children))
+ return 0;
+
+ if (!is_use_triple_cgroup())
+ return 0;
+
+ r = write_string_file(file, one_zero(arg_default_cpuset_clone_children), 0);
+ log_info(PACKAGE_STRING " set %s to %s, ret=%d", file, one_zero(arg_default_cpuset_clone_children), r);
+ return r;
+}
+
+
static int initialize_runtime(
bool skip_setup,
struct rlimit *saved_rlimit_nofile,
@@ -1906,6 +1974,7 @@ static int initialize_runtime(
return r;
}
+ ali_handle_cpuset_clone_children();
status_welcome();
hostname_setup();
machine_id_setup(NULL, arg_machine_id, NULL);
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zyu_cheng/systemd.git
git@gitee.com:zyu_cheng/systemd.git
zyu_cheng
systemd
systemd
a8

搜索帮助