linux 内存pss,内存耗用:VSS/RSS/PSS/USS

最近的项目由于内存吃紧,急需对内存进行缩减,这里纪录查看进程内存耗用的相关知识。摘录自网络。

Terms

VSS - Virtual Set Size,占用的虚拟内存的大小(包括共享库所占用的内存)

RSS - Resident Set Size,实际上占用的物理内存的大小(包括共享库占用)

PSS - Proportional Set Size,实际上占用的物理内存的大小(比例分配共享库占用的内存)

USS - Unique Set Size,进程肚子占用的物理内存(不包括共享库占用的内存)

Overview

The aim of this post is to provide information that will assist in interpreting memory reports from various tools so the true memory usage for Linux processes and the system can be determined. Android has a tool called procrank (/system/xbin/procrank), which lists out the memory usage of Linux processes in order from highest to lowest usage. The sizes reported per process are VSS, RSS, PSS, and USS. For the sake of simplicity in this description, memory will be expressed in terms of pages, rather than bytes. Linux systems like ours manage memory in 4096 byte pages at the lowest level. VSS (reported as VSZ from ps) is the total accessible address space of a process.This size also includes memory that may not be resident in RAM like mallocs that have been allocated but not written to. VSS is of very little use for determing real memory usage of a process. RSS is the total memory actually held in RAM for a process.RSS can be misleading, because it reports the total all of the shared libraries that the process uses, even though a shared library is only loaded into memory once regardless of how many processes use it. RSS is not an accurate representation of the memory usage for a single process. PSS differs from RSS in that it reports the proportional size of its shared libraries, i.e. if three processes all use a shared library that has 30 pages, that library will only contribute 10 pages to the PSS that is reported for each of the three processes. PSS is a very useful number because when the PSS for all processes in the system are summed together, that is a good representation for the total memory usage in the system. When a process is killed, the shared libraries that contributed to its PSS will be proportionally distributed to the PSS totals for the remaining processes still using that library. In this way PSS can be slightly misleading, because when a process is killed, PSS does not accurately represent the memory returned to the overall system. USS is the total private memory for a process, i.e. that memory that is completely unique to that process.USS is an extremely useful number because it indicates the true incremental cost of running a particular process. When a process is killed, the USS is the total memory that is actually returned to the system. USS is the best number to watch when initially suspicious of memory leaksin a process.

Overview

本片文章的目的是为了帮助理解从多种工具到处的关于Linux进程真实占用内存的报告。 Android有一个叫做procrank(/system/xbin/procrank)的工具,它可以从高到低的列出Linux进程的内存占用量。每个进程按大小可以分为VSS,RSS,PSS和USS。 为了简化描述,一下内存将以 “页”的形式来表示,而不是“字节”,像我们的Linux系统内存管理中最低级别的页有4096字节。

VSS,是一个进程总共可以访问的地址空间,其大小还包括了可能不在RAM中的内存(比如虽然malloc分配可空间,但尚未写入)。VSS很少被用于判断一个进程的真实内存使用量。

RSS是一个进程在RAM中真实存储的总内存。但是RSS还是可能会造成误导,因为它包括该进程所使用的所有共享库的大小,而不管共有多少个进程一起使用该共享库。所以RSS并不能准确反应但进程的内存占用情况。

PSS,与RSS不同,它按比例表示使用的共享库,例如:如果有三个进程都使用了同一个共享库,共占用了30页内存,那么PSS将认为每个进程分别占用该共享库10页的大小。PSS是非常有用的数据,因为系统中所有进程的PSS都相加的话,就刚好反映了系统中的全部内存占用。而当一个进程被销毁之后,其占用的共享库那部分比例的PSS,将会再次按比例分配给余下使用该库的进程。这样PSS可能会造成一点误导,因为当一个进程被销毁后,PSS不能准确的表示返回给全局系统的内存(the memory returned to the overall system)。

USS是一个进程所占用的私有内存,即该进程独占的内存。USS是非常有用的数据,因为它反映了运行一个特定进程真实的边际成本(增量成本)。当一个进程被销毁后,USS是真实返回给系统的内存。当进程中存在一个可以的内存泄漏时,USS时最佳观察数据。

58e11d785f67728c1031cd8bf3ebaa0a.png

93f1942e168245f58d803d962413d2a9.png

d5b6f405d865268f58f1e3d70f7d7278.png

070a190d1c5faf430da9930f176ea4a4.png

查看PSS的内存占用,可以通过proc文件系统下的smaps查看。

//TODO

//查看脚本

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值