113 lines
5.3 KiB
Diff
113 lines
5.3 KiB
Diff
|
|
From 4e150d944763459fd8c070d6f53a3ab02d2883f4 Mon Sep 17 00:00:00 2001
|
||
|
|
From: xujing <xujing125@huawei.com>
|
||
|
|
Date: Tue, 24 Dec 2024 16:12:11 +0800
|
||
|
|
Subject: [PATCH] add DefaultEnableMemswLimit support
|
||
|
|
|
||
|
|
---
|
||
|
|
src/core/cgroup.c | 12 +++++++-----
|
||
|
|
src/core/main.c | 4 ++++
|
||
|
|
src/core/manager.c | 1 +
|
||
|
|
src/core/manager.h | 2 ++
|
||
|
|
src/core/system.conf.in | 1 +
|
||
|
|
5 files changed, 15 insertions(+), 5 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
|
||
|
|
index 47c5bb0..8d386c0 100644
|
||
|
|
--- a/src/core/cgroup.c
|
||
|
|
+++ b/src/core/cgroup.c
|
||
|
|
@@ -1539,11 +1539,13 @@ static void cgroup_context_apply(
|
||
|
|
|
||
|
|
(void) set_attribute_and_warn(u, "memory", "memory.limit_in_bytes", buf);
|
||
|
|
|
||
|
|
- if (sw_val == CGROUP_LIMIT_MAX)
|
||
|
|
- strncpy(buf, "-1\n", sizeof(buf));
|
||
|
|
- else
|
||
|
|
- xsprintf(buf, "%" PRIu64 "\n", sw_val);
|
||
|
|
- (void) set_attribute_and_warn(u, "memory", "memory.memsw.limit_in_bytes", buf);
|
||
|
|
+ if (u->manager->default_enable_memsw_limit) {
|
||
|
|
+ if (sw_val == CGROUP_LIMIT_MAX)
|
||
|
|
+ strncpy(buf, "-1\n", sizeof(buf));
|
||
|
|
+ else
|
||
|
|
+ xsprintf(buf, "%" PRIu64 "\n", sw_val);
|
||
|
|
+ (void) set_attribute_and_warn(u, "memory", "memory.memsw.limit_in_bytes", buf);
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
diff --git a/src/core/main.c b/src/core/main.c
|
||
|
|
index 7b3e6c4..e43dc2d 100644
|
||
|
|
--- a/src/core/main.c
|
||
|
|
+++ b/src/core/main.c
|
||
|
|
@@ -154,6 +154,7 @@ static bool arg_default_memory_accounting;
|
||
|
|
static bool arg_default_cpuset_accounting;
|
||
|
|
static bool arg_default_freezer_accounting;
|
||
|
|
static bool arg_default_tasks_accounting;
|
||
|
|
+static bool arg_default_enable_memsw_limit;
|
||
|
|
static TasksMax arg_default_tasks_max;
|
||
|
|
static bool arg_default_invalidate_cgroup;
|
||
|
|
static sd_id128_t arg_machine_id;
|
||
|
|
@@ -715,6 +716,7 @@ static int parse_config_file(void) {
|
||
|
|
{ "Manager", "DefaultCpusetAccounting", config_parse_bool, 0, &arg_default_cpuset_accounting },
|
||
|
|
{ "Manager", "DefaultFreezerAccounting", config_parse_bool, 0, &arg_default_freezer_accounting },
|
||
|
|
{ "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting },
|
||
|
|
+ { "Manager", "DefaultEnableMemswLimit", config_parse_bool, 0, &arg_default_enable_memsw_limit },
|
||
|
|
{ "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max },
|
||
|
|
{ "Manager", "DefaultInvalidateCgroup", config_parse_bool, 0, &arg_default_invalidate_cgroup },
|
||
|
|
{ "Manager", "CtrlAltDelBurstAction", config_parse_emergency_action, 0, &arg_cad_burst_action },
|
||
|
|
@@ -796,6 +798,7 @@ static void set_manager_defaults(Manager *m) {
|
||
|
|
m->default_cpuset_accounting = arg_default_cpuset_accounting;
|
||
|
|
m->default_freezer_accounting = arg_default_freezer_accounting;
|
||
|
|
m->default_tasks_accounting = arg_default_tasks_accounting;
|
||
|
|
+ m->default_enable_memsw_limit = arg_default_enable_memsw_limit;
|
||
|
|
m->default_tasks_max = arg_default_tasks_max;
|
||
|
|
m->default_invalidate_cgroup = arg_default_invalidate_cgroup;
|
||
|
|
m->default_oom_policy = arg_default_oom_policy;
|
||
|
|
@@ -2466,6 +2469,7 @@ static void reset_arguments(void) {
|
||
|
|
arg_default_cpuset_accounting = false;
|
||
|
|
arg_default_freezer_accounting = false;
|
||
|
|
arg_default_tasks_accounting = true;
|
||
|
|
+ arg_default_enable_memsw_limit = true;
|
||
|
|
arg_default_tasks_max = DEFAULT_TASKS_MAX;
|
||
|
|
arg_default_invalidate_cgroup = true;
|
||
|
|
arg_machine_id = (sd_id128_t) {};
|
||
|
|
diff --git a/src/core/manager.c b/src/core/manager.c
|
||
|
|
index 4b60927..ddd5c2d 100644
|
||
|
|
--- a/src/core/manager.c
|
||
|
|
+++ b/src/core/manager.c
|
||
|
|
@@ -748,6 +748,7 @@ int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager
|
||
|
|
.default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT,
|
||
|
|
.default_cpuset_accounting = false,
|
||
|
|
.default_tasks_accounting = true,
|
||
|
|
+ .default_enable_memsw_limit = true,
|
||
|
|
.default_tasks_max = TASKS_MAX_UNSET,
|
||
|
|
.default_invalidate_cgroup = true,
|
||
|
|
.default_timeout_start_usec = DEFAULT_TIMEOUT_USEC,
|
||
|
|
diff --git a/src/core/manager.h b/src/core/manager.h
|
||
|
|
index 9334429..40f7c7e 100644
|
||
|
|
--- a/src/core/manager.h
|
||
|
|
+++ b/src/core/manager.h
|
||
|
|
@@ -376,6 +376,8 @@ struct Manager {
|
||
|
|
bool default_tasks_accounting;
|
||
|
|
bool default_ip_accounting;
|
||
|
|
|
||
|
|
+ bool default_enable_memsw_limit;
|
||
|
|
+
|
||
|
|
TasksMax default_tasks_max;
|
||
|
|
usec_t default_timer_accuracy_usec;
|
||
|
|
bool default_invalidate_cgroup;
|
||
|
|
diff --git a/src/core/system.conf.in b/src/core/system.conf.in
|
||
|
|
index 2fe6f60..062a1fc 100644
|
||
|
|
--- a/src/core/system.conf.in
|
||
|
|
+++ b/src/core/system.conf.in
|
||
|
|
@@ -58,6 +58,7 @@
|
||
|
|
#DefaultCpusetAccounting=
|
||
|
|
#DefaultFreezerAccounting=no
|
||
|
|
#DefaultTasksAccounting=yes
|
||
|
|
+#DefaultEnableMemswLimit=yes
|
||
|
|
#DefaultTasksMax=80%
|
||
|
|
#DefaultLimitCPU=
|
||
|
|
#DefaultLimitFSIZE=
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|