MSDN中关于Working Set的一些说明

*The working set of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. 
*The working set of a process consists of the set of resident physical pages visible to the process. When a thread accesses a page that is not in the working set of its process, a page fault occurs. Before the thread can continue, the virtual memory manager must add the page to the working set of the process. A larger working set increases the probability that a page will be resident in memory, and decreases the rate of page faults.

可以把Working Set看成一个进程可以用到(但不一定会使用)的物理内存(物理内存页的集合)。内存管理单元在进行虚拟内存地址到物理内存地址转换时,如果虚拟地址不在物理内存中,会引起page fault异常。足够的WorkingSet就可以保证常用的虚拟地址都位于物理内存中,减少这种异常,避免了异常处理(例如访问swap文件,将页面读入物理内存)带来的性能损耗。因此,对于时间比较敏感的程序,应该分配足够的WorkingSet以保证程序性能。
 
*When you increase the working set size of an application, you are taking away physical memory from the rest of the system.
*Suppose you have a 16-megabyte system and you set your minimum to four megabytes. In effect, this takes away four megabytes from the system. Other applications may be unable to get their minimum working set.

可见,Working Set是被真实地从物理内存中划分出来的。一个程序占用了多少Working Set,物理内存中就有多少空间不能被其它程序使用。
 
*Reducing memory consumption is always a beneficial goal. If you call SetProcessWorkingSetSize(0xffffffff, 0xffffffff), this tells the system that your working set can be released. This does not change the current sizing of the working set, it just allows the memory to be used by other applications. It is a good idea to do this when your application goes into a wait state. 
*Windows NT 3.5 allows processes to increase their working set size by using SetProcessWorkingSetSize(). This API is also useful to trim your minimum working set size if you want to run many processes at once, because each process has the default minimum working set size reserved, no matter how small the process actually is.

Windows会为每个进程保留一个默认数值的working set,然而这个保留的Working set可能会比该process实际需要的大。可以用SetProcessWorkingSetSize()来对进程的Working set进行裁剪,只保留进程目前已经占用的页面,空闲的就释放掉给其它应用使用。

猜你喜欢

转载自netcome.iteye.com/blog/751779
今日推荐