Bug 1718953

Summary: Layered slices are left in a "dead" state if slices are stopped that have child slices underneath
Product: Red Hat Enterprise Linux 7 Reporter: Kyle Walker <kwalker>
Component: systemdAssignee: David Tardon <dtardon>
Status: ON_QA --- QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: urgent    
Version: 7.6CC: bbreard, dtardon, fkrska, lnykryn, msekleta, ovasik, redhat_bugzilla, rmetrich, sreber, systemd-maint-list
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-219-69.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1729227 1729228 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1729227, 1729228    

Description Kyle Walker 2019-06-10 15:31:35 UTC
Description of problem:
 For nested slices, stopping of the parent results in the parent slice entering a "dead" state. Upstream releases result in the child and parent slices being removed without a "dead" state. 

Version-Release number of selected component (if applicable):
 systemd-219-62.el7_6.7.x86_64

How reproducible:
 Easily

Steps to Reproduce:
1. Start a few nested slices using "systemd-run"
    # systemd-run --slice first-second-third echo test

2. Verify that all are active
    # systemctl list-units --type slice --all first*

3. Stop the "first-second" slice
    # systemctl stop first-second.slice

4. Verify the slice states
    # systemctl list-units --type slice --all first*

Actual results:

    # systemd-run --slice first-second-third echo test
    Running as unit run-5416.service.

    # systemctl list-units --type slice --all first*
    UNIT                     LOAD   ACTIVE SUB    DESCRIPTION
    first-second-third.slice loaded active active first-second-third.slice
    first-second.slice       loaded active active first-second.slice
    first.slice              loaded active active first.slice

    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.

    3 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.

    # systemctl stop first-second.slice

    # systemctl list-units --type slice --all first*
    UNIT                     LOAD   ACTIVE   SUB    DESCRIPTION
    first-second-third.slice loaded active   active first-second-third.slice
    first-second.slice       loaded inactive dead   first-second.slice
    first.slice              loaded active   active first.slice

    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.

    3 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.

Expected results:

    # systemd-run --slice first-second-third.slice echo "test"
    Running as unit: run-rfa7d23674bad47259b4d31ea38911c15.service

    # systemctl list-units --type slice --all first*
    UNIT                     LOAD   ACTIVE SUB    DESCRIPTION                                                                                                                                                                                    
    first-second-third.slice loaded active active first-second-third.slice                                                                                                                                                                       
    first-second.slice       loaded active active first-second.slice                                                                                                                                                                             
    first.slice              loaded active active first.slice                                                                                                                                                                                        

    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.
    
    3 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.

    # systemctl stop first-second.slice

    # systemctl list-units --type slice --all first*
    UNIT        LOAD   ACTIVE SUB    DESCRIPTION                                                                                                                                                                                                 
    first.slice loaded active active first.slice                                                                                                                                                                                                 
    
    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.
    
    1 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.

Additional info:
 I initially suspected that the following commit was responsible:

  commit 8c8da0e0cb498245c765732cf9caa081a70c560f
  Author: Lennart Poettering <lennart@poettering.net>
  Date:   Tue Sep 29 13:06:28 2015 +0200

    core: add a "Requires=" dependency between units and the slices they are located in
    
    We place the processes we fork off in the cgroup anyway, and we probably
    shouldn't be able to get that far if we couldn't set up the slice due to
    resource problems or unmet conditions. Hence upgrade the dependency
    between units and the slices they are located in from Wants= to
    Requires=.

Test outcome with the above patch results in the 3rd generation slice being stopped, but the 2nd generation remains in the "dead" state:

    # systemctl list-units --type slice --all first*
    UNIT               LOAD   ACTIVE   SUB    DESCRIPTION
    first-second.slice loaded inactive dead   first-second.slice
    first.slice        loaded active   active first.slice

    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.

    2 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.


This did have the effect of stopping the child slice, but it still left the parent in the dead state. The failure condition here is needing to be addressed as OpenShift workloads will issue stop operations on slices without necessarily stopping the child slices. This is necessary to avoid a unit leakage condition that will _eventually_ result in E2BIG due to MANAGER_MAX_NAMES.

Comment 2 David Tardon 2019-06-11 16:40:29 UTC
Yeah. Units with cyclic references are not garbage collected properly. This was fixed by https://github.com/systemd/systemd/pull/8175 . It doesn't look too hard to backport, so I'll give it a try...

Comment 3 David Tardon 2019-06-17 08:25:07 UTC
PR: https://github.com/systemd-rhel/rhel-7/pull/21

Comment 4 David Tardon 2019-06-20 15:46:15 UTC
Testing rpms: http://people.redhat.com/dtardon/systemd/bz1718953-nested-slices/

Comment 5 Sam Mingo 2019-06-20 18:37:45 UTC
If we were to try these RPMs out, what would be the recommended way of installing them?

Comment 9 Lukáš Nykrýn 2019-07-11 13:29:39 UTC
fix merged to github master branch -> https://github.com/systemd-rhel/rhel-7/pull/21 -> post

Comment 12 Lukáš Nykrýn 2019-07-24 13:26:58 UTC
fix merged to github rhel-7.6 branch -> https://github.com/systemd-rhel/rhel-7/pull/31 -> post