FeralInteractive / gamemode

Optimise Linux system performance on demand
BSD 3-Clause "New" or "Revised" License
4.67k stars 184 forks source link

gamemoderun does not renice all processes #457

Open FLAGEL opened 8 months ago

FLAGEL commented 8 months ago

Describe the bug gamemoderun does not renice all processes it should. This happens with Proton-games in Steam Flatpak, unclear if it works as intended outside of a Flatpak sandbox.

To Reproduce 1) Launch a Steam+Proton game (e.g. Worms Armageddon) with launch option: gamemoderun %command% 2) List gamemode-processes within Flatpak with gamemodelist (not available in Steam Flatpak, running it as shell script). Note that only one process (reaper) has been properly reniced to -5:

[📦 com.valvesoftware.Steam ~]$ find /proc -maxdepth 2 -type f -user "${USER}" -readable -name maps -exec   awk -- '$0 ~ /libgamemodeauto\.so\.0/ {pid=FILENAME; gsub("[^0-9]", "", pid); print pid;nextfile}' {} +   | xargs | xargs -I{} -- ps -o pid,ppid,user,ni,psr,comm --pid '{}'
    PID    PPID USER      NI PSR COMMAND
  71621   28806 user      -5   7 reaper
  71732   71698 user       0   3 python3
  71734   71732 user       0   3 steam.exe
  71736   71698 user       0   4 wineserver
  71740   71698 user       0   2 services.exe
  71743   71698 user       0   1 winedevice.exe
  71753   71698 user       0   6 winedevice.exe
  71766   71698 user       0   1 plugplay.exe
  71772   71698 user       0   0 svchost.exe
  71780   71698 user       0  11 conhost.exe
  71782   71698 user       0   0 explorer.exe
  71791   71698 user       0   8 rpcss.exe
  71801   71698 user       0   5 tabtip.exe
  71818   71698 user       0   3 WA.exe

3) The process-tree makes it clear what is going on:

[📦 com.valvesoftware.Steam ~]$ ps --forest -eo pid,ni,pri,psr,comm
    PID  NI PRI PSR COMMAND
  71697   0  19   6 bwrap
  71698   0  19   6  \_ pressure-vessel
  71732   0  19   3      \_ python3
  71734   0  19   3      |   \_ steam.exe
  71736   0  19   9      \_ wineserver
  71740   0  19   2      \_ services.exe
  71743   0  19   1      \_ winedevice.exe
  71753   0  19   6      \_ winedevice.exe
  71766   0  19   1      \_ plugplay.exe
  71772   0  19   0      \_ svchost.exe
  71780   0  19  11      \_ conhost.exe
  71782   0  19   3      \_ explorer.exe
  71791   0  19   8      \_ rpcss.exe
  71801   0  19   5      \_ tabtip.exe
  71818   0  19  10      \_ WA.exe
      1   0  19   5 bwrap
      2   0  19   2 bash
  28700   0  19   7  \_ bash
  28806   0  19   9  |   \_ steam
  28839   0  19   0  |       \_ steamwebhelper
  28869   0  19   0  |       |   \_ steamwebhelper
  28882   0  19   5  |       |   |   \_ steamwebhelper
  28870   0  19   1  |       |   \_ steamwebhelper
  28964   0  19   1  |       |   |   \_ steamwebhelper
  30072   5  14   0  |       |   |   \_ steamwebhelper
  71861   5  14  10  |       |   |   \_ steamwebhelper
  28918   0  19  10  |       |   \_ steamwebhelper
  44019   0  19  11  |       |   \_ steamwebhelper
  28990   0  19   0  |       \_ steam-runtime-l
  71621  -5  24   7  |       \_ reaper
  71622  -5  24   6  |       |   \_ steam-runtime-l
  71851   0  19  11  |       \_ gameoverlayui
  71954   0  19   6  \_ ps

Possible solution 1) Reuse gamemodelist script to renice relevant processes:

