1. Under Linux, look at a running program, how much memory is consumed, and the general commands are
(1). PS aux:
where the VSZ (or VSS) column represents how much virtual memory the program occupies.
The RSS column indicates how much physical memory the program occupies.
Virtual memory is not considered, it does not occupy actual physical memory.
(2). The top command can also
where the VIRT (or VSS) column indicates how much virtual memory the program occupies. The vsz column in the same PS aux
The Res column indicates how much physical memory the program occupies. RSS columns in the same PS aux
2. Under Linux, see how much memory is being consumed by the current system, and the General command is free
Where free is the system and how much memory is available.
But because the Linux system has a principle for memory usage, it is that memory is valuable and how much can be used. So, Linux caches the already-called packages and puts them in memory.
Thus, in fact, the memory that can be used can be understood as, free+buffers+cached
3. When you are finished with these commands, you will find a strange phenomenon when you use the PS aux command to check it out.
All of the data in the RSS column, added up, is much larger than the number of physical memory.
For example, the physical memory is 2G, and the RSS column data add up, there may be 5 g more, what is the matter?
This is because the value of the RSS column deceives us.
The memory mechanism of Linux is this:
When you run a program, Linux calls the link libraries that the program relies on, such as lib.xx.so. First see if the link library is mapped into memory, and if it is not mapped, the code snippet and data segment are mapped into memory, otherwise they are simply added to the process's address space.
Thus, when n programs, dependent on lib.xx.so, in fact, there is only one lib.xx.so in memory, not N.
While RSS shows a program occupies the actual physical memory, will lib.xx.so also come in.
For example, x program, itself occupies 5 m of memory, Lib.xx.so occupies memory 2m,lib.xx.so by n programs share dependency. The RSS shows that the X program runs and consumes 7M of memory. In fact, the X program takes up 5M of space. The extra 2m is included in the RSS feed.
When you use PS aux display memory consumption, n shared dependent lib.xx.so n programs, all of this 2m space, counted in their own RSS, so that the sum of the RSS value, more than the actual physical memory.
Of course, the memory use mechanism of Linux is very complex, not a sentence can be said clearly. Here is a simple explanation, the PS aux RSS value, and does not reflect the actual use of physical memory.
4. If you are looking at more detailed memory usage, you can use several methods, or several methods, in combination:
These methods require the privileges of the root account.
(1). pmap-d $pid
$pid is the PID of the running program
(2). cat/proc/$pid/smaps
Smaps's data is more detailed, can be summed up briefly, the order of induction is as follows:
cat/proc/$pid/smaps | awk '/size| rss| pss| shared| private| referenced| Swap/{val_name=gensub (/([a-za-z_]*). */, "\\1", 1,$1); list[val_name]+=$2;} End{for (val in list) print Val,list[val];} '
(3). cat/proc/$pid/maps
(4). cat/proc/$pid/STATM
Output interpretation
First column Size: task virtual address space size
Second column resident: the size of the physical memory being used
Third column shared: number of shared pages
Fourth Trs: The size of executable virtual memory owned by the program
Fifth-column Lrs: The size of the library of virtual memory space that is being imaged by the task
Sixth column Drs: size of program data segment and stack of user state
Seventh Column dt: number of dirty pages
(5). Vmstat
This command is said to provide some reference information, not yet studied
5. As a phper, tried to use PHP function Memory_get_usage (), the function also can not get PHP currently running program, actual, really occupy the amount of memory.
If you really want to, PHP really occupies the memory, probably only in, the beginning of the program run, the execution of Memory_get_usage ().
At the end of the program run, Memory_get_usage () is executed once. Subtract the values from the two, and the resulting value should be a relatively accurate, memory-intensive amount.
This method has not been tested, considering, get this amount, also no practical significance, plus usually busy, too lazy to try.
Perhaps PHP also has a method, is to use the Shm_* series functions, which I also did not delve into, see this article (http://duckweeds.blog.sohu.com/166663796.html)
6. There are also some articles that can be consulted, as follows:
(1) A C programmer, the eyes of the Linux memory use in detail, write more detailed, more detailed, but also more professional.
(2) Detailed description of the/PROC/PID/STATM
(3) Simple interpretation of STATM, maps, MEMMAP memory information file analysis under Linux/proc
(4) Use of shared memory in PHP
(5) Memory Usage with Smaps
(6) capturing Process Memory Usage under Linux , this article seems to be an advertisement for a product, but it has a detailed explanation of the concepts of Uss,pss,rss .
(7) elc:how Much memory is applications really using, as (6), is the same product advertising, the article has some things to refer to
(8) Linux Check Memory Usage, the article on free, vmstat,top, Gnome-system-monitor and other commands have some introduction
(9) Console monitoring Tools for SUSE Linux , the Top,free,uptime,pmap,smartctl,iostat,strace and other orders are introduced, and the introduction of a more detailed, at present only a cursory look at, have time to look again.
(10) The Solaris 9 Enhanced Pmap, which describes the application of pmap in more detail, is nothing more than a Solaris 9-based
Linux, a running program, how much memory occupied