RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1828758 - "systemctl list-unit-files" kills the system usability
Summary: "systemctl list-unit-files" kills the system usability
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd
Version: 7.8
Hardware: All
OS: Linux
urgent
urgent
Target Milestone: rc
: ---
Assignee: David Tardon
QA Contact: Frantisek Sumsal
URL:
Whiteboard:
: 1947190 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-04-28 10:17 UTC by Renaud Métrich
Modified: 2024-12-20 19:03 UTC (History)
18 users (show)

Fixed In Version: systemd-219-78.el7_9.5
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-01-11 17:35:51 UTC
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github redhat-plumbers systemd-rhel7 pull 135 0 None open install: refactor find_symlinks() and don't search for symlinks recur… 2021-11-19 18:20:30 UTC
Github systemd systemd pull 18943 0 None closed install: refactor find_symlinks() and don't search for symlinks recursively 2021-05-12 08:11:00 UTC
Red Hat Product Errata RHBA-2022:0066 0 None None None 2022-01-11 17:35:55 UTC

Description Renaud Métrich 2020-04-28 10:17:39 UTC
Description of problem:

On large systems with many users connecting to it (e.g. ~1000 users, but can be reproduced with less users, depending on how many sessions they use), a simple "systemctl list-unit-files" query freezes systemd for an enormous amount of time (>= 50 seconds), preventing regular users to use the system:
- they cannot connect to it in less than 25 seconds
- no event is handled by systemd (clean ups, etc)

The reason behind this is systemd not off-loading the "ListUnitFiles" query which is heavily I/O consuming (it reads *all* unit configuration files).

Version-Release number of selected component (if applicable):

systemd-219 but also systemd-239 (RHEL8) and later


How reproducible:

Always


Steps to Reproduce:
1. Create 1000 users in a VM with 8GB of memory / 4 CPUs

  # for i in $(seq 1 1000); do user="user$(printf "%04d" $i)"; echo $user; useradd $user; echo "user" | passwd --stdin $user; done

2. Copy root's key to user0001's authorized_keys

  # ssh-copy-id user0001@localhost
  Password: "user"

3. Create all other authorized_keys files

  # for i in $(seq 2 1000); do user="user$(printf "%04d" $i)"; cp -r user0001/.ssh $user; chown -R $user:$user $user/.ssh; done

4. Spawn 1000 ssh sessions

  # for i in $(seq 1 1000); do user="user$(printf "%04d" $i)"; echo "$user"; ssh -f $user@localhost 'sleep 3600'; done

5. Execute "list-unit-files"

  # systemctl list-unit-files --no-pager
  Failed to list unit files: Connection timed out


Actual results:

systemd not functional ~50 seconds!

Expected results:

systemd still doing its usual job


Additional info:

The "ListUnitFiles" is only an example, we suppose that there are other operations (DBus or others) that affect systemd as well, but so far we weren't able to find those yet.

Comment 2 Frantisek Sumsal 2020-05-22 13:29:25 UTC
Possibly related upstream issue: https://github.com/systemd/systemd/issues/14730

Comment 6 Chris Williams 2020-11-11 21:40:03 UTC
Red Hat Enterprise Linux 7 shipped it's final minor release on September 29th, 2020. 7.9 was the last minor releases scheduled for RHEL 7.
From intial triage it does not appear the remaining Bugzillas meet the inclusion criteria for Maintenance Phase 2 and will now be closed. 

From the RHEL life cycle page:
https://access.redhat.com/support/policy/updates/errata#Maintenance_Support_2_Phase
"During Maintenance Support 2 Phase for Red Hat Enterprise Linux version 7,Red Hat defined Critical and Important impact Security Advisories (RHSAs) and selected (at Red Hat discretion) Urgent Priority Bug Fix Advisories (RHBAs) may be released as they become available."

If this BZ was closed in error and meets the above criteria please re-open it flag for 7.9.z, provide suitable business and technical justifications, and follow the process for Accelerated Fixes:
https://source.redhat.com/groups/public/pnt-cxno/pnt_customer_experience_and_operations_wiki/support_delivery_accelerated_fix_release_handbook  

Feature Requests can re-opened and moved to RHEL 8 if the desired functionality is not already present in the product. 

Please reach out to the applicable Product Experience Engineer[0] if you have any questions or concerns.  

[0] https://bugzilla.redhat.com/page.cgi?id=agile_component_mapping.html&product=Red+Hat+Enterprise+Linux+7

