Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Critical] Windows not release unused standby list even cached size is full #6

Closed
mhtvsSFrpHdE opened this issue Mar 30, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@mhtvsSFrpHdE
Copy link
Owner

Steam client just downloaded a game "the witcher 2",
after that, m/prefetch report Time: 43.58 Sec every time,
even if available RAM is 24.9 GB and cached is 24.8 GB.
That shows, if cached is full, Windows won't free unused cache for new cache content.

The result is low performance. This explained why my Firefox always read from disk:
when Firefox requested cache, the cached space is full.

By use sysinternals RAMMap\File Summary, there are pack0.dzip, en0.w2speech
cached in standby list, pack0.dzip is 9.79 GB, en0.w2speech is 1.01 GB.

The computer download and update games whole night.
Until I awake and discover Firefox is slow, I never open that game before.
That shows Windows is extremely stupid to judge what are important cache to keep.
It may just a "first come, first served, until full" simple design.
New cache won't free old cache, this only happens if "in use memory" take that space.

Same situation also happen on running virtual machine,
single vmdk file can take 2~9 GB in stand by list.

Use sysinternals CacheSet to change Working set minimum to 1024 KB,
and set maximum to 204800 KB,
open a VM still left a 2.37 GB cache in standby list.

In this case, the other thing can try is once discovered standby list space
is not enough to hold all cache content, empty it before start prefetch.

I found this: https://gist.github.com/bitshifter/c87aa396446bbebeab29
it seems there is no API to selective delete cache from standby list, and only empty all?

@mhtvsSFrpHdE mhtvsSFrpHdE mentioned this issue Mar 30, 2022
1 task
@mhtvsSFrpHdE
Copy link
Owner Author

mhtvsSFrpHdE commented Mar 30, 2022

Update:

sysinternals CacheSet have positive effect on this topic,
after minimum to 1024 KB and maximum to 204800 KB, PC run with virtual machine a day.

At night, there are only 4.2 GB is cached, and vmdk takes 388 MB, is the maximum one.
The rest of physical RAM remains empty, Firefox is always cached and no cache miss.
It seems very large file are excluded from standby list, all files are small file.
My point of view: if a file is too big, it will benefit from HDD continuous reading,
so no need to cache them unless this is a game resource pack.

Depending on what are running on PC, settings need to adjust for example:

  • Gaming: No limit on cache file size
  • General: Greater than 200 MB should not being cached

I here collect information every day to see if there's valuable CacheSet and vmdk result.

  • Day 1:
    Available 17.9 GB, Cached 4.2 GB, 13.7 GB RAM wasted, no cache miss
  • Day 2
    Available 10.3 GB, Cached 10.3 GB, 0 GB RAM wasted, cache miss every time

Conclusion:

After VM boot, soon vmdk in standby will increase to how many VM RAM assigned.
If execute a clear standby, vmdk will reduce, and won't increase until VM disk read behavior.
How many disk VM has read, how many standby vmdk will increase.
I guess the initial increase is because booting a VM will read a lot of system files.

The maximum size limit is not matter, these cache is persistent.
And I didn't find a way to selective delete mapped file from standby,
only clear all available, and they are undocumented Windows API.

VMWare have no related document about vmdk and standby RAM.

So the simplest thing I can do is check cached size,

if (available - cached) < certian amount && certian process running (vmware):
    clear standby
    other code as usual

Use memreduct to clear standby can be an acceptable choice,
the tool require 3.0 MB RAM at background.
If run clear code inside prefetch, 3.0 MB is saved.

@mhtvsSFrpHdE mhtvsSFrpHdE added the bug Something isn't working label Mar 30, 2022
@mhtvsSFrpHdE
Copy link
Owner Author

mhtvsSFrpHdE commented Jul 19, 2022

memreduct can run without background process and use memreduct.exe -clean to do default clean.

I can focus on check and calculate if I need to clean standby before prefetch.

Update: No, the command will show a dialog window and no method to skip show dialog.
It's a GUI stuff and not CLI or programming friendly.

@mhtvsSFrpHdE
Copy link
Owner Author

A test shows more detail about the kernel cache mechanism #7

This was referenced Aug 5, 2022
@mhtvsSFrpHdE mhtvsSFrpHdE mentioned this issue Aug 12, 2022
9 tasks
@mhtvsSFrpHdE
Copy link
Owner Author

Interesting information that shows VMWare may abuse host I/O cache:

https://communities.vmware.com/t5/VMware-Workstation-Pro/Disk-write-cache-broken-in-Workstation-14/td-p/490090

Reply by Testerhood:

Today I upgraded to VMware Workstation Player 15.0.3 (original version was 12.5.8) and I immediately noticed that VMs were trashing my host system's memory cache. Of course it's cool that VMs benefit of greatly increased IO performance with memory cache enabled, but I wasn't amazed that this is automatically enabled by default - most notably without any warning or hint. I haven't found any changelog that mentions this, only this well hidden forum post. So, funnily enough, I can confirm that this change works. However, the unwanted side effect is that it's enabled for everything - according to the experience I made. In order to disable this, I added a line called hard-disk.hostBuffer = "disabled" to "C:\ProgramData\VMware\VMware Workstation\config.ini". Now it's globally disabled, but I have seen it works to enable this for specific VMs by adding disk.hostBuffer = "enabled" in the vmx file for each VM respectively.

Please be more transparent with such changes for upcoming newer versions. Thank you!

@mhtvsSFrpHdE
Copy link
Owner Author

Fun result

No giant vmdk appears in RAMMap file summary,
so virtual machine does not loot standby list anymore.

This setting is undocumented, I search on VMWare doucment but nothing found.

Conclusion

Certain application may create giant file mapping in RAM.
This behavior will treat as "conflict" with m/prefetch.

Clear standby list is a "workaround", but not a fix.
For example, hard-disk.hostBuffer = "disabled" is a fix,
because after this setting, the problem is solved from the root cause.

@mhtvsSFrpHdE
Copy link
Owner Author

Since VMWare problem is solved,
I will keep looking if there is other application are abusing the standby list,
may be decided to add a patch at an appropriate time in the future.

If you need this patch to deal with such situation, reply or create a new issue:
Tell me what the application is, and how did you failed to turn off it's "file mapping".

@mhtvsSFrpHdE mhtvsSFrpHdE added enhancement New feature or request help wanted Extra attention is needed and removed bug Something isn't working labels Aug 21, 2022
@mhtvsSFrpHdE
Copy link
Owner Author

Start from version 2.8, custom tray menu introduced.
You can now use custom tray menu to start memreduct to clear stand by list.

https://github.com/mhtvsSFrpHdE/prefetch/wiki/Best-practice#clear-standby-list

For automation, you may write your own wrapper to monitor OS status,
or use the stdin interface to interactive with prefetch.
This issue treat as fixed.

@mhtvsSFrpHdE mhtvsSFrpHdE added wontfix This will not be worked on and removed enhancement New feature or request help wanted Extra attention is needed labels Sep 11, 2022
@mhtvsSFrpHdE mhtvsSFrpHdE added enhancement New feature or request and removed wontfix This will not be worked on labels Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant