From 284149392755f086d0a714071c33aa609e61505e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 7 Dec 2017 22:25:26 +0100 Subject: [PATCH] Use a dash-truncated drop-in for user-%j.slice configuration This removes the UserTasksMax= setting in logind.conf. Instead, the generic TasksMax= setting on the slice should be used. Instead of a transient unit we use a drop-in to tweak the default definition of a .slice. It's better to use the normal unit mechanisms instead of creating units on the fly. This will also make it easier to start user@.service independently of logind, or set additional settings like MemoryMax= for user slices. The setting in logind is removed, because otherwise we would have two sources of "truth": the slice on disk and the logind config. Instead of trying to coordinate those two sources of configuration (and maintainer overrides to both), let's just convert to the new one fully. Right now now automatic transition mechanism is provided. logind will emit a hint when it encounters the setting, but otherwise it will be ignored. Fixes #2556. --- man/logind.conf.xml | 11 ---- src/login/logind-dbus.c | 16 +++++- src/login/logind-gperf.gperf | 48 ++++++++--------- src/login/logind-user.c | 81 ++++------------------------ src/login/logind-user.h | 2 + src/login/logind.conf.in | 1 - src/login/logind.h | 1 - units/meson.build | 3 ++ units/user-.slice.d/10-defaults.conf | 15 ++++++ 9 files changed, 68 insertions(+), 110 deletions(-) create mode 100644 units/user-.slice.d/10-defaults.conf diff --git a/man/logind.conf.xml b/man/logind.conf.xml index 9e21c0b218f..a35faf15c53 100644 --- a/man/logind.conf.xml +++ b/man/logind.conf.xml @@ -325,17 +325,6 @@ systemd-logind. - - UserTasksMax= - - Sets the maximum number of OS tasks each user may run concurrently. This controls the - TasksMax= setting of the per-user slice unit, see - systemd.resource-control5 - for details. If assigned the special value infinity, no tasks limit is applied. - Defaults to 33%, which equals 10813 with the kernel's defaults on the host, but might be smaller in - OS containers. - - RemoveIPC= diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index d92437b67f3..7078e67dd4a 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -332,6 +332,20 @@ static int property_get_current_inhibitors( return sd_bus_message_append(reply, "t", (uint64_t) hashmap_size(m->inhibitors)); } +static int property_get_compat_user_tasks_max( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + assert(reply); + + return sd_bus_message_append(reply, "t", CGROUP_LIMIT_MAX); +} + static int method_get_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_free_ char *p = NULL; Manager *m = userdata; @@ -2720,7 +2734,7 @@ const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("NCurrentInhibitors", "t", property_get_current_inhibitors, 0, 0), SD_BUS_PROPERTY("SessionsMax", "t", NULL, offsetof(Manager, sessions_max), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("NCurrentSessions", "t", property_get_current_sessions, 0, 0), - SD_BUS_PROPERTY("UserTasksMax", "t", NULL, offsetof(Manager, user_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("UserTasksMax", "t", property_get_compat_user_tasks_max, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_METHOD("GetSession", "s", "o", method_get_session, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetSessionByPID", "u", "o", method_get_session_by_pid, SD_BUS_VTABLE_UNPRIVILEGED), diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index f6f57526f61..c85339dcd35 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -17,27 +17,27 @@ struct ConfigPerfItem; %struct-type %includes %% -Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) -Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) -Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) -Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) -Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) -Login.InhibitDelayMaxSec, config_parse_sec, 0, offsetof(Manager, inhibit_delay_max) -Login.HandlePowerKey, config_parse_handle_action, 0, offsetof(Manager, handle_power_key) -Login.HandleSuspendKey, config_parse_handle_action, 0, offsetof(Manager, handle_suspend_key) -Login.HandleHibernateKey, config_parse_handle_action, 0, offsetof(Manager, handle_hibernate_key) -Login.HandleLidSwitch, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch) -Login.HandleLidSwitchExternalPower,config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch_ep) -Login.HandleLidSwitchDocked, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch_docked) -Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited) -Login.SuspendKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, suspend_key_ignore_inhibited) -Login.HibernateKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, hibernate_key_ignore_inhibited) -Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited) -Login.HoldoffTimeoutSec, config_parse_sec, 0, offsetof(Manager, holdoff_timeout_usec) -Login.IdleAction, config_parse_handle_action, 0, offsetof(Manager, idle_action) -Login.IdleActionSec, config_parse_sec, 0, offsetof(Manager, idle_action_usec) -Login.RuntimeDirectorySize, config_parse_tmpfs_size, 0, offsetof(Manager, runtime_dir_size) -Login.RemoveIPC, config_parse_bool, 0, offsetof(Manager, remove_ipc) -Login.InhibitorsMax, config_parse_uint64, 0, offsetof(Manager, inhibitors_max) -Login.SessionsMax, config_parse_uint64, 0, offsetof(Manager, sessions_max) -Login.UserTasksMax, config_parse_user_tasks_max,0, offsetof(Manager, user_tasks_max) +Login.NAutoVTs, config_parse_n_autovts, 0, offsetof(Manager, n_autovts) +Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) +Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) +Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) +Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) +Login.InhibitDelayMaxSec, config_parse_sec, 0, offsetof(Manager, inhibit_delay_max) +Login.HandlePowerKey, config_parse_handle_action, 0, offsetof(Manager, handle_power_key) +Login.HandleSuspendKey, config_parse_handle_action, 0, offsetof(Manager, handle_suspend_key) +Login.HandleHibernateKey, config_parse_handle_action, 0, offsetof(Manager, handle_hibernate_key) +Login.HandleLidSwitch, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch) +Login.HandleLidSwitchExternalPower, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch_ep) +Login.HandleLidSwitchDocked, config_parse_handle_action, 0, offsetof(Manager, handle_lid_switch_docked) +Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited) +Login.SuspendKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, suspend_key_ignore_inhibited) +Login.HibernateKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, hibernate_key_ignore_inhibited) +Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited) +Login.HoldoffTimeoutSec, config_parse_sec, 0, offsetof(Manager, holdoff_timeout_usec) +Login.IdleAction, config_parse_handle_action, 0, offsetof(Manager, idle_action) +Login.IdleActionSec, config_parse_sec, 0, offsetof(Manager, idle_action_usec) +Login.RuntimeDirectorySize, config_parse_tmpfs_size, 0, offsetof(Manager, runtime_dir_size) +Login.RemoveIPC, config_parse_bool, 0, offsetof(Manager, remove_ipc) +Login.InhibitorsMax, config_parse_uint64, 0, offsetof(Manager, inhibitors_max) +Login.SessionsMax, config_parse_uint64, 0, offsetof(Manager, sessions_max) +Login.UserTasksMax, config_parse_compat_user_tasks_max, 0, offsetof(Manager, user_tasks_max) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 379d8d0cdd7..01b602dbc49 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -368,36 +368,6 @@ fail: return r; } -static int user_start_slice(User *u) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - const char *description; - char *job; - int r; - - assert(u); - - u->slice_job = mfree(u->slice_job); - description = strjoina("User Slice of ", u->name); - - r = manager_start_slice( - u->manager, - u->slice, - description, - "systemd-logind.service", - "systemd-user-sessions.service", - u->manager->user_tasks_max, - &error, - &job); - if (r >= 0) - u->slice_job = job; - else if (!sd_bus_error_has_name(&error, BUS_ERROR_UNIT_EXISTS)) - /* we don't fail due to this, let's try to continue */ - log_error_errno(r, "Failed to start user slice %s, ignoring: %s (%s)", - u->slice, bus_error_message(&error, r), error.name); - - return 0; -} - static int user_start_service(User *u) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *job; @@ -453,11 +423,6 @@ int user_start(User *u) { return r; } - /* Create cgroup */ - r = user_start_slice(u); - if (r < 0) - return r; - /* Save the user data so far, because pam_systemd will read the * XDG_RUNTIME_DIR out of it while starting up systemd --user. * We need to do user_save_internal() because we have not @@ -858,8 +823,8 @@ int config_parse_tmpfs_size( return 0; } -int config_parse_user_tasks_max( - const char* unit, +int config_parse_compat_user_tasks_max( + const char *unit, const char *filename, unsigned line, const char *section, @@ -870,45 +835,17 @@ int config_parse_user_tasks_max( void *data, void *userdata) { - uint64_t *m = data; - uint64_t k; - int r; - assert(filename); assert(lvalue); assert(rvalue); assert(data); - if (isempty(rvalue)) { - *m = system_tasks_max_scale(DEFAULT_USER_TASKS_MAX_PERCENTAGE, 100U); - return 0; - } - - if (streq(rvalue, "infinity")) { - *m = CGROUP_LIMIT_MAX; - return 0; - } - - /* Try to parse as percentage */ - r = parse_percent(rvalue); - if (r >= 0) - k = system_tasks_max_scale(r, 100U); - else { - - /* If the passed argument was not a percentage, or out of range, parse as byte size */ - - r = safe_atou64(rvalue, &k); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse tasks maximum, ignoring: %s", rvalue); - return 0; - } - } - - if (k <= 0 || k >= UINT64_MAX) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Tasks maximum out of range, ignoring: %s", rvalue); - return 0; - } - - *m = k; + log_syntax(unit, LOG_NOTICE, filename, line, 0, + "Support for option %s= has been removed.", + lvalue); + log_info("Hint: try creating /etc/systemd/system/user-.slice/50-limits.conf with:\n" + " [Slice]\n" + " TasksMax=%s", + rvalue); return 0; } diff --git a/src/login/logind-user.h b/src/login/logind-user.h index d95059d5a91..18a80b3fdfd 100644 --- a/src/login/logind-user.h +++ b/src/login/logind-user.h @@ -79,3 +79,5 @@ UserState user_state_from_string(const char *s) _pure_; int bus_user_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error); int bus_user_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error); + +int config_parse_compat_user_tasks_max(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); diff --git a/src/login/logind.conf.in b/src/login/logind.conf.in index 40a77dc7be9..1029e29bc73 100644 --- a/src/login/logind.conf.in +++ b/src/login/logind.conf.in @@ -35,4 +35,3 @@ #RemoveIPC=yes #InhibitorsMax=8192 #SessionsMax=8192 -#UserTasksMax=33% diff --git a/src/login/logind.h b/src/login/logind.h index be2963c256d..7470516fba2 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -182,7 +182,6 @@ int manager_set_lid_switch_ignore(Manager *m, usec_t until); int config_parse_n_autovts(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_tmpfs_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); -int config_parse_user_tasks_max(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret); int manager_get_user_from_creds(Manager *m, sd_bus_message *message, uid_t uid, sd_bus_error *error, User **ret); diff --git a/units/meson.build b/units/meson.build index 5e454ab3b18..1c89f369570 100644 --- a/units/meson.build +++ b/units/meson.build @@ -304,6 +304,9 @@ foreach tuple : units endif endforeach +install_data('user-.slice.d/10-defaults.conf', + install_dir : systemunitdir + '/user-.slice.d') + ############################################################ meson.add_install_script(meson_make_symlink, diff --git a/units/user-.slice.d/10-defaults.conf b/units/user-.slice.d/10-defaults.conf new file mode 100644 index 00000000000..95ab11b30be --- /dev/null +++ b/units/user-.slice.d/10-defaults.conf @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=User Slice of UID %j +After=systemd-user-sessions.service + +[Slice] +TasksMax=33%