Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between using PSS and VSZ in process memory

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

The difference between PSS and VSZ is used in process memory. For this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more small partners who want to solve this problem find a simpler and easier way.

You can use ps aux to get per-process memory usage, where VSZ is the virtual memory usage size and RSS (resident set size) is the resident memory size from the/proc/PID/status file.

~ # ps aux | headUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.4 0.1 18984 1968 ? Ss 10:58 0:47 /sbin/helloroot 2 0.0 0.0 0 0 ? S 10:58 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 10:58 0:10 [ksoftirqd/0]

But RSS does not represent the actual memory consumption of the process, because memory is shared between different processes, so the method of accumulating RSS of all processes will repeatedly calculate the shared memory, and the result will be too large. The correct way to do this is to add the Pss (process's proportional share of this mapping) field in/proc/PID/smaps. Select statistics for a VMA:

01e70000-01ef6000 rw-p 00000000 00:00 0 [heap]Size: 536 kBRss: 408 kBPss: 408 kBShared_Clean: 0 kBShared_Dirty: 0 kBPrivate_Clean: 0 kBPrivate_Dirty: 408 kBReferenced: 408 kBAnonymous: 408 kBAnonHugePages: 0 kBShmemPmdMapped: 0 kBShared_Hugetlb: 0 kBPrivate_Hugetlb: 0 kBSwap: 0 kBSwapPss: 0 kBKernelPageSize: 4 kBMMUPageSize: 4 kBLocked: 0 kBVmFlags: rd wr mr mw me ac sd

Each virtual memory area (VMA) is a contiguous range of virtual addresses, and they do not overlap. A vm_area_struct instance completely describes a memory area, including the start and end addresses, access flags, and vm_file fields used to indicate the mapped file (if any). where size represents the size of the virtual space, Rss represents the size of the resident memory, Pss represents the allocated memory size, Referenced represents the total memory size referenced or accessed, Anonymous represents the memory size not mapped to a file, Swap is also anonymous memory, and represents the size of the swap partition memory. The relationships between the fields are as follows:

USS = Private_Clean + Private_DirtyPss = USS + (Shared_Clean + Shared_Dirty)/nRSS = USS + Shared_Clean + Shared_Dirty

Take the hello process as an example, using the statistical memory data described above:

Use ps~ # ps aux| grep /sbin/helloroot 1182 0.7 0.2 474208 5636 ? Sl 11:00 1:38 /sbin/hellogrep -w Pss /proc/1182/smaps | awk 'BEGIN{sum=0} {sum+=$2} END {print "total mem:"sum}'total mem:1752

As you can see, RSS is very different from PSS. The memory statistics of the process must use Pss.

The answer to the difference between PSS and VSZ in process memory is shared here. I hope the above content can be helpful to everyone. If you still have a lot of doubts, you can pay attention to the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report