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
Under Linux, look at a running program, how much memory is being consumed