I'm confused with the concept of Working Set ,while reading the Memory Management code of the Windows Research Kernel.
Roughly, the working set is the areas of memory in active use. http://en.wikipedia.org/wiki/Working_set
The "working set" is short hand for "parts of memory that the current algorithm is using" and is determined by which parts of memory the CPU just happens to access. It is totally automatic to you. If you are processing an array and storing the results in a table, the array and the table are your working set.
This is discussed because the CPU will automatically store accessed memory in cache, close to the processor. The working set is a nice way to describe the memory you want stored. If it is small enough, it can all fit in the cache and your algorithm will run very fast. On the OS level, the kernel has to tell the CPU where to find the physical memory your application is using (resolving virtual addresses) every time you access a new page (typically 4k in size) so also you want to avoid that hit as much as possible.
See What Every Programmer Should Know About Memory - PDF for graphs of algorithm performance vs size of working set (around page 23) and lots of other interesting info.
Basically - write your code to access the smallest amount of memory possible (i.e classes are small, not too many of them), and try to ensure tight loops run on a very very small subset of that memory.
All the memory your program is using that is not in the "working set" is marked for swap to disk. When the operating system needs more memory for other work it will try to keep the working set of each program in memory, but everything else is up for grabs.
The "working set" is an informal term meaning the memory that's being accessed "frequently" (for some definition of frequently) by an application or set of applications. Applications may also allocate memory that they access infrequently (no more than once every few dozen seconds, perhaps not even once an hour); this would be outside of the working set.
An example might be if you have two Firefox Windows, a minimized one that you haven't looked at for several hours, and an open one that you're browsing in right now. The memory used to store the data associated with the open window is going to be in the working set; the memory used to store the data associated with the window that's not open and that you haven't looked at for several hours is not in the working set.
This is mainly used in discussions about whether you have enough RAM in your system. If your working set is smaller than your RAM, you can work comfortably, because the data your program or programs frequently access is always in memory. If your working set is larger than your RAM, the operating system will be constantly swapping pages out to disk to make room to swap in pages that an application wants to access; these swapped out pages, being in the working set, will almost immediately be needed again, meaning that you've got to take other pages and write them out to disk, and it just goes on and on like this. This is referred to as "thrashing."
If you're not reading or writing many files, your disk light is on all the time, and your system feels very slow, that's a pretty good sign that you're thrashing.
The working set is the set of pages that are physically in memory at any one time. Although the working set if quoted and displayed in kilobytes the smallest working set you can have is 4k (8K on Itanium) as thats the size of a page in Windows.
To see the working set of a process look at the "Mem Usage" column in the task manager's "Processes" tab.
If you're running a .NET app you can watch the working set be reduced looking at the process in the task manager process tab and then minimizing the application. Its working set is dramatically reduced as Windows swaps it out to the page file (since the process is assumed to not be "working" as much).