Android 这个关于 VSS/RSS/PSS/USS 的解释准确吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22372960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:53:36  来源:igfitidea点击:

Is this explanation about VSS/RSS/PSS/USS accurate?

androidmemory-management

提问by Victor S

I read an explanation about VSS/RSS/PSS/USS:

我读了一篇关于 VSS/RSS/PSS/USS 的解释:



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.

这篇文章的目的是提供有助于解释来自各种工具的内存报告的信息,以便确定 Linux 进程和系统的真实内存使用情况。

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.

Android 有一个工具叫 procrank (/system/xbin/procrank),它按使用率从高到低的顺序列出了 Linux 进程的内存使用情况。每个进程报告的大小是 VSS、RSS、PSS 和 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.

为了在本描述中简单起见,存储器将以页而不是字节来表示。像我们这样的 Linux 系统在最低级别以 4096 字节的页面管理内存。

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.

VSS(从 ps 报告为 VSZ)是进程的总可访问地址空间。此大小还包括可能不会驻留在 RAM 中的内存,如已分配但未写入的 malloc。VSS 很少用于确定进程的实际内存使用情况。

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.

RSS 是进程实际在 RAM 中保存的总内存。RSS 可能会产生误导,因为它报告了进程使用的所有共享库的总数,即使共享库只加载到内存中而不管有多少进程使用它。RSS 不能准确表示单个进程的内存使用情况。

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.

PSS 与 RSS 的不同之处在于它报告其共享库的比例大小,即如果三个进程都使用一个具有 30 页的共享库,则该库将只向 PSS 贡献 10 页,而这三个进程中的每一个都报告。PSS 是一个非常有用的数字,因为当系统中所有进程的 PSS 相加时,它可以很好地表示系统中的总内存使用量。当一个进程被终止时,为其 PSS 做出贡献的共享库将按比例分配到仍在使用该库的其余进程的 PSS 总数。这样 PSS 可能会有点误导,因为当一个进程被杀死时,PSS 并不能准确地表示返回给整个系统的内存。

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 leaks in a process.

USS 是进程的总私有内存,即该进程完全唯一的内存。USS 是一个非常有用的数字,因为它表示运行特定流程的真实增量成本。当一个进程被杀死时,USS 是实际返回给系统的总内存。当最初怀疑进程中的内存泄漏时,USS 是最好的观察数字。

For systems that have Python available, there is also a nice tool called smem that will report memory statistics including all of these categories.

对于具有可用 Python 的系统,还有一个名为 smem 的好工具,它将报告包括所有这些类别的内存统计信息。

# procrank
procrank
PID      Vss        Rss           Pss         Uss   cmdline
481   31536K   30936K   14337K    9956K  system_server
475   26128K   26128K   10046K    5992K  zygote
526   25108K   25108K    9225K    5384K  android.process.acore
523   22388K   22388K    7166K    3432K  com.android.phone
574   21632K   21632K    6109K    2468K  com.android.settings
521   20816K   20816K    6050K    2776K  jp.co.omronsoft.openwnn
474    3304K    3304K    1097K     624K   /system/bin/mediaserver
37     304K      304K     289K      288K  /sbin/adbd
29     720K      720K     261K      212K  /system/bin/rild
601     412K     412K     225K      216K  procrank
   1     204K     204K     185K      184K  /init
35     388K     388K     182K      172K  /system/bin/qemud
284     384K     384K     160K      148K  top
27     376K     376K     148K      136K  /system/bin/vold
261     332K     332K     123K     112K  logcat
33     396K     396K     105K       80K   /system/bin/keystore
32     316K     316K     100K       88K   /system/bin/installd
269     328K     328K      95K       72K  /system/bin/sh
26     280K     280K      93K       84K   /system/bin/servicemanager
45     304K     304K      91K       80K   /system/bin/qemu-props
34     324K     324K      91K       68K   /system/bin/sh
260     324K     324K      91K       68K   /system/bin/sh
600     324K     324K      91K      68K   /system/bin/sh
25     308K     308K      88K       68K   /system/bin/sh
28     232K     232K      67K       60K   /system/bin/debuggerd
#


But I cannot find the original of this article, and I would like to know whether this explanation is accurate.

但是我找不到这篇文章的原文,我想知道这个解释是否准确。

采纳答案by Skeets

That sounds correct and also lines up with the description found here: http://elinux.org/Android_Memory_Usage

这听起来是正确的,并且与此处的描述一致:http: //elinux.org/Android_Memory_Usage

From the page...

从页面...

  • Vss = virtual set size
  • Rss = resident set size
  • Pss = proportional set size
  • Uss = unique set size
  • Vss = 虚拟集大小
  • Rss = 常驻集大小
  • Pss = 比例集大小
  • Uss = 独特的套装尺寸