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,910
    Likes Received:
    8,163
    GPU:
    GF RTX 2070 Super
    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.
  2. Mott

    Mott Master Guru

    Messages:
    911
    Likes Received:
    206
    GPU:
    MSI 6800XT GXT
    @X7007 I'll get rid of the task and see if this new version has any stutters for me. Thanks for bringing it to our attention.

    Now just to find some time to play a game....
     
  3. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    I updated my app to 1.0.0.1

    Changes since 1.0.0.0
    - Configurable option: clear when standby list is XXXXMB and when Free memory is lower than XXXXmb.
    - Show some approximate memory information.
    - Can minimize to systray.
    - Possibly fixed a system crash issue.

    Edit:
    I updated my app to 1.0.0.2

    Changes since 1.0.0.1
    - Prevent G-SYNC to activate for the app (by disable hardware gpu acceleration for the app). Thanks Blaire for the suggestion.
     
    Last edited: Sep 30, 2018
  4. SabotageX

    SabotageX Active Member

    Messages:
    74
    Likes Received:
    9
    GPU:
    Gigabyte RTX 3080
    Ok, so if i want to remove the freestandbymemory script posted earlier and use only Wagnard's tool. Do i just have to delete the "freestandbymemory.bat" file from C:\Windows and delete the "freestandbymemory" task from Task Scheduler?
     
    Last edited: Sep 30, 2018

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,910
    Likes Received:
    8,163
    GPU:
    GF RTX 2070 Super
    What "history"? You see task details (name, status, triggers, next run time, last run time, last run result) in the table with tasks. Btw what user account is specified in the "General tab => Security options" (in task properties dialog) ? Try to set "SYSTEM".


    Yes.
     
    SabotageX likes this.
  6. windrunnerxj

    windrunnerxj Master Guru

    Messages:
    367
    Likes Received:
    59
    GPU:
    MSI Gaming 1060 6G
    Yeah
     
  7. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    There is also a condition to clean when memory is lower than 500(by default). If you were not under 500mb free , it wont clean.

    If you still see the issue, can you give me a screenshot of the app when you think it should clean it?
    test the link again too, normally its 1.0.0.2. Clear browser cache issue. or CTRL-F5
     
    Mott likes this.
  8. RzrTrek

    RzrTrek Ancient Guru

    Messages:
    2,516
    Likes Received:
    712
    GPU:
    RX 580
    I had to change the free memory is lower than value to max and then it would clean my cache.
     
  9. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    When it was lower, it would never clean even if you had 500MB or lower?
     
  10. RzrTrek

    RzrTrek Ancient Guru

    Messages:
    2,516
    Likes Received:
    712
    GPU:
    RX 580
    [​IMG]

    I never got so far and had 13 GB of free ram while testing, just wanted to check it out. Also everything seems to be working flawlessly.

    When the cache reach 1024 MB it will clean my cache as advertised (only wish this feature was built into my system) but keep up your good work.
     

  11. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    Thanks,
    Also note that some games do use the standby list (Rise of the TombRaider), if you always clean the list, the game will keep loading from you HDD most of the time (may cause stutter).

    From my testing it is more efficient to clean it when physical memory is starting to run low.
    But hey, you guys know what it is best for you. ;)
     
    Last edited: Sep 30, 2018
    AveYo, Mott and RzrTrek like this.
  12. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    Hello guys!
    Nice to see this topic getting some discussion here, who knows maybe the new dev blood at Microsoft will have mercy and fix this dreadful issue once and for all in 1809 later on.

    Do any of you remember the dreadful days of Steam experimenting with Chromium Embedded Framework and making a mess of all competitive games because their steamwebhelper.exe processes were leaking memory and causing stutters?
    If you do, then you must have heard about a steamwebhelper_killer.bat script, but probably don't know it was made by me :D
    Now days, it's no longer an issue (and there is a built-in steam launch parameter -no-browser available) but it was a plague for a couple years!

    Based on that experience I've made FreeStandbyMemory.bat as a response to manual tasks that were floating around and caused stutters by themselves - because that's what matters: the schedule. If it clears stuff each run - it's making things worse.

    Using wmic to query the FreePhysicalMemory and then simply exiting if it's above the threshold (512MB set, but you can put 1024 or even 99999 to force a clear every time for testing) is very efficient - even on my ancient htpc it takes less than 0.5s, without any resource usage spike. And yes, wmic is faster to run than powershell overall, reason for the check not being done in powershell as in v1.

    As for the heavy lifting done by the bundled C# snippet into powershell into batch - it was working just fine!
    I could have cooked my own, or modify the one I found, but decided to go with it as-is, mainly for trust and recognition.
    Going above and beyond trying to tweak it is a classic example of superfluous micro-optimizations that don't matter, or worse.
    The actual operation of zeroing memory won't be faster because you do some crazy stuff like compiling a service.
    It remains as fast as your RAM + CPU can do it. And keep in mind it does not even stutter on Core2 / DDR2 era hardware.
    Sure, Windows will start filling it up again, but you only notice that when you are close to idle, it's not as aggressive when you are actually playing! That's the target scenario.

    So, going from a script to a compiled program without a significant speed gain or functionality is going backwards, imho.
    Sorry, Wagnard :D I did laugh a little reading about the issues you've bumped into dealing with the compiled executable.
    Let's say the script version and the compiled program would offer the same core functionality. Yet the script version is plain-text (the pinnacle of open-source), editable on the spot, free to gain trust over time (vs. no signed binaries), no hosting troubles, no AV troubles (except really lame ones).
    But that's just my principle: "anything related to OS that can be done via scripting, should be done via scripting".
    Feel free to work on alternatives, and shut me up with some benchmarks :D

    And finally, the update: v3 of my script has lost a lot of weight! It is now less than 4KB as a whole!
    - using my slim RtlAdjustPrivilege
    - implemented SetSystemFileCacheSize suggestion by Maks.K
    - ClearFileSystemCache made optional - to disable, use [FreeStandbyMemory.Program]::ClearStandbyCache($false)
    It's still enabled by default because I find it reliable for multiple roles machines (gaming, media server, compiling etc) - where
    caches are big and work fine for everything except when gaming

    - dropped all exception output since it's meant to run headless on the local system account
    - setting advanced schedule options (DontStopIfGoingOnBatteries, higher priority, execution limit, close previous instances
    - built-in add/remove schedule by simply executing the script again
    - removed find.exe dependency (more a precaution for those that made the error of overriding windows tools with linux ones)

    I've meant no offense with this post, but if you feel in any way so, direct your response to OP - he invited me here :p

    [edit]
    Latest update: v6 features a fileless task run schedule! https://pastebin.com/Kj36ug5h
    - snippet is exported in the registry (could have been a one-liner but schedule /TR limits command size to ~260chars).
    - only powershell running (not significantly slower or faster than wmic) - mostly for convenience + less av /monitoring triggers
    - added optional FILESYSTEMCACHEALSO=1 (disable by using 0 instead of 1)
    - added hints on how to manually run a clear to check if it's working
    - better formatting (split long lines)
    Older v4 cmd+wmic-based is still available via gist history: https://git.io/FreeStandbyMemory.bat
     
    Last edited: Oct 2, 2018
  13. RzrTrek

    RzrTrek Ancient Guru

    Messages:
    2,516
    Likes Received:
    712
    GPU:
    RX 580
    I did however notice that it won't save my values when I exit the program and when I relaunch it will revert back to the default values.

    Tried doing the following: run w/wo admin privileges -> launch -> edit values -> exit -> relaunch the program = everything is reset.
     
  14. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    Yeah I don't save value yet. It is in "super" early development. :)

    @AveYo I'm all for alternatives. No worries here. Btw what issue made you laugh? if it's the crash, it was also present in the C# script I found on the web (possibly the one you are using? )
    As for benchmark, Usually a compiled version is faster than scripted. But have not tested.
    But I suspect mine is way faster as I don't rely on WMIC or performance counter at all. I Pin/Invoke the windows library directly and thus achieve nearly native speed.

    Edit: I made a benchmark for fun. On my system, Querying and actualizing the GUI for the Total system memory, "Standby list & system Working set" and the Free Memory is taking 5ms. or 0.005Sec (if I remove updating the GUI, it will be even faster than that.) So if you are 0.5 sec, you are technically 100x slower and not to mention you are not updating a GUI or anything.
    No offense there too, just wanted to throw my 2 cents.For me I have more fun compiling stuff than script. Guess everyone is different. I like problem solving etc.

    Edit2: Also nice move by using implemented SetSystemFileCacheSize it is way better than the other option that had chance to cause memory corruption. I looked at your script and you did a great job really. As long as we help the community, thats the import thing and must keep thing free.
     
    Last edited: Oct 1, 2018
    Mott, disq, AveYo and 1 other person like this.
  15. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,910
    Likes Received:
    8,163
    GPU:
    GF RTX 2070 Super
    @AveYo Welcome to forum. I want to praise your cool scripts. I have learned couple things. PowerShell is still my favourite scripting language (natural selection for .Net programmer), but CMD gained several points.

    I will soon publish C# source file (and script for building and setting up) for this purging tool in the form of system service with feature of purging both on timer and on the start of listed apps.

    PS Btw, that is a mystery for me, how do you know "Maks.K" when my account here is "mbk1969" ???

    PPS As for original PowerShell script published by Alexander Korotkov, its C# code looks like a work of student in some places. Since I find pleasure in simple code I just couldn`t resist the itch.
     
    Last edited: Oct 1, 2018
    AveYo likes this.

  16. AveYo

    AveYo Member

    Messages:
    43
    Likes Received:
    48
    GPU:
    8800GS 384MB
    I did not, I simply given credits to the comment on Alexander Korotkov's script published on technet.
    And yes his script might not be perfect, but was and still is damn effective.
    I always value at the top of my list work such as his - it's generally harder to do stuff via scripting but it's more rewarding to the community than slapping yet another bugged binary that does the same thing, with more work put into self-updating and donation buttons/ads, and that will soon die out. Note that I'm talking in general, not about any utilities shared in this thread (I haven't checked any of them because for now my script is perfect for the job :D)
    Using logman is not only overkill but a possible increase of dpc latency (it is effective while testing, but under high load usage from games and/or when windows update, push notifications, telemetry, power study, hdd maintenance and the dreadful defender starts going ham, stuff begins to crack under pressure. (that's my assessment after working on the next windows_update_toggle version - had to fall back to task scheduler). Don't like your service idea either but if I think more about it - why not? Go for it, even if it's just an exercise.


    I don't mean to nag, but your benchmark is irrelevant since you're only measuring one operation from your TSR (always running in the background program, that also consumes memory) and skipping any overhead that I was including (and the 0.5s was maximum from process start to process exit on a potato). I'm not contesting a compiled program is faster - but not that faster (just adding the startup time will blow that 5ms).
    Fully agree with your helping the community, and sorry for not checking out your program, I promise I will do so I can praise you too.
     
    Mott likes this.
  17. Mott

    Mott Master Guru

    Messages:
    911
    Likes Received:
    206
    GPU:
    MSI 6800XT GXT
    OP updated to try and encapsulate everything without being a wall of text.

    Please let me know if anyone thinks there should be any changes to it in order to more accurately reflect this thread. I am doing my best but I could always miss something important.

    Game on Guru3D!
     
  18. Wagnard

    Wagnard Ancient Guru

    Messages:
    2,662
    Likes Received:
    341
    GPU:
    MSI Geforce GTX 1080
    For information, me and AveYo used the same base for clearing the Standby list; we issue the same c# command to Windows.
    The key difference between us, is more what happens before (I do not use the TaskScheduler or the performance counter(WMI), I directly invoke the libraries). But basically we throw the same command to Windows at the end.
    So in the final it is more about personal preference about if you want a GUI with some details or not.
    Test both and see what you guys like the most / is working better for your system.

    And yes I sign my binaries and host my website and I like it this way+ useful in real life job. I even added a donation button :eek: for those who want to share a beer.

    Good night all, enough for me today.
     
    Mott and AveYo like this.
  19. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,910
    Likes Received:
    8,163
    GPU:
    GF RTX 2070 Super
    Monolith binary has advantage over scheduled bat-file (cmd.exe). In case Windows has memory leak free RAM becomes thin quite fast. And in that bad state OS needs to launch new process - cmd.exe to execute bat-file which in turn launches powershell.exe to execute ps1-file.

    Creation of process is heavy operation which needs RAM for:
    - 1MB for the stack memory in new process
    - kernel and user space process structures (along with all environment vars)
    - registry operations
    - file operations (searching and loading needed DLLs, increasing file cache).

    Then cmd.exe needs to parse and execute bat-file.

    Then powershell.exe needs to:
    - load all modules installed into PS
    - parse and execute ps1-file
    - compile C# code into managed dynamic assembly (.Net IL code) and load it into PS session (Add-Type -TypeDefinition $Snippet -Language CSharp)
    - compile .Net code into native code upon the call to class`s method ([FreeStandbyMemory.Program]::ClearStandbyCache($true))

    We can call it a burst. But monolith exe-file is completely free from such burst because it is launched at earlier stage where OS still has enough RAM, and then it just sits and wait for bad RAM condition to purge standby list (and file cache).
     
  20. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,910
    Likes Received:
    8,163
    GPU:
    GF RTX 2070 Super
    @AveYo You can discard this method
    Code:
    static void Main(string[] args)
    {
    ClearStandbyCache(true);
    }
    
    from PS portion of script. Alexander Korotkov obviously pasted a C# code for console application. In your PS usage method "Main" is not needed.

    Also since you do not check the result codes of API functions you can discard "SetLastError = true" (as well as CharSet = CharSet.Unicode, since SetSystemFileCacheSize has no string input params)
    Code:
    [DllImport("kernel32")]
    public static extern bool SetSystemFileCacheSize(IntPtr MinimumFileCacheSize, IntPtr MaximumFileCacheSize, Int32 Flags);
    
    @AveYo @Wagnard
    The usage of GCHandle
    Code:
    int SystemInfoLength = Marshal.SizeOf(MemoryPurgeStandbyList);
    GCHandle gcHandle = GCHandle.Alloc(MemoryPurgeStandbyList, GCHandleType.Pinned);
    NtSetSystemInformation(SystemMemoryListInformation, gcHandle.AddrOfPinnedObject(), SystemInfoLength);
    gcHandle.Free();
    
    is overkill and completely redundant. Here is more simple and more safe code
    Code:
    [DllImport("ntdll.dll", SetLastError = true)]
    static extern UInt32 NtSetSystemInformation(int InfoClass, ref int Info, int Length);
    ...
    int MemoryPurgeStandbyList = 4;
    uint res = NtSetSystemInformation(SystemMemoryListInformation, ref MemoryPurgeStandbyList, Marshal.SizeOf(MemoryPurgeStandbyList));
    
    with a bit changed prototype for NtSetSystemInformation, with class field MemoryPurgeStandbyList moved to the method ClearStandbyCache as local variable, and with removed variable SystemInfoLength.
     
    Last edited: Oct 1, 2018
    Mott likes this.

Share This Page