process explorer中的visual size vs working set; private bytes vs WS private

本文详细解释了Processexplorer中进程的内存使用情况,包括虚拟内存和物理内存的多个指标,并对比了PrivateBytes与WorkingSet的区别。

在process explorer 中双击某个线程,出现Properties dialog,点击Performance tab就会出现进程的性能统计信息;

比如我机器上firefox的虚拟内存和物理内存如下:

Virtual Memory:

Virtual Size         426,124K

Private Bytes      153,352K

 

Physical Memory:

Working Set        166,292K

   WS Private       137,336K

   WS Shareable    28,956K

   WS Shared         11,296K

(WS Private + WS Shareable = Working Set;

WS Shareable包含WS Shared)

 

说明:

Working Set是fireofox使用到物理内存的大小;(physical memory)

Virtual Size是firefox使用的虚拟内存的大小;(physical memory + pages)

 

WS Private是firefox使用到的物理内存的大小,但是不包含和别的进程共享的物理内存(not shared physical memory)

Private Bytes是使用的虚拟内存量的大小,包含map到disk上的page,但是不包含和别的进行共享的虚拟内存;(not shared physical memory + not shared pages)

 

网上很多人将Private Bytes和Working Set做对比,这时没有意义的。

 

外文解释:

Virtual Bytes are the total virtual address space occupied by the entire process, including memory-mapped files such as shared DLLs. This is like the working set except it includes data that has already been paged out and is sitting in a pagefile somewhere. The total virtual bytes used by every process on a system under heavy load will add up to significantly more memory than the machine actually has.

Private Bytes refer to the amount of physical memory (RAM) that the process executable has asked for - not necessarily the amount it is actually using. Private bytes are "private" because they (usually) exclude memory-mapped files (i.e. shared DLLs). But - here's the catch - they don't necessarily exclude memory allocated by those files. So if your executable depends on any libraries - and almost every executable does - you cannot always tell whether a change in private bytes was due to the executable itself or some library it links to. Also note that "physical memory" is not a perfect description - what it really means is bytes that can be addressed without a page fault.

Working Set refers to the total physical address space used by the process. This includes memory-mapped files and quite possibly several other things; a 32-bit process can access 4 GB of address space and not all of that address space is actually memory. This is the same value that gets reported in Task Manager's "Mem Usage" and has been the source of endless amounts of confusion in recent years. Similarly to private bytes, this is "physical" in the sense that it can be addressed without a page fault.

The working set of a program is a collection of those pages in its virtual address space that have been recently referenced. It includes both shared and private data. The shared data includes pages that contain all instructions your application executes, including those in your DLLs and the system DLLs. As the working set size increases, memory demand increases.

 

其他的可参见:

http://technet.microsoft.com/en-us/library/bb742598.aspx
http://bytes.com/topic/windows/answers/626995-difference-between-physical-kernal-memory
http://smallvoid.com/article/winnt-kernel-memory.html
http://blogs.msdn.com/slavao/archive/2005/01/29/363181.aspx
http://www.ibm.com/developerworks/library/j-memusage/
http://ask-leo.com/how_do_i_find_out_whos_using_all_my_memory.html

### 区别及含义 #### Private Bytes Private Bytes 是指一个进程使用的虚拟内存量,这部分内存不包含与其他进程共享的虚拟内存[^4]。这意味着 Private Bytes 包括了那些映射到磁盘页面的内存,但这些内存不会被其他进程所使用。在诊断应用程序的内存泄漏问题时,Private Bytes 是一个重要的指标,因为它可以帮助识别出是否有一个特定的应用程序正在消耗过多的非共享资源。 #### Working Set Working Set 指的是物理内存的一部分,它既包括了属于当前进程的私有物理内存(Private Working Set),也包括了可以共享的 Working Set(Sharable Working Set)[^3]。换句话说,Working Set 包含了最近被访问过的页面,并且这些页面目前驻留在物理内存中。当系统需要更多内存时,操作系统可能会将一些页面从 Working Set 中移除并换出到分页文件中。 #### 区别 - **Private Bytes** 与 **Working Set** 的主要区别在于,前者衡量的是虚拟地址空间中的非共享部分,而后者则是物理内存中的一部分,可能包含共享和私有的内存区域。 - 在 Process Explorer 中观察这两个值可以帮助理解进程如何利用内存资源。例如,如果一个进程的 Private Bytes 值很高,则表明该进程正在使用大量的独占虚拟内存;而高 Working Set 值则表示该进程正在积极地使用大量物理内存,这可能是由于频繁的数据访问导致的。 ### 示例代码 以下是一个简单的 Python 脚本示例,用于演示如何获取某个进程的信息,包括其 Private BytesWorking Set: ```python import psutil def get_process_memory_info(pid): try: p = psutil.Process(pid) mem_info = p.memory_info() print(f"Process ID: {pid}") print(f"Private Bytes: {mem_info.private / (1024 * 1024):.2f} MB") print(f"Working Set: {mem_info.rss / (1024 * 1024):.2f} MB") except psutil.NoSuchProcess as e: print(e) # 使用实际的进程ID替换这里的PID get_process_memory_info(PID) ``` 请注意,在运行此脚本之前,请确保安装了 `psutil` 库,可以通过执行 `pip install psutil` 来安装。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值