Comment 7 Renaud Métrich 2021-05-06 09:19:02 UTC
*** Bug 1947190 has been marked as a duplicate of this bug. ***

Comment 8 Renaud Métrich 2021-05-06 09:26:10 UTC
I'm reopening this because this is a critical issue, not only on systems with many users, but also on systems having heavy docker workloads (e.g. 1500 scopes).

It appears that the **list-unit-files** operations ends up having some kind of O(n^2) algorithm which doesn't scale.
I didn't dig completely into the code but observed from backtrace and reproducer that the check on the files is not linear, which is a real problem for scalability.
I see something like below:

~~~
- method_list_unit_files()
  - for all scope units
    - find_symlinks_in_scope(<scopeX>)
      - for all scope units
        - find_symlinks_fd(<scopeY.d>)
~~~


Simple reproducer using scopes:

1. I start 100 scopes and check the number of **fcntl()** operations

  ~~~
  # for i in $(seq 1 100); do systemd-run --scope --unit="runscope$i" /bin/sleep 3600 & sleep 0.01; done
  
  # strace -ttTvyy -o systemd_100scopes.strace -e fcntl -s 256 -p 1 &
  
  # systemctl list-unit-files >/dev/null
  Failed to list unit files: Connection timed out 
  ~~~
  
  I wait for the operation to complete on the systemd side: even though the `systemctl` command exited in timeout, the operation is still ongoing. Then I check the strace:
  
  ~~~
  # grep -c "F_SETFD, FD_CLOEXEC" systemd_100scopes.strace
  242841
  
  # grep -m1 "F_SETFD, FD_CLOEXEC" systemd_100scopes.strace
  10:36:19.522057 fcntl(16</etc/systemd/system>, F_SETFD, FD_CLOEXEC) = 0 <0.000004>
  # tac systemd_100scopes.strace | grep -m1 "F_SETFD, FD_CLOEXEC"
  10:36:46.140838 fcntl(17</run/systemd/system/user-0.slice.d>, F_SETFD, FD_CLOEXEC) = 0 <0.000004>
  ~~~

  Here above, the number of operations is already crazy (242841) and systemd took 27 seconds to perform the operation on my system (under strace, which slows down the process).
  

2. Now I redo the test with 200 more scopes (total 300 scopes)

  ~~~
  # for i in $(seq 101 300); do systemd-run --scope --unit="runscope$i" /bin/sleep 3600 & sleep 0.01; done
  
  # strace -ttTvyy -o systemd_300scopes.strace -e fcntl -s 256 -p 1 &
  
  # systemctl list-unit-files >/dev/null
  Failed to list unit files: Connection timed out 
  ~~~
  
  Wait for the operation to complete on the systemd side, then check the strace:
  
  ~~~
  # grep -c "F_SETFD, FD_CLOEXEC" systemd_300scopes.strace
  690041

  # grep -m1 "F_SETFD, FD_CLOEXEC" systemd_300scopes.strace
  10:41:31.842921 fcntl(16</etc/systemd/system>, F_SETFD, FD_CLOEXEC) = 0 <0.000005>
  # tac systemd_300scopes.strace | grep -m1 "F_SETFD, FD_CLOEXEC"
  10:42:42.399127 fcntl(17</run/systemd/system/user-0.slice.d>, F_SETFD, FD_CLOEXEC) = 0 <0.000004>
  ~~~

  Here above, the number of operations increases by a 3 factor and systemd took more than one minute to perform the operation on my system (3 times the time for 100 scopes).


Without stracing, with 1700 scopes, I see that systemd is not responsive for more than 35 seconds.

Comment 11 Dwayne 2021-05-06 16:37:05 UTC
Setting the Customer Flag = Yes; per EN-40415

Comment 12 David Tardon 2021-05-12 08:11:04 UTC
https://github.com/systemd/systemd/pull/18943 should reduce the time ~3-4 times. I uploaded test rpms that include that patch to http://people.redhat.com/dtardon/systemd/bz1828758-list-unit-files/ , in case anyone wants to try that.

Comment 16 Plumber Bot 2021-11-25 12:57:05 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel7/pull/135

Comment 20 Plumber Bot 2021-12-01 12:46:46 UTC
fix merged to github master branch -> https://github.com/redhat-plumbers/systemd-rhel7/pull/137

Comment 26 errata-xmlrpc 2022-01-11 17:35:51 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:0066


Note You need to log in before you can comment on or make changes to this bug.