[📦 com.valvesoftware.Steam ~]$ find /proc -maxdepth 2 -type f -user "${USER}" -readable -name maps -exec   awk -- '$0 ~ /libgamemodeauto\.so\.0/ {pid=FILENAME; gsub("[^0-9]", "", pid); print pid;nextfile}' {} + | xargs renice --priority -5 -p
71621 (process ID) old priority -5, new priority -5
71732 (process ID) old priority 0, new priority -5
71734 (process ID) old priority 0, new priority -5
71736 (process ID) old priority 0, new priority -5
71740 (process ID) old priority 0, new priority -5
71743 (process ID) old priority 0, new priority -5
71753 (process ID) old priority 0, new priority -5
71766 (process ID) old priority 0, new priority -5
71772 (process ID) old priority 0, new priority -5
71780 (process ID) old priority 0, new priority -5
71782 (process ID) old priority 0, new priority -5
71791 (process ID) old priority 0, new priority -5
71801 (process ID) old priority 0, new priority -5
71818 (process ID) old priority 0, new priority -5

2) Result of above in process tree:

[📦 com.valvesoftware.Steam ~]$ ps --forest -eo pid,ni,pri,psr,comm
    PID  NI PRI PSR COMMAND
  71697   0  19   6 bwrap
  71698   0  19   6  \_ pressure-vessel
  71732  -5  24   3      \_ python3
  71734  -5  24   3      |   \_ steam.exe
  71736  -5  24   0      \_ wineserver
  71740  -5  24   2      \_ services.exe
  71743  -5  24   1      \_ winedevice.exe
  71753  -5  24   6      \_ winedevice.exe
  71766  -5  24   1      \_ plugplay.exe
  71772  -5  24   0      \_ svchost.exe
  71780  -5  24  11      \_ conhost.exe
  71782  -5  24   6      \_ explorer.exe
  71791  -5  24   8      \_ rpcss.exe
  71801  -5  24   5      \_ tabtip.exe
  71818  -5  24   0      \_ WA.exe
      1   0  19   5 bwrap
      2   0  19  10 bash
  28700   0  19   7  \_ bash
  28806   0  19   2  |   \_ steam
  28839   0  19   4  |       \_ steamwebhelper
  28869   0  19   0  |       |   \_ steamwebhelper
  28882   0  19  10  |       |   |   \_ steamwebhelper
  28870   0  19   1  |       |   \_ steamwebhelper
  28964   0  19  10  |       |   |   \_ steamwebhelper
  30072   5  14   0  |       |   |   \_ steamwebhelper
  71861   5  14  11  |       |   |   \_ steamwebhelper
  28918   0  19  10  |       |   \_ steamwebhelper
  44019   0  19  11  |       |   \_ steamwebhelper
  28990   0  19   0  |       \_ steam-runtime-l
  71621  -5  24   7  |       \_ reaper
  71622  -5  24   6  |       |   \_ steam-runtime-l
  71851   0  19  10  |       \_ gameoverlayui
  72123   0  19   7  \_ ps

Expected behavior Note that this behavior is not seen with native Linux games launched within the Steam Flatpak.

[📦 com.valvesoftware.Steam ~]$ find /proc -maxdepth 2 -type f -user "${USER}" -readable -name maps -exec   awk -- '$0 ~ /libgamemodeauto\.so\.0/ {pid=FILENAME; gsub("[^0-9]", "", pid); print pid;nextfile}' {} +   | xargs | xargs -I{} -- ps -o pid,ppid,user,ni,psr,comm --pid '{}'
    PID    PPID USER      NI PSR COMMAND
  72209   28806 user      -5   1 reaper
  72210   72209 user      -5   7 hl.sh
  72213   72210 user      -5   0 hl_linux

System Info (please complete the following information): [1] com.valvesoftware.Steam 1.0.0.78, Proton 8.0-4 or GE-Proton8-25 [2] Linux host 6.6.8-arch1-1 https://github.com/FeralInteractive/gamemode/pull/1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000 x86_64 GNU/Linux [3] flatpak 1:1.15.6-1, gamemode 1.8.1-1, dbus 1.14.10-1