Score:1

Unit user-.slice failed to load properly: Invalid argument

us flag

I have been trying to set up resource controls on 22.04.1 login node so users can't degrade the system by running anything too intensive. I looked at using cgroups but apparently since it's a systemd system, user-.slice is what I'm after. Unfortunately I can't even get the default service to launch.

❯ sudo systemctl status user-.slice
Warning: The unit file, source configuration file or drop-ins of user-.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
○ user-.slice - User Slice of UID
Loaded: error (Reason: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument)
Drop-In: /usr/lib/systemd/system/user-.slice.d
└─10-defaults.conf
Active: inactive (dead)
Docs: man:user@.service(5)

I can't see what argument is invalid and I have reloaded the units with sudo systemctl daemon-reload but it still says they've change...

❯ sudo systemctl daemon-reload
❯ sudo systemctl restart user-.slice
Failed to start user-.slice: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument
See system logs and 'systemctl status user-.slice' for details.
❯ systemctl status user-.slice
Warning: The unit file, source configuration file or drop-ins of user-.slice changed on disk. Run 'systemctl daemon-reload' to reload units.
○ user-.slice - User Slice of UID
Loaded: error (Reason: Unit user-.slice failed to load properly, please adjust/correct and reload service manager: Invalid argument)
Drop-In: /usr/lib/systemd/system/user-.slice.d
└─10-defaults.conf
Active: inactive (dead)
Docs: man:user@.service(5)

The main configs are currently the defaults:

❯ cat /usr/lib/systemd/system/user.slice
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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 and Session Slice
Documentation=man:systemd.special(7)
Before=slices.target
❯ cat /usr/lib/systemd/system/user-.slice.d/10-defaults.conf
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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
Documentation=man:user@.service(5)
After=systemd-user-sessions.service
StopWhenUnneeded=yes

[Slice]
TasksMax=33%

Ultimately I just want to add 2 settings for memory and cpu caps:

❯ cat 50-user-caps.conf
[Slice]
CPUQuota=400%
MemoryMax=4G

Any clue what's going on?

Answered by @steeldriver

You don't interact with the user-.slice service, but the user-UID.slice ones that automatically pick up the drop ins.

hr flag
I *think* the `Invalid Argument` is complaining about is the (missing) UID of the slice in the command itself (not the unit file(s)) - it works for me with `systemctl status user-1000.slice` or more generally `systemctl status user-$(id -u).slice`
SHawarden avatar
us flag
I'm trying to apply the slice to all users though, not just on a given uid. The documentation implies that `user-.slice` applies to everyone.
SHawarden avatar
us flag
@steeldriver Ahh, I see, The `user-.slice` service isn't actually a service at all. It automatically applies to each individual `user-UID.slice`... and is working perfectly. thank you! If you make this the answer I'll mark it.
Score:2
hr flag

I think the issue here is one of understanding the slice naming convention - in particular, to which slice the dash "belongs". From man systemd.slice:

   The name of the slice encodes the location in the tree. The name
   consists of a dash-separated series of names, which describes the path
   to the slice from the root slice. The root slice is named -.slice.
   Example: foo-bar.slice is a slice that is located within foo.slice,
   which in turn is located in the root slice -.slice.

So in the case of the user-slice hierarchy, the valid systemctl status commands are

  • systemctl status user-$(id -u).slice or for example systemctl status user-1000.slice

  • systemctl status user.slice

  • systemctl status -- -.slice for the root slice

where the -- in the case of the root slice is necessary to prevent -.slice being parsed as a command line option.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.