什么是Linux内存管理中的RSS和VSZ

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7880784/
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-05 06:51:24  来源:igfitidea点击:

What is RSS and VSZ in Linux memory management

linux

提问by tuban

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

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

回答by Basile Starynkevitch

They are not managed, but measured and possibly limited (see getrlimitsystem call, also on getrlimit(2)).

它们不是管理的,而是被测量的并且可能是有限的(参见getrlimit系统调用,也在getrlimit(2) 上)。

RSS means resident set size(the part of your virtual address space sitting in RAM).

RSS 表示常驻集大小(位于 RAM 中的虚拟地址空间部分)。

You can query the virtual address spaceof process 1234 using proc(5)with cat /proc/1234/mapsand its status (including memory consumption) thru cat /proc/1234/status

您可以查询虚拟地址空间使用过程1234 PROC(5)cat /proc/1234/maps它的地位(包括内存消耗)通cat /proc/1234/status

回答by caf

RSS is Resident Set Size (physically resident memory - this is currently occupying space in the machine's physical memory), and VSZ is Virtual Memory Size (address space allocated - this has addresses allocated in the process's memory map, but there isn't necessarily any actual memory behind it all right now).

RSS 是常驻集大小(物理上常驻内存 - 这是当前占用机器物理内存中的空间),而 VSZ 是虚拟内存大小(分配的地址空间 - 这在进程的内存映射中分配了地址,但不一定有任何现在它背后的实际内存)。

Note that in these days of commonplace virtual machines, physical memory from the machine's view point may not really be actual physical memory.

请注意,在当今常见的虚拟机中,从机器的角度来看,物理内存可能并不是真正的物理内存。

回答by jmh

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.

RSS 是常驻集大小,用于显示分配给该进程以及在 RAM 中的内存量。它不包括换出的内存。它确实包括来自共享库的内存,只要这些库中的页面实际上在内存中。它确实包括所有堆栈和堆内存。

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.

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

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:

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

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

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 值相加,您很容易得到比系统更多的空间。

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.

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

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(比例设置大小)。这是一种较新的度量,它跟踪共享内存作为当前进程使用的比例。因此,如果之前有两个进程使用相同的共享库:

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

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.

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

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

还有比这更多的方法,要了解更多信息,请查看以下参考资料:

Also see:

另见:

回答by Anugraha Sinha

I think much has already been said, about RSS vs VSZ. From an administrator/programmer/user perspective, when I design/code applications I am more concerned about the RSZ, (Resident memory), as and when you keep pulling more and more variables (heaped) you will see this value shooting up. Try a simple program to build malloc based space allocation in loop, and make sure you fill data in that malloc'd space. RSS keeps moving up. As far as VSZ is concerned, it's more of virtual memory mapping that linux does, and one of its core features derived out of conventional operating system concepts. The VSZ management is done by Virtual memory management of the kernel, for more info on VSZ, see Robert Love's description on mm_struct and vm_struct, which are part of basic task_struct data structure in kernel.

我认为关于 RSS 与 VSZ 已经说了很多。从管理员/程序员/用户的角度来看,当我设计/编码应用程序时,我更关心 RSZ(驻留内存),因为当您不断提取越来越多的变量(堆积)时,您会看到这个值飙升。尝试一个简单的程序在循环中构建基于 malloc 的空间分配,并确保在该 malloc 空间中填充数据。RSS 不断上升。就VSZ而言,它更多是linux所做的虚拟内存映射,其核心特性之一源自传统的操作系统概念。VSZ 管理由内核的虚拟内存管理完成,有关 VSZ 的更多信息,请参阅 Robert Love 对 mm_struct 和 vm_struct 的描述,它们是内核中基本 task_struct 数据结构的一部分。