From 56a2d693758acea46cc7d40533f642b0661108f9 Mon Sep 17 00:00:00 2001 From: xujing Date: Tue, 24 Dec 2024 16:20:03 +0800 Subject: [PATCH] add DefaultEnableMemswLimit support --- add-DefaultEnableMemswLimit-support.patch | 112 ++++++++++++++++++++++ systemd.spec | 6 +- 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 add-DefaultEnableMemswLimit-support.patch diff --git a/add-DefaultEnableMemswLimit-support.patch b/add-DefaultEnableMemswLimit-support.patch new file mode 100644 index 0000000..8980486 --- /dev/null +++ b/add-DefaultEnableMemswLimit-support.patch @@ -0,0 +1,112 @@ +From 4e150d944763459fd8c070d6f53a3ab02d2883f4 Mon Sep 17 00:00:00 2001 +From: xujing +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 + diff --git a/systemd.spec b/systemd.spec index da3eb1a..d9d8c06 100644 --- a/systemd.spec +++ b/systemd.spec @@ -25,7 +25,7 @@ Name: systemd Url: https://systemd.io/ Version: 249 -Release: 99 +Release: 100 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -792,6 +792,7 @@ Patch9058: embedded-add-noexec-mount-option-to-strenthen-tmp-pa.patch Patch9059: embedded-use-yocto-configs.patch Patch9060: embedded-add-cpuset-cgv1-and-freezer-cgv1-option.patch Patch9061: systemd-logind-add-log-to-display-devices.patch +Patch9062: add-DefaultEnableMemswLimit-support.patch Patch9801: Systemd-Add-sw64-architecture.patch Patch9802: 0029-Add-support-for-the-LoongArch-architecture.patch @@ -2246,6 +2247,9 @@ grep -q -E '^KEYMAP="?fi-latin[19]"?' /etc/vconsole.conf 2>/dev/null && /usr/bin/systemd-cryptenroll %changelog +* Tue Dec 24 2024 xujing - 249-100 +- add DefaultEnableMemswLimit support + * Tue Dec 24 2024 huyubiao - 249-99 - systemd-logind button_dispatch add log to display devices that triggered the button -- Gitee