Why is the total RSS sum of PS larger than the actual physical memory

When using ps aux to view system processes, the sixth column, the RSS column, shows the physical memory used by the process.
But when adding this column of all processes in the system, the sum obtained is much higher than the actual physical memory of the system? what on earth is this kind of happenings?
Just take a look at how Linux manages memory.
What I understand is this. Linux will allocate a certain amount of memory to each process when it is spawned. This is just allocation, and the VSZ column reflected in ps is called virtual memory. But in fact these processes do not occupy these memory. May wish, I also borrowed an example from the Internet to describe it, just like a bank pays its employees, each employee has his own bank card, and the bank will transfer a fixed amount of money to the employee’s bank card every month. But this process is not about sending actual money to employees, it’s just a bunch of numbers. In fact, banks don’t have that much money. Let’s look back and see if Linux allocates memory to a process. Is it similar to the above example?
After talking about the above point of view, I still can’t answer the question set by the author, so continue to discuss:
When adding up this column of all processes in the system, the sum obtained is much higher than the actual system. Physical memory? This is because the result of ps, the RSS part, includes shared memory. Here is a look at using pmap.
pmap -d 24030
24030: /usr/local/php/bin/php-cgi –fpm –fpm-config /usr/local/php/etc/php-fpm.conf
Address Kbytes Mode Offset Device Mapping
0000000000400000 6444 rx– 0000000000000000 008:00002 php-cgi
0000000000c4b000 272 rw— 000000000064b000 00-000-00000 php-cgi
000000–000-00000000: 0000c8f000: 00000052 r 000000-0000c8f000: anon]
00000000059dc000 9572 rw— 00000000059dc000 000:00000 [anon]
0000003519000000 508 rx– 0000000000000000 008:00002 libfreetype.so.6.3.10
000000351907f000 2048 —– 000000000007f000 008: 00002 libfreetype.so.6.3.10
The middle part is omitted
00002b757df75000 4 rw— 000000000000a000 008:00002 libnss_files-2.5.so
00002b757df76000 32768 rw-s- 0000000000000000 000:00008 zero (deleted) < br> 00002b7580685000 4 rw-s- 0000000000000000 000:00008 zero (deleted)
00007fff2e126000 476 rwx– 00007fff2e126000 000:00000 [stack]
00007fff2e19d000 8 rw — 00007fff2e19d000 000:00000   [ anon ]
ffffffffff600000    8192 —– 0000000000000000 000:00000   [ anon ]
mapped: 139548K    writeable/private: 12344K    shared: 32772K

pmap是用To display the memory usage instructions, -d is followed by the process id. For the use of pmap and the displayed data, please see http://mylinux.5d6d.com/thread-977-1-1.html linux will share some Libraries are loaded into memory. In the output of pmap, the names of these shared libraries are usually lib*.so, such as libX11.so.6.2.0. This libX11.so.6.2.0 will be loaded by many processes into its own operating environment. At the same time, in the RSS results output by ps, each process contains this libX11.so.6.2.0, but in fact it is only Once the load is loaded, if you simply add the results of ps, the calculation will be repeated. Looking at the output of pmap, in fact, the memory occupied by the php-cgi pure process is writeable/private: 12344K

Leave a Comment

Your email address will not be published.