Flushing the Windows Disk Cache
Occasionally, I want to test the performance of a program after a cold boot, or maybe after the computer has been idle for hours and the program has been paged out. For example, the IMVU client starts relatively quickly when the disk cache is warm, but at system boot, it can take quite a while for the login dialog to even appear. Iterating in these situations is a pain in the butt because you have to reboot or leave your computer idle for hours.
I'm sure there exists a program which will flush the disk caches and force programs out of memory and into the page file, but I can't find it. So I wrote one.
First, a caveat: programs these days rarely handle out-of-memory situations, so running flushmem.exe
might cause open applications to explode like popcorn. Buyer beware, etc.
After running flushmem.exe
, you should find that your computer becomes painfully slow as applications are paged back into memory and the disk cache is refilled. Perfect. Now I can realistically simulate the experiences of our users.
You can download the program here or on the FlushMem page.
- flushmem.exe
- flushmem.cpp (source code)
Implementation details: in Windows, each process has a 2 GB user mode address space limit by default. If physical memory + page file size is greater than 2 GB, flushmem spawns multiple processes. Each process allocates memory in 64 KiB chunks until it can't anymore, and then writes to each page, forcing older pages out to the page file.
Consume.exe, bundled with the free "Windows Server 2003 Resource Kit Tools" does this and more: http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
Thanks. Last night I would have used it, but today flushmem.exe suits my purposes better. (Consume.exe spews windows over my desktop and is intended more for testing programs in low-memory situations.)
hi Chad,
I was desperately looking for a tool to flush my system cache as it was causing a database server that i was using (Interbase) to become unresponsive on Windows 2003 Server. I landed upon your page and tried the flushmem.exe and it works great. Thanks for the same. The only question I have for you is, is there a way to prevent flushmem from consuming all of the CPU memory while it is running? Any help on the same will be very helpful. Thanks for the utility.
Hi Raghu,
I'm not sure, as flushmem flushes the cache by allocating as much memory as possible.
Best of luck, Chad
Dear Chad, I have a 2009 Gateway that came with Vista but I changed it to xp pro about a year ago. It has 4gb ram and 500 gb HD. All was fine but I'm into home recording and I notice that sometimes the computer would hiccup during either recording or playback. I downloaded and ran flushmem.exe thinking this would help. I also unloaded a lot of stuff from my start up folder. But now I cant run open office from Oracle even though the program is on my computer. It shows up in programs listing and windows explorer. Also I'm missing my windows msconfigin file. All programs downloaded run fine. Do you think I messed up my registry with this flushmem.exe? Any help possible? Thank you. Charlie Niel
For others that turn up here, check the solution to this SO question, as it provides a good alternative "RAMMap" from sysinternals.
http://stackoverflow.com/questions/478340/clear-file-cache-to-repeat-performance-testing
I have run this utility and it stuck my PC (Windows 7) not recommended
Question: I assume Flushmem uses the SetWorkingSet API ?
Nope, that wouldn't affect the overall system caches.
This sounds like just what I need! But when I execute it on my Windows 7 Pro 64 bit system, I get a DOS window:
allocation granularity: 65536 forking 11 subprocesses allocating... allocating... allocating... allocating... allocating... allocating ... 2086666240 bytes flushing... 2086666240 bytes flushing... 2086666240 bytes flushing... 2086666240 bytes flushing... 16292249601335033856 bytes flushing... bytes flushing... allocating... 10944512 bytes flushing...
But then an error dialog box: "flushmem.exe - Application Error - The application was unable to start correctly (0xc0000142). Click OK to close the application".
Is this to be expected?
Hi Rex!
I'm not sure where the error message is coming from, but it sounds like the program operated correctly! Note that on Linux there are easier ways to flush the disk cache.