11

I have a windows server 2008 R2 file server, that has some large files that on rare occasions is very important to get copied to another system as quickly as possible.

Is there a way to force these files to always be cached to RAM?

Josh
  • 245
  • 1
  • 3
  • 8
  • 1
    Note: Not directly related, but if you're really hurting for speed, and your file transfer is via code you control, not just built-in utilities, you may want to update your code to use [the `TransmitFile` function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms740565%28v=vs.85%29.aspx). By opening a file with `FILE_FLAG_SEQUENTIAL_SCAN` then using `TransmitFile` to send the file data over the socket, Windows will aggressively prefetch to minimize delays, and perform the socket writes directly from the system cache, removing unnecessary system calls to copy to and from user space. – ShadowRanger Jan 27 '17 at 16:54

5 Answers5

8

Most of the time the bottleneck isn't so much getting the file from disk to RAM but rather from RAM to network. Unless the system is very bogged down in activity or low on RAM, Windows should handle file caching fairly intelligently.

You might want to do some testing and see if there really is a bottleneck with your system that would see marked improvement by keeping certain files in memory versus swapped to disk when Windows thinks it should be saved to disk. I'm betting you'll save very little time as the bottleneck would most likely be the network, and by the time the file is queued up to go to the network the drive is already filling buffers in memory as it pulls the file off the drive.

That said, the only really reliable way to have data files held in memory that I know of is to create a RAM disk and copy the files there, assuming they are static. Otherwise you have a power outage and they're gone.

Otherwise you might want to invest in lots of RAM and high speed disk drives. Maybe even a mirrored RAID configuration, as that has a high read (slower write) performance. I'd let Windows and the memory manager do it's thing, and focus on minimizing access time with better subsystems (fast disk, RAID, lots of memory, high speed and high quality NIC) rather than tweaking it to the point that debugging or troubleshooting could become more of a pain down the road.

Bart Silverstrim
  • 31,172
  • 9
  • 67
  • 87
3

You can try supercache or other alternate cache solutions, or you may want to consider using a SSD with high speed read access - That will saturate almost any network connection pretty easily.

The only other option I don't think matches your needs but I'll mention it:

If you are WRITING the file in your application you can try creating with:

FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE

This tells Windows to try to keep files in RAM instead of on disk - I don't think this will match your needs though but you can read more at http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx#caching_behavior

Matthieu
  • 121
  • 9
0

There is no standard way to do this. Windows lacks such hooks. If this is really important to you, you can attempt to game the Windows file-caching algorithms by frequently accessing the file from the network. That should keep the file cached, but there are no guarantees. IIRC, you don't need to read the entire file to get the entire file cached, so reading a subset of the file should be sufficient.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
0

Yes, there is a way to trick the OS Memory Manager and load the entire file/folder into the OS System cache. Take a look the the post here: http://www.arcgis.com/home/item.html?id=08a5a05ff82446bb8a8befad03b1bb86

  • 4
    Welcome to Server Fault! We really do prefer that answers contain content not pointers to content. Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – user9517 Feb 25 '13 at 18:42
0

You may premap files using memory mapped files to speed up things https://www.microsoft.com/store/apps/9N9TWRVC493H