What does working set tell you?

Recently, I have been looking at memory usage. Up until this point, I have been using working set to tell me how much physical memory a process is using. It turns out that this definition is wrong. Working set actually tells you how many virtual pages in the process are mapped into physical memory. What is the difference? With private memory (memory that can’t be shared between two processes, or two virtual addresses in the same process; example: memory return from malloc), these two definitions are equivalent. But my original (bad) definition breaks down for shared memory, or memory mapped files. Try this as an example:

  1. Open a file
  2. Call CreateFileMapping to creating a mapping handle
  3. Call MapViewOfFile twice to create two different identical views on the same file
  4. Try looping through just one of the views and look at what that does to your process’s working set
  5. Now try looping through both views and look at what that does to your process’s working set

The result you will find is that the working set from #5 is double the working set from #4. However, the OS isn’t using any more physical memory in #5 then in #4.