I want to access a file uisng using FILE_FLAG_RANDOM_ACCESS. But when a large file is accessed via FILE_FLAG_RANDOM_ACCESS, huge memory consumption could result in bad system performance. Is there a way to put a limit on cache size for a specific file handle?
Windows doesn't provide a way to set a maximum cache size, but this is relatively easy to implement on your own. Open the file with FILE_FLAG_NO_BUFFERING
and implement your own cache with an LRU list to determine when to evict blocks. Note that starting with Windows Server 2016, FILE_FLAG_RANDOM_ACCESS
is less aggressive about retaining data in the cache, so this is less of a concern. Microsoft still recommends avoiding this flag, however.
Further reading: Troubleshoot Cache and Memory Manager Performance Issues
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With