views:

61

answers:

1

Our application is memory intensive and deals with reading a large number of disk files. The total load can be more than 3 GB.

There is a custom memory manager that uses memory mapped files to achieve reading of such a huge data. The files are mapped into the process memory space only when needed and with this the process memory is well under control. But what is observed is, with memory mapping, the system cache keeps on increasing until it occupies the available physical memory. This leads to the slowing down of the entire system.

My question is how to prevent system cache from hogging the physical memory? I attempted to remove the file buffering (by using FILE_FLAG_NO_BUFFERING ), but with this, the read operations take considerable amount of time and slows down the application performance. How to achieve the scalability without sacrificing much on performance. What are the common techniques used in such cases?

I dont have a good understanding of the WinXP OS caching behavior. Any good links explaining the same would also be helpful.

+2  A: 

I work on a file backup product, so we often run into similar scenario, where our own file access causes the cache manager to keep data around -- which can cause memory usage to spike.

By default the windows cache manager will try to be useful by reading ahead, and keeping file data around in case its needed again.

There are several registry keys that let you tweak the cache behavior, and some of our customers have had good results with this.

XP is unique in that it has some server capability, but by default optimized for desktop programs, not caching. You can enable System Cache Mode in XP, which causes more memory to be set aside for caching. This might improve performance, or you may be doing this already and its having a negative side effect! You can read about that here

I can't recommend a custom memory manager, but I do know that most heavy weight apps do there own caching (Exchange, SQL). You can observe that by running process monitor.

If you want to completely prevent cache manager from using memory to cache your files you must disable both read and write caching:

FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH

There are other hints you can give the CM, (random access, temporary file) read this document on Caching Behavior here

You can still get good read performance even if you disable caching, but your going to have to emulate the cache manager behavior by having your own background threads doing read aheads

Also, I would recommend upgrading to a server class OS, even windows 2003 is going to give you more cache manager tuning options. And of course if you can move to Windows 7 / Server 2008, you will get even more performance improvements, with the same physical resources, because of dynamic paged/non paged pool sizing, and working set improvements. There is a nice article on that here

Ivan Bohannon