7

For testing purposed I need to clear file cache (for example to measure file operation performance).

I found CacheSet from sysinternals, but pressing Clear there doesn't help. A file that I just copied to Nil when copied again do this in a blink of an eye (while the initial operation took significant 2 seconds).

Does it mean that HD has its own caching that can't be canceled or cleared?

2
  • 1
    Copying a file is not a good way to test your file-cache, the time may vary by file fragmentation and the spot where it is saved. It may also depend on the used file system.
    – Michael K
    May 18, 2011 at 10:32
  • serverfault.com/questions/91804/…
    – Sam Liao
    May 28, 2014 at 9:58

4 Answers 4

2

I'm not sure how much relevance this has to your question, but to answer your 2nd part, yes, hard-drives have their own internal hardware cache - usually 2, 8, 16, 32 or recently 64 megabytes.

Aside from that, Windows has a feature called Disk Write Caching which may help you. It can be enabled/disabled on a per-drive basis doing the following (directly copied from here):

  1. Right-click My Computer, and then click Properties.
  2. Click the Hardware tab.
  3. Click Device Manager.
  4. Click the plus sign (+) next to the Disk Drives branch to expand it.
  5. Right-click the drive on which you want to enable or disable disk write caching, and then click Properties.
  6. Click the Disk Properties tab.
  7. Click to select or clear the Write Cache Enabled check box as appropriate.
  8. Click OK.
2
  • 4
    The hard-drive cache has no relation to the windows file cache, disabling it does only decrease the hdd r/w performance.
    – Michael K
    May 18, 2011 at 10:30
  • Agree with Michael K: The hard-drive cache has no relation to the windows file cache, disabling it does only kills the hdd r/w performance
    – IceCold
    Dec 2, 2013 at 13:27
2

Here is the easy solution:

Start one (or more) instance(s) of MemAlloc. Allocate an amount of RAM equal with about 80% of total amount of RAM you have installed in your computer. This will force Windows to release the memory it reserved for file caching. Close all MemAlloc instances. Done.

Note: MemAlloc can allocat maximum 2GB of RAM. So, if you have more than 2GB of RAM in your computer, start additional instances of MemAlloc.

2
  • 4
    That’s hardly an ideal solution. If you are going to use a kludgy solution like this, then you may as well simply read a large file instead. At least by reading a large file, you only flush the drive cache. Allocating RAM as you suggested has the side-effect of pushing things into the pagefile which will kill performance for quite a while afterward.
    – Synetech
    Dec 1, 2013 at 0:38
  • He only needs this 'for testing purposes'. I this scenario I don't think he cares much about the swapping issue. Which is not that big anyway.
    – IceCold
    Dec 2, 2013 at 13:29
0

Did you try Sysinternals Sync utility as well, to flush all cached file data?

This will flush all devices including removable media.

.\sync.exe -r

-1

I've answered this question on StackOverflow -- you need to open the volume in a certain way.

2
  • Your solution is based on undocumented Windows behavior. Some users reported that your solution is not working on all systems.
    – IceCold
    Dec 2, 2013 at 13:32
  • @Altar: Your point...?
    – user541686
    Dec 2, 2013 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .