Fix game stutter on Win 10 1703-1809

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

  1. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    @AveYo
    You can avoid WMI completely:

    Code:
        var pcFreeAndZero = new System.Diagnostics.PerformanceCounter("Memory", "Free & Zero Page List Bytes", true);
        UInt64 avail = Convert.ToUInt64(pcFreeAndZero.NextValue()) >> 20; // converting bytes to megabytes, use ">> 10" for kilobytes
        if(avail > freemtarget) return;
    
    One performance counter instead of WMI query.
     
    Last edited: Oct 10, 2018
    Exostenza and AveYo like this.
  2. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    I actually use WMIv2 that is somehow a bit faster under stress, while counters being way too slow on my test PC - orders of magnitude slow. But thanks for the hint! I'm also not sure it's the same thing with the FreePhysicalMemory value, taking zeroed memory into consideration might skew results. Will test just for science :)
     
    Exostenza likes this.
  3. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    It can be that in most WMI structures (and in most Win API structures) free physical memory is a sum of free & zero page list bytes and standby page list bytes.

    CIM_OperatingSystem is abstract WMI class (there can`t be instances of abstract classes). It serves as a parent class for some other classes, including Win32_OperatingSystem. When you execute WMI query for abstract class it returns instances of all classes derived from that abstract class. That means more burdensome work comparing with the WMI query for the derived class. So in theory searching for Win32_OperatingSystem should be more lightweight than searching for CIM_OperatingSystem.

    Win32_OperatingSystem is marked as singleton, which means there can be only one instance of this class in WMI. So you can use this code for getting it:
    Code:
    using (CimSession mySession = CimSession.Create(null))
    {
        CimInstance instance = mySession.GetInstance(@"root\cimv2", new CimInstance("Win32_OperatingSystem"));
        if ((UInt64)instance.CimInstanceProperties["FreePhysicalMemory"].Value > freemtarget) return;
    }
    
    It can be less heavy.

    Update: Code was updated...
     
    Last edited: Oct 10, 2018
    Exostenza and AveYo like this.
  4. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    I had all combinations tested some time ago, and wmic / powershell wmi was faster, with the cim variant constantly slower, but not by much. Then I had to install visual studio, dotnet etc. and cim became better. Note that I'm talking about my calamity scenarios when even process monitor crawls. I swear it all these cpu vulnerabilities patches are doing weird stuff, or Microsoft really jumped the boat with telemetry - can't wait to move to an AMD system for a change. To this date I have never seen windows work as fast as my old amd64 dfi lanparty wd raptor rig.
    I'm about to clean install a stable windows version (ltsb) on a system and will get to the bottom of this once and for all :)
     
    Exostenza likes this.

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    It seems I managed to adopt low memory notification API. I can try it on weekend. It promises lowest footprint and payload comparing to WMI and timer algorithms, since it only uses two Win API functions, needs no timer and performance counter, and communicates (so to speak) directly with memory manager.
    New purge query syntax will be like "purge <target> on notify(<minutes>)" (without treshold part since I decided to not set the low memory treshold value in registry to not affect possible dependencies).
     
    Last edited: Oct 11, 2018
    Exostenza, AveYo and disq like this.
  6. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    UPDATE: v2018.10.12 (final?) available AT https://pastebin.com/Kj36ug5h OR https://git.io/FreeStandbyMemory.bat
    Dropped wmi dependency and it payed off, winapi really trumps everything! I urge any previous users to check it out
    It is now ultra fast (in the 0-3ms range) at checking free ram and exiting if not under target! Not much left to optimize there :rolleyes:
    What I could try would be my own event subscription instead of native scheduler - but the advanced task is doing great for now
    Still <6KB :)
     
    mbk1969 and Exostenza like this.
  7. CrazyGenio

    CrazyGenio Master Guru

    Messages:
    455
    Likes Received:
    39
    GPU:
    rtx 3090
    i'm really gratefull with your work all of you
     
  8. Exostenza

    Exostenza Maha Guru

    Messages:
    1,408
    Likes Received:
    748
    GPU:
    MSI 4090 GT
    OP updated with final script from @AveYo and now includes the new solution from @mbk1969 with an explanation of it.

    Please let me know if you guys want anything added or revised in the OP.
     
  9. Martigen

    Martigen Master Guru

    Messages:
    534
    Likes Received:
    254
    GPU:
    GTX 1080Ti SLI
    So, ah, are we convinced this is necessary with 1809?
     
  10. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    There is a thing you can optimize - you forgot to ditch (in red color):

    set "mmi=%Windir%\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Management.Infrastructure"
    for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%mmi%\*Microsoft.Management.Infrastructure.dll"') do set "mmi="%%v""
    %csc% /out:FreeStandbyMemory.exe /target:winexe /platform:anycpu /optimize /nologo /reference:%mmi% "%~f0"
     

  11. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,746
    Likes Received:
    519
    GPU:
    MSI Geforce GTX 1080
    On my case, it is still needed.
     
    AveYo likes this.
  12. Driller_au

    Driller_au Member Guru

    Messages:
    145
    Likes Received:
    25
    GPU:
    Zotac 4090 Airo
    I just played a few hours of BF1 with Wagnards app and it triggered 3 times
     
    AveYo likes this.
  13. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    Your introduction text under the "Option 2: ..." made me blush.
     
    AveYo likes this.
  14. EdKiefer

    EdKiefer Ancient Guru

    Messages:
    3,127
    Likes Received:
    394
    GPU:
    ASUS TUF 3060ti
    But that doesn't mean it is needed, just that standby memory went to X limit.
    I don't have any issues playing BF1 even when I have a VM of win10 running in the background were free memory goes to small amounts.
    Normally though my standby never gets that full, I do a shutdown every night so that might affect things and I don't try an run 100 exe while playing games.
     
  15. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    I failed to understood the logic behind memory notifications and to achieve wanted algorithm of purging and hence abandoned that type of schedule. Alas.

    But on the way I updated the source, so gurus can re-download and rebuild the binary
    http://www.mediafire.com/file/r5p3icyvnecm6np/PurgeMemCacheService.zip/file

    Change log:
    - a bit of speed and footprint optimizations (nothing major);
    - a cleanup for WMI events on start/stop of processes (just in case, since there is no consensus about it).

    PS Mott, you can ignore this and to not update the text in OP.
     
    Last edited: Oct 12, 2018

  16. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    I know, but decided to not make yet another update since not used referenced assemblies are scrapped by csc
    And btw, your CIM change suggestion was noticeable slower. I also fixed wmi and powershell on my dev pc to have more decent delays under load - it was unsurprisingly caused by domain configuration.

    That's probably my fault :D I joked in pm with OP about we the scripters needing to stick together vs. the superior digitally signed exe provider plebs like @Wagnard :p and looks like @Mott delivered and promoted you above :rolleyes:

    I'd say all 3 solutions are competitive, so it's a matter of preference / need of features / dealing with issues such as lame av's.

    @EdKiefer: that's exactly how I run them games - 100 exes while playing, closing and reopening games 10-20 times per session, not shutting down the pc like ever - suspend to ram ftw!
     
    Smough and mbk1969 like this.
  17. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,746
    Likes Received:
    519
    GPU:
    MSI Geforce GTX 1080
    Seriously ??:confused: I never known I was in a "versus" scripters. I hope you know that mbk1969 solution is a .exe too. So your kinda alone in your VS.

    @mbk1969 Your setup.bat script have a bug that prevent the installation of the service if the folder we extract it contain a space.

    Yes I , the superior digitally signed exe provider pleb, also try the others solution too :cool:
     
    Last edited: Oct 13, 2018
  18. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    That`s not a bug. That`s a protection against users who love folders with spaces in name.

    PS bat-file updated (for spaces-in-folder-name-perverts).
     
    Last edited: Oct 13, 2018
  19. Chilace

    Chilace New Member

    Messages:
    8
    Likes Received:
    1
    GPU:
    GTX 1050Ti 4GB
    Hello all. Is it worth to mention Mem Reduct ?
    I used this tool before finding this topic. It may be worse than the solutions available here, but at least it is localized into several languages.
     
  20. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    The more the better.
     

Share This Page