Fix game stutter on Win 10 1703-1809

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

  1. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    You should be more specific now when this thread hosts several versions. Were you talking about OP scripts or mine ones?

    Also just in case, how exactly do you check whether standby list was cleared or not?
     
  2. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    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.
     
  3. Mott

    Mott Master Guru

    Messages:
    911
    Likes Received:
    206
    GPU:
    MSI 6800XT GXT
    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.
  4. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    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.
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    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
  6. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    Will do, noted.
     
    Singleton99 and Dynarush_333 like this.
  7. rasfire

    rasfire Member

    Messages:
    20
    Likes Received:
    0
    GPU:
    MSI GTX1080TI Gam X
    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.
     
  8. Driller_au

    Driller_au Member Guru

    Messages:
    132
    Likes Received:
    20
    GPU:
    Asus 2080 Ti OC
    @ 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
     
  9. LocoDiceGR

    LocoDiceGR Ancient Guru

    Messages:
    2,360
    Likes Received:
    820
    GPU:
    Gigabyte 3060 Ti
    1809 is upon us guys...that will bring new problems. :D
     
    mbk1969 likes this.
  10. windrunnerxj

    windrunnerxj Master Guru

    Messages:
    367
    Likes Received:
    59
    GPU:
    MSI Gaming 1060 6G
    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.
     

  11. JonasBeckman

    JonasBeckman Ancient Guru

    Messages:
    17,485
    Likes Received:
    2,875
    GPU:
    MSI 6800 "Vanilla"
    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.)
     
  12. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    For that bugs should be filed by users. The more the faster it should receive higher priority.
     
  13. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    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.
     
  14. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    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.
     
  15. windrunnerxj

    windrunnerxj Master Guru

    Messages:
    367
    Likes Received:
    59
    GPU:
    MSI Gaming 1060 6G
    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.
     

  16. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    You can try to configure Superfetch to deal only with boot optimization (excluding apps optimization).
     
  17. SpookySkeleton

    SpookySkeleton Member Guru

    Messages:
    145
    Likes Received:
    19
    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]
     
  18. X7007

    X7007 Ancient Guru

    Messages:
    1,636
    Likes Received:
    38
    GPU:
    Sapphire 6900XT
    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]
     
    Mott likes this.
  19. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,915
    Likes Received:
    8,191
    GPU:
    GF RTX 2070 Super
    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
  20. disq

    disq Member Guru

    Messages:
    139
    Likes Received:
    96
    GPU:
    [​IMG]

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

Share This Page