Linux内存管理中的RSS和VSZ是什么 [英] What is RSS and VSZ in Linux memory management

查看:348
本文介绍了Linux内存管理中的RSS和VSZ是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux内存管理中的RSS和VSZ是什么?在多线程环境中,如何同时管理和跟踪这两者?

What are RSS and VSZ in Linux memory management? In a multithreaded environment how can both of these can be managed and tracked?

推荐答案

RSS是常驻集大小,用于显示为该进程分配了多少内存并位于RAM中.它不包括换出的内存.只要共享库中的页面实际在内存中,它就包括共享库中的内存.它确实包括所有堆栈和堆内存.

RSS is the Resident Set Size and is used to show how much memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory.

VSZ是虚拟内存大小.它包括该进程可以访问的所有内存,包括换出的内存,已分配但未使用的内存以及来自共享库的内存.

VSZ is the Virtual Memory Size. It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.

因此,如果进程A具有500K二进制文件并链接到2500K共享库,则具有200K的堆栈/堆分配,其中100K实际上在内存中(其余部分已交换或未使用),并且它实际上仅加载了1000K的共享库和自己的二进制文件400K然后:

So if process A has a 500K binary and is linked to 2500K of shared libraries, has 200K of stack/heap allocations of which 100K is actually in memory (rest is swapped or unused), and it has only actually loaded 1000K of the shared libraries and 400K of its own binary then:

RSS: 400K + 1000K + 100K = 1500K
VSZ: 500K + 2500K + 200K = 3200K

由于部分内存是共享的,因此许多进程可能会使用它,因此,如果您将所有RSS值相加,则最终可能会比系统拥有更多的空间.

Since part of the memory is shared, many processes may use it, so if you add up all of the RSS values you can easily end up with more space than your system has.

分配的内存也可能不在RSS中,直到程序实际使用它为止.因此,如果您的程序预先分配了一堆内存,然后随着时间的推移使用它,您可能会看到RSS上升而VSZ保持不变.

The memory that is allocated also may not be in RSS until it is actually used by the program. So if your program allocated a bunch of memory up front, then uses it over time, you could see RSS going up and VSZ staying the same.

还有PSS(比例设置大小).这是一个较新的度量,它跟踪共享内存作为当前进程使用的比例.因此,如果以前有两个进程使用相同的共享库:

There is also PSS (proportional set size). This is a newer measure which tracks the shared memory as a proportion used by the current process. So if there were two processes using the same shared library from before:

PSS: 400K + (1000K/2) + 100K = 400K + 500K + 100K = 1000K

所有线程共享相同的地址空间,因此每个线程的RSS,VSZ和PSS与该过程中的所有其他线程相同.使用ps或top在linux/unix中查看此信息.

Threads all share the same address space, so the RSS, VSZ and PSS for each thread is identical to all of the other threads in the process. Use ps or top to view this information in linux/unix.

要了解更多信息,请检查以下参考文献:

There is way more to it than this, to learn more check the following references:

  • http://manpages.ubuntu.com/manpages/en/man1/ps.1.html
  • https://web.archive.org/web/20120520221529/http://emilics.com/blog/article/mconsumption.html

另请参阅:

这篇关于Linux内存管理中的RSS和VSZ是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