prstat 输出中 SIZE 和 RSS 值的含义

发布于 2024-07-09 06:39:34 字数 300 浏览 7 评论 0原文

有人可以清楚地解释我们从 Solaris 中的 prstat 获得的 SIZE 和 RSS 值的含义吗?

我编写了一个测试 C++ 应用程序,它使用 new[] 分配内存,填充它并使用 delete[] 释放它。

据我了解,SIZE值应该与进程“保留”了多少虚拟内存有关,即内存“分配”或“新建”。

除非我真正使用它(填充一些值),否则该内存不会汇总在 RSS 值中。 但即使我释放内存,RSS 也不会丢失。

我不明白我可以正确分配给这两个值的语义。

Can somebody give some clear explanation of the meaning of the SIZE and RSS values we get from prstat in Solaris?

I wrote a testing C++ application that allocates memory with new[], fills it and frees it with delete[].

As I understood, the SIZE value should be related to how much virtual memory has been "reserved" by the process, that is memory "malloced" or "newed".

That memory doesn't sum up in the RSS value unless I really use it (filling with some values). But then even if I free the memory, the RSS doesn't drop.

I don't understand what semantic I can correctly assign to those 2 values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝礼 2024-07-16 06:39:34

RSS(据我所知可靠)表示进程正在使用多少物理内存。 使用 Solaris 默认内存分配器,释放内存不会对 RSS 执行任何操作,因为它只是更改一些指针和值以告知内存可以自由重用。
如果您不通过再次分配来再次使用该内存,它最终将被分页并且 RSS 将丢失。

如果您希望在释放后立即返回释放的内存,可以使用 Solaris mmap 分配器,如下所示:

export LD_PRELOAD=libumem.so
export UMEM_OPTIONS=backend=mmap

RSS is (AFAIK reliably) representing how much physical memory a process is using. Using Solaris default memory allocator, freeing memory doesn't do anything about RSS as it just changes some pointers and values to tell that memory is free to be reused.
If you don't use again that memory by allocating it again, it will eventually be paginated out and the RSS will drop.

If you want freed memory to be returned immediately after a free, you can use the Solaris mmap allocator like this:

export LD_PRELOAD=libumem.so
export UMEM_OPTIONS=backend=mmap
夏了南城 2024-07-16 06:39:34

Size是进程的总虚拟内存大小,包括所有映射文件和设备,而RSS应该是常驻集大小,但完全不可靠,你应该尝试从pmap获取该信息。

Size is the total virtual memory size of the process, including all mapped files and devices, and RSS should be the resident set size, but is completely unreliable, you should try to get that information from pmap.

蓝咒 2024-07-16 06:39:34

一般来说,一旦内存被分配给进程,它就永远不会返还给操作系统。 在 Unix 系统上,sbrk() 调用用于扩展进程地址空间,并且没有类似的调用可以用于另一个方向。

As a general rule once memory is allocated to a process it will never be given back to the operating system. On Unix systems the sbrk() call is used to extend the processes address space, and there is not analogous call to go in the other direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文