内存耗用:VSS/RSS/PSS/USS

news/2024/7/20 13:17:21 标签: 移动开发, python, 内存管理

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

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

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时最佳观察数据。

看到网上有副图画的比较直观(https://yq.aliyun.com/articles/24048)

VSSRSSPSSUSS

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

//TODO

//查看脚本

转载于:https://my.oschina.net/u/2561528/blog/1588667


http://www.niftyadmin.cn/n/1694852.html

相关文章

lucene学习

什么是lucene Lucene的目的是为软件开发人员提供一个简单易用的工具包,以方便在目标系统中实现全文检索的功能,或者是以此为基础建立起完整的全文检索引擎 为什么我们要用Lucene?对比数据库 1.lucene可以对文件进行检索,这是数…

zabbix3.0中文显示乱码的问题

[rootzabbix-server include]# pwd /usr/share/zabbix/include [rootzabbix-server include]# vi defines.inc.php #修改第93行 define(ZBX_FONT_NAME,msyh); #修改第45行改为 define(ZBX_GRAPH_FONT_NAME,msyh) 然后下载微软雅黑字体,改名为msyh传入 /usr/share/za…

缓存常见问题以及解决方法

缓存雪崩 如果缓存集中在一段时间内失效,发生大量的缓存穿透,所有的查询都落在数据库上,就造成了缓存雪崩。 如何解决缓存雪崩 如果缓存经常在一个时间消失,就要考虑key的过期时间是不是一样的,可以随机一下过期时间…

分支结构和循环结构

上节课的回顾 print(f{a:> 30.3f })其中的30.3f 的30表示使用30个字符, .3f表示保留小数点后3位,可参照下面: # 获得用户输入的一个整数a,计算a的平方根,保留小数点后3位,并打印输出。‪‬‪‬‪‬‪‬‪…

java获取子类 转

获取子类 package com.tools;import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.…

python学习之socket黏包

7.4 socket ​ 【重要】 避免学习各层的接口,以及协议的使用, socket已经封装好了所有的接口,直接使用这些接口或者方法即可,方便快捷,提升开发效率。 socket在python中就是一个模块,通过使用学习模块提供的功能,建立两个进程之间的连接和通信&#xff0…

Runtime的应用

来自&#xff1a;http://www.imlifengfeng.com/blog/?p397 1、快速归档 (id)initWithCoder:(NSCoder *)aDecoder { if (self [super init]) { unsigned int outCount; Ivar * ivars class_copyIvarList([self class], &outCount); for (int i 0; i < outCount; i ) …

Centos6.5操作系统mysql-5.5安装多实例

Centos6.5操作系统mysql-5.5安装多实例 MySQL多实例就是在一台机器上开启多个不同的服务端口&#xff08;如&#xff1a;3306,3307,3308&#xff09;&#xff0c;运行多个MySQL服务进程&#xff0c;通过不同的socket监听不同的服务端口来提供各自的服务。各个实例之间是相互独…