lowleveldesign / process-governor

This application allows you to put various limits on Windows processes.
MIT License
627 stars 62 forks source link

Can't seem to get Working Set limiting working for Anno 1800 #27

Closed Nicholas-Steel closed 3 years ago

Nicholas-Steel commented 3 years ago

If I try it with a BAT file and run the BAT file as an administrator the game closes almost immediately, if I try it with the Install parameter the game will persist as a Process but in a broken state with very little RAM used and no way to close it due to a lack of permissions to interact with the process.

The game seems to use around 7GB's of Active Private Working Set and will exhaust all remaining RAM as Working Set before commencing gameplay. My goal was to limit the games Working Set so that there was around 1GB's of RAM left for other tasks on the computer to utilize/minimize the amount of paging needed when multi-tasking (similar to what the Xbox One, Xbox Series, PS4 and PS5 gaming consoles do).

I have 16GB's of RAM.

procgov64.exe -m=15G Anno1800.exe "D:\Anno 1800\Bin\Win64\procgov64.exe" --maxws=9G --minws=9G Anno1800.exe (elevated command prompt)

Both of these will launch the game, however the game is not constrained in memory usage. Adding the -r parameter causes the game to not open.

Windows 10 21H1

lowleveldesign commented 3 years ago

The -r option propagates the limits to child processes. If you skip it, the child process will not be constrained and that explains why you see the game running. Could you please record a procmon trace with and without the -r option and share it with me? I would like to see what processes are launched. There is a chance too that the game breaks because it does not have enough free memory when run under procgov.

Nicholas-Steel commented 3 years ago

Does Procgov prevent a program from spilling over in to Swap/Page File? I was thinking ProcGov only controlled the amount of physical RAM the program would see as available and the influenced program would naturally start using the Paging File once it runs out of the RAM it thinks is available (assuming there is enough available RAM for the critical portions of the program to occupy).

Hmmm, should I be using Filtering for Procmon or just capture every processes activity?

lowleveldesign commented 3 years ago

You're right that when you limit the working set, procgov will apply a constraint only on the amount of used physical memory by the process. However, this still could cause problems in the target process. Btw., are there any logs in the Event Viewer about the error?

For the procmon, let's first enable only the process/thread activity: image

Nicholas-Steel commented 3 years ago

Gonna take a moment to compress the data.

Nicholas-Steel commented 3 years ago

You can download the traces with and without -r here https://mega.nz/file/bt4ADQBL#JH_UsX2VicCszx6oG3bGR8IHWnHmlc34oRptQrHP33Y

lowleveldesign commented 3 years ago

Please also upload or copy-paste the G:\Ubisoft Games\logs\aux_r1_log.txt log file (after running with -r option). Make sure it does not contain anything private. I see that Anno1800.exe can't start UbisoftGameLauncher.exe and it logs something to this file. Maybe it's the error message :)

Nicholas-Steel commented 3 years ago

aux_r1_log.txt

[13796]  2021-09-16 04:22:12      [15232]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[12900]  2021-09-16 19:44:04      [ 1584]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[ 1320]  2021-09-16 19:46:26      [ 6380]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[ 9384]  2021-09-16 19:47:22      [13276]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[11000]  2021-09-16 19:47:45      [10664]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[ 1460]  2021-09-16 19:49:46      [ 1232]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[ 8908]  2021-09-16 19:58:51      [ 6324]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450
[11064]  2021-09-18 15:40:32      [10196]      ERROR      Process.cpp (118)                                Failed to start exe G:\Ubisoft Games\UbisoftGameLauncher.exe workdir G:\Ubisoft Games\ error=1450

I doubt this will be helpful but here it is. Wouldn't surprise me if it's some kinda anti-tamper/DRM/anti-debugging system stopping it.

lowleveldesign commented 3 years ago

Actually, the error helps a lot. The 1450 error means ERROR_NO_SYSTEM_RESOURCES. I just noticed that you set the --minws to a very high value. I'm unsure how setting minimum working set impacts the child processes. Could you try setting minws to something smaller, for example, -r --minws 1M --maxws 9G? Does it change anything?

Nicholas-Steel commented 3 years ago

I did try that before, but I kept getting an error from the Governor program until I made the min and max match.

lowleveldesign commented 3 years ago

Hmm, that's strange. I was able to reproduce the error 1450 with notepad when setting --minws 8G --maxws 8G and starting a child process. But when I switched to --minws 1M --maxws 8G everything worked. Could you specify what's the procgov error when you set this small --minws value?

Nicholas-Steel commented 3 years ago

You're right, it works. I'm thinking I may have done something dumb and set the Maximum to 1MB and Minimum to 9GB when originally testing.

Thank you very much for the assistance, it's been greatly appreciated. I'll let the game run for a while to ensure the limit is being applied, at the moment it's fluctuating around 8.5 to 9.5GB's Working Set. Not surprising that there's a bit of looseness with the limit considering how programs use RAM. 5e6bc9bc-ac0e-49a0-8239-e6df71afcc45

image

Nicholas-Steel commented 3 years ago

What does Error Code 5 mean? It's added to the "game_starter_log.txt" in Ubisoft Connect's log folder when I try to apply any limit today. Yesterday and day before that it was working fine via Process Governor.

The game still works fine without Process Governor.

[ 7456]  2021-09-20 16:14:26      [13948]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[ 7456]  2021-09-20 16:14:26      [13948]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[ 4956]  2021-09-20 16:15:18      [ 9896]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[ 4956]  2021-09-20 16:15:18      [ 9896]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[  812]  2021-09-20 16:16:23      [15200]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[  812]  2021-09-20 16:16:23      [15200]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[10744]  2021-09-20 16:18:35      [ 4108]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[10744]  2021-09-20 16:18:35      [ 4108]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[ 7772]  2021-09-20 16:21:29      [14356]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[ 7772]  2021-09-20 16:21:29      [14356]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[ 8304]  2021-09-20 16:24:13      [10744]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[ 8304]  2021-09-20 16:24:13      [10744]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
[ 2968]  2021-09-20 16:28:15      [ 5272]      ERROR      GameStarter.cpp (201)                            Failed to start Uplay executable, error code: 5
[ 2968]  2021-09-20 16:28:15      [ 5272]      ERROR      UplayConnection.cpp (138)                        Failed to start Uplay           
lowleveldesign commented 3 years ago

It's access denied which usually indicates that the process does not have access to a resource. I am not sure how this relates to procgov. Do you apply only the memory limit? Do you start the game under the same user?

Nicholas-Steel commented 3 years ago

I just make a Batch file with this content

"D:\Anno 1800\Bin\Win64\procgov64.exe" -r --minws=1M --maxws=9G Anno1800.exe
pause

I also tried

D:
CD "D:\Anno 1800\Bin\Win64\"
procgov64.exe -r --minws=1M --maxws=9G Anno1800.exe
pause

and run it as an Administrator. All I did between it working and no longer working, was shut down the computer for the night. image

Edit: looking in to security permissions it seems there is indeed a problem with the Anno 1800 folder for some reason, specifically the Administrator accounts permissions for that folder. I'll look in to this some more, no clue what could've caused it.

Edit 2: Nope that wasn't it. I just moved everything to a new folder, deleted the original Anno 1800 folder and renamed the new folder to Anno 1800 to clear up the permissions issue, process Governor still won't launch the game. So this was just a red herring.

lowleveldesign commented 3 years ago

Try running procmon again but with all events enabled and look for ACCESS DENIED results. They should point you to the erroneous actions.

Nicholas-Steel commented 3 years ago

Logfile.zip

Here's a capture. From what I can tell there is no Access Denied instance.

Also this is what I meant earlier about a Permissions issue, Administrator has a red X on its icon when viewing the Security of the Anno 1800 and sub folders, while no other folder shows this phenomenon. I've tried recreating the folder as previously stated and I've also tried removing Administrator account permissions and then re-adding them to the folder: image

I did not check permissions before the issue with Processor Governor began so I can't say if this issue is even relevant to PG not working. Wouldn't surprise me if it is what is stopping it, since I am running the program as an Administrator.

Edit: Ah, okay so "Administrator" is not the same as "Administrators", the account without the s shows the red x on the icon. In either case changing it to Administrators didn't resolve the issue.

lowleveldesign commented 3 years ago

I don't see procgov running in the trace you attached. And indeed there is no access denied error reported in the logs. I know it sounds bad, but maybe you should try reinstalling the whole game.

Nicholas-Steel commented 3 years ago

Okay well while I still believe one day it worked, the next day it stopped working, no system changes were made by me and I'm the only user of this PC... I have now figured out a way to get it to work. I now have to run Ubisoft Connect as an administrator first, and then the batch file as an Administrator.

Procgov64.exe recursively launching Anno1800.exe > Anno1800.exe launching Ubisoft Connect > Ubisoft Connect launching the game... no longer works.

Ubisoft Connect loaded as an Administrator > Procgov64.exe recursively launching Anno1800.exe... does work.


When it first worked I used "D:\Anno 1800\Bin\Win64\procgov64.exe" -r --minws=1M --maxws=9G Anno1800.exe

When it stopped working, I was using that same command. When I figured out this current solution that same command is still being used (it's stored in a Batch file that I execute as an Administrator)