Here is a small utility I made whose purpose is to flush (empty) the Windows file cache. It can also flush and purge memory working sets, standby and modified lists.
It can be useful to reduce memory usage of a particular VM (on a host with dynamic memory) or for testing and bench-marking purposes.
The utility was compiled with Delphi XE and comes as a simple command-line executable with just two options
- by default (no option) it will flush the file cache working set and empty the memory working set, this is usually very fast and has limited impact.
- “full” will also flush the modified list and purge memory standby list, this can be slow and may slow down the machine for a while after it, as the OS will reload in memory what it really needs.
- “help” will display a small help.
You can download it here: FlushFileCache.zip (13 kB)
Note that it relies on the undocumented NtSetSystemInformation function. The source code will be available on a github repository as soon as I clean up the proprietary bits.
FWIW, if you have some memory-frugal service to run, it’s entirely feasible to use this utility on a Windows 2008 R2 server and stay under 128 MB RAM usage. Most of the unused OS services will be swapped out, leaving only core services in RAM.