Fix game stutter on Win 10 1703-1809

Discussion in 'Videocards - NVIDIA GeForce Drivers Section' started by Exostenza, Apr 3, 2018.

  1. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,746
    Likes Received:
    519
    GPU:
    MSI Geforce GTX 1080
    Just to let everyone knows, I have released my personal solution for clearing the standby list. (early development so please don't judge me)
    It is available on my website.
     
  2. Exostenza

    Exostenza Maha Guru

    Messages:
    1,408
    Likes Received:
    748
    GPU:
    MSI 4090 GT
    Love your work. Will put in OP.

    Thanks so much!

    EDIT: OP overhauled. More info and hopefully no more clutter.

    EDIT2: I've invited AveYo to come and weigh in on all this so I hope to see him turning up in this thread soon!

    EDIT3: @mbk1969 if you have a definitive script you would like me to add to the OP please let me know and I will so you can get some more people trying it out. I have been so busy with my MA studies lately that games have been taking a back seat.
     
    Last edited: Sep 29, 2018
    Wagnard likes this.
  3. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Well, you can simply put a link to this post
    https://forums.guru3d.com/threads/f...date-sept-29-2018.420251/page-10#post-5590135
    as an alternative more lightweight implementation. I soon will post second alternative implementation without scripts, task schedulers - monolith system service (that should be lightweight even more) with feature of purging standby list on listed applications` start.
     
  4. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    That version utilizes PowerShell. May be setting security execution policy will solve: launch elevated PowerShell and execute there "set-executionpolicy Unrestricted"

    PS What is "Last Run Result" for the task?
     
    Last edited: Sep 29, 2018

  5. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,746
    Likes Received:
    519
    GPU:
    MSI Geforce GTX 1080
    Will do, noted.
     
    Singleton99 and Dynarush_333 like this.
  6. rasfire

    rasfire Member

    Messages:
    21
    Likes Received:
    0
    GPU:
    EVGA RTX3080 FTW
    Hello Everyone :)

    "set CLEAR_WHEN_UNDER_MB=512"

    What is the best size to put put here in place?
    Does this depends on your systems total ram?(16GB in my case..

    Kind Regards.
     
  7. Driller_au

    Driller_au Member Guru

    Messages:
    145
    Likes Received:
    25
    GPU:
    Zotac 4090 Airo
    @ Wagnard your app works great :) a suggestion if you go back and develop it more is to make it so we can add it to the startup list, i tried and it didn't work, it was there and enabled but didn't start thanks
     
  8. LocoDiceGR

    LocoDiceGR Ancient Guru

    Messages:
    2,858
    Likes Received:
    1,071
    GPU:
    Gigabyte 3060 Ti
    1809 is upon us guys...that will bring new problems. :D
     
    mbk1969 likes this.
  9. windrunnerxj

    windrunnerxj Master Guru

    Messages:
    487
    Likes Received:
    127
    GPU:
    RTX 4060
    You can leave it at default I guess. From what I understand this issue arises when your system runs out of free RAM, can't properly clear it and starts using your pagefile.
    I don't think I ever encountered this issue on my machine with 8GB of RAM or I simply don't notice it. Constantly clearing SBL doesn't seem like a good solution to me personally since I still use an HDD for my OS driver and every memory clear causes 99% load on the HDD for a minute or two.
     
  10. JonasBeckman

    JonasBeckman Ancient Guru

    Messages:
    17,564
    Likes Received:
    2,961
    GPU:
    XFX 7900XTX M'310
    Yeah the super-fetch (Renamed as of 1809) service will start caching stuff as the standby memory is cleared going by prefetech data I assume and loading up memory as much as can be.
    I do not know much about the issue myself though, not something I have noticed but prevalent enough to be a serious problem so hopefully Microsoft can fix the situation where instead of emptying out and unloading the cache as it should it gets stuck and moves into page or swap area and that's really bad performance wise. (It should be using RAM not some storage system on the HDD or SSD.)

    Strange that it isn't a bigger priority since it's been around for a while now and is somehow still a issue in RS5 for several users.
    Manual controls for path exclusions, unloading or emptying out the data wouldn't hurt but the root issue has to be found and dealt with at some point.
    (Emptying it out like this works but then the super-fetch service goes into action immediately to fill it up again so it's a bit of a balance act since there's no fine control over this system.)
     

  11. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    For that bugs should be filed by users. The more the faster it should receive higher priority.
     
  12. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Easy to test yourself. Start perfmon, add counter "Memory/Available MBytes" and start your usual activity. If you feel that performance is choked, ALT-Tab to perfmon to see the value - if it is low you can set this value for CLEAR_WHEN_UNDER_MB.
     
  13. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    If you use script in OP then your HDD activity can be the result of clearing file cache along with the SBL. You can try my version to verify that suspicion. Or you can comment out the clearing of file cache from original script.
     
  14. windrunnerxj

    windrunnerxj Master Guru

    Messages:
    487
    Likes Received:
    127
    GPU:
    RTX 4060
    I didn't try any scripts, just used RAMMap's Empty Standby List for testing. Stopping Superfetch service eliminates all that excessive disk usage, but is it even a good idea to have Superfetch permanently disabled if I don't have any SSDs?
    The only stuttering I sometimes encounter is after alt-tabbing during games. Almost always happens with CSGO, but restarting the game eliminates the alt-tab stutter. Maybe "Fullscreen Optimization" is at fault here, but I didn't try turning it off.
     
  15. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    You can try to configure Superfetch to deal only with boot optimization (excluding apps optimization).
     

  16. SpookySkeleton

    SpookySkeleton Member Guru

    Messages:
    153
    Likes Received:
    23
    GPU:
    RTX 3090
    @Wagnard script works better for me, but after many hours of system uptime, the app gets stuck like this for a long time
    [​IMG]
    [​IMG]
     
  17. X7007

    X7007 Ancient Guru

    Messages:
    1,874
    Likes Received:
    72
    GPU:
    ZOTAC 4090 EXT AMP
    It seems they fixed it on the new windows update version
    1803 17134.320

    Uptime is 1:20:41:54
    C:\>systeminfo | find "System Boot Time:"
    System Boot Time: 09/28/2018, 21:24:32
    [​IMG]
     
    Exostenza likes this.
  18. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Here is cleaner for another "channel" - file cache. It should purge file cache when it becomes greater then 2000000000 bytes (a value to configure).

    Create folder "PurgeFileCache" and paste these files there:

    - setup.bat
    Code:
    @echo off
    rem format for CLEAR_EVERY_MINUTES is MM:SS. if CLEAR_EVERY_MINUTES is less then 10 minutes use leading zero - 01:00, 02:00, 03:00, ..., 09:00.
    set CLEAR_EVERY_MINUTES=10:00
    set CLEAR_WHEN_GREATER_B=2000000000
    cd %~dp0
    echo Compiling console application...
    c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -target:exe -subsystemversion:6.01 PurgeFileCache.cs > nul || exit /b 1)
    echo.
    echo Creating task with console application...
    Schtasks.exe /Create /Tn PurgeFileCache /Ru SYSTEM /Sc ONIDLE /I 999 /Tr "%~dp0PurgeFileCache.exe" > nul || exit /b 2)
    echo.
    echo Creating performance counter alert and task for starting this alert on every logon...
    logman.exe create alert HighFileCacheAlert -th "\Memory\System Cache Resident Bytes>%CLEAR_WHEN_GREATER_B%" -tn "PurgeFileCache" -si %CLEAR_EVERY_MINUTES% -m start stop > nul || exit /b 3
    Schtasks.exe /Create /Tn StartHighFileCacheAlert /Ru SYSTEM /Sc ONLOGON /Tr "logman start HighFileCacheAlert" > nul || exit /b 4
    echo.
    echo Starting performance counter alert...
    logman.exe start HighFileCacheAlert > nul || exit /b 5
    echo.
    echo Success!
    exit /b
    

    - cleanup.bat
    Code:
    @echo off
    echo Stopping and deleting perfomance counter alert...
    logman.exe stop HighFileCacheAlert
    logman.exe delete HighFileCacheAlert
    echo.
    echo Stopping and deleting tasks...
    Schtasks.exe /End /Tn PurgeFileCache
    Schtasks.exe /Delete /Tn PurgeFileCache /F
    Schtasks.exe /End /Tn StartHighFileCacheAlert
    Schtasks.exe /Delete /Tn StartHighFileCacheAlert /F
    echo.
    echo Deleting console application...
    cd %~dp0
    del /F /Q PurgeFileCache.exe
    

    - PurgeFileCache.cs
    Code:
    using System;
    using System.Runtime.InteropServices;
    using System.Security.Principal;
    namespace PurgeMemCache
    {
        class Program
        {
            [System.Security.SuppressUnmanagedCodeSecurity]
            [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
            static int Main(string[] args)
            {
                try
                {
                    using (var current = WindowsIdentity.GetCurrent(TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges))
                    {
                        TokPriv1Luid newst;
                        newst.Count = 1; newst.Luid = 0L; newst.Attr = 2;// SE_PRIVILEGE_ENABLED;
                        if (!LookupPrivilegeValue(null, "SeIncreaseQuotaPrivilege", ref newst.Luid))
                        {
                            Console.Error.Write("Error in LookupPrivilegeValue: {0}", Marshal.GetLastWin32Error());
                            return 1;
                        }
                        if (!AdjustTokenPrivileges(current.Token, false, ref newst, 0, IntPtr.Zero, IntPtr.Zero))
                        {
                            Console.Error.Write("Error in AdjustTokenPrivileges: {0}", Marshal.GetLastWin32Error());
                            return 2;
                        }
                        UInt32 res = SetSystemFileCacheSize(IntPtr.Subtract(IntPtr.Zero,1), IntPtr.Subtract(IntPtr.Zero,1), 0);
                        if (res == 0)
                        {
                            Console.Error.Write("Error in SetSystemFileCacheSize: {0}", Marshal.GetLastWin32Error());
                            return 3;
                        }
                    }
                    return 0;
                }
                catch(Exception ex)
                {
                    Console.Error.Write("Unexpected error:\n{0}", ex.ToString());
                    return 4;
                }
            }
            [DllImport("advapi32.dll", SetLastError = true)]
            static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
            [DllImport("advapi32.dll", SetLastError = true)]
            static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
            [DllImport("Kernel32.dll", SetLastError = true)]
            static extern UInt32 SetSystemFileCacheSize(IntPtr MinimumFileCacheSize, IntPtr MaximumFileCacheSize, UInt32 Flags);
       
            [StructLayout(LayoutKind.Sequential, Pack = 1)]
            struct TokPriv1Luid
            {
                public int Count;
                public long Luid;
                public int Attr;
            }
        }
    }
    

    setup.but should do these steps:
    - build C# source file into console application (with C# compiler in .Net Framework folder) "PurgeFileCache.exe"
    - create task "PurgeFileCache" with this console application
    - create performance counter ("\"\Memory\System Cache Resident Bytes>%CLEAR_WHEN_GREATER_B%") alert "HighFileCacheAlert" with check for every "%CLEAR_EVERY_MINUTES%" minutes, and with call of task "PurgeFileCache" (in case the check result is true)
    - create task "StartHighFileCacheAlert" which should start the performance counter alert "HighFileCacheAlert" at every logon
    - start the performance counter alert "HighFileCacheAlert"
    You can change the values CLEAR_EVERY_MINUTES - performance counter sampling interval, and CLEAR_WHEN_GREATER_B - the treshold for calling the purge of file cache.

    cleanup.bat should do these steps:
    - stop and delete the performance counter alert "HighFileCacheAlert"
    - stop and delete task "PurgeFileCache"
    - stop and delete task "StartHighFileCacheAlert"
    - delete console application

    PurgeFileCache.cs file is just reworked code of original PowerShell script published by Alexander Korotkov - I removed purging of standby list. In case of error application should return code of error: 1, 2, 3 or 4. And of course you can execute (as administrator) console application built from this source file any time you want.
     
    Last edited: Sep 30, 2018
  19. disq

    disq Member Guru

    Messages:
    199
    Likes Received:
    185
    GPU:
    [​IMG]

    Is this normal? Memory stays on 100 even though there's available RAM?!
     
  20. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    That`s not "100 MB", that`s "100%" - scaled value (between minimum and maximum samples). You can delete first performance counter, and then invoke properties dialog for needed counter. There you switch to "Graph" tab, select View - "Line" and set Vertical scale - Maximum to overall amount of your RAM in megabytes (I guess). I will try this too now...

    PS You can see actual numbers in fields under the graph - "Last", "Average", "Minimum".


    PPS I never view performance counters in Line view. I use Report view.
     
    Last edited: Sep 30, 2018
    disq likes this.

Share This Page