user541686
user541686

Reputation: 210445

Read a File From Cache, But Without Polluting the Cache (in Windows)

Windows has a FILE_FLAG_NO_BUFFERING flag that allows you to specify whether or not you want your I/O to be cached by the file system.

That's fine, but what if I want to use the cache if possible, but avoid modifying it?

In other words, how do you tell Windows the following?

Read this file from the cache if it's already cached, but my data doesn't exhibit locality, so do not put it into the cache!

The SCSI standard defines a Disable Page Out bit that does precisely this, so I'm wondering how (if at all) it is possible to use that feature from Windows (with cooperation of the file system cache too, of course)?


Edit: TL;DR:

What's the equivalent of FILE_FLAG_WRITE_THROUGH for reads?

Upvotes: 1

Views: 291

Answers (2)

bmargulies
bmargulies

Reputation: 100040

I see two flags that look suspiciously like what you are asking for:

FILE_FLAG_RANDOM_ACCESS
FILE_FLAG_SEQUENTIAL_SCAN

The later's doc clearly suggests that it won't retain pages in cache, though it will probably read-ahead sequentially. The former's doc is completely opaque, but would seem to imply what you want. If the pattern is quite random, hanging onto pages for later reuse would be a waste of memory.

Keep in mind that, for files, the Windows kernel always will use some pages of 'cache' to hold the I/O. It has nowhere else to put it. So it's not meaningful to say 'don't cache it,' as opposed to 'evict the old pages of this file before evicting some other pages.'

Upvotes: 0

Jerry Coffin
Jerry Coffin

Reputation: 490128

About the closest Windows provides to what you're asking is FILE_FLAG_WRITE_THROUGH.

Upvotes: 1

Related Questions