Linux system memory usage

I have been using the linux operating system for many years, but I don’t know much about memory usage (it is estimated that many people don’t know much about it), just recently there is a task to reduce the memory usage of the program (to run more programs on a server at the same time, the memory become the bottleneck), I took a little in-depth understanding of the usage instructions of linux memory.

Generally speaking, the top command is used to see the memory usage. The output of the top command is roughly as follows:


  PID USER PR NI  VIRT RES SHR S %CPU %MEM TIME+ COMMAND                                                                       
25335 odin 20 0 37.7g 34g 9.3g S 610.7 27.4 19127:31 norm_lquery2                                                                  
5708 odin 20 0 37.8g 34g 9.3g S 608.0 27.5 18311:43 norm_lquery1

where VIRT stands for virtual memory size, which is all the space occupied by the program in the virtual program space.
RES stands for resident set size, which is the content that the program stays in physical memory. It has a similar meaning to the memory occupied by us. If the program does not access much and the system memory is relatively tight, the content in the RES may be deleted. Replacing it to the swap space will cause a page fault when accessing it again, and replace the content in the RES again.
SHR represents shared memory (shared memory size). If the program calls commands and uses shared memory, it is reflected in this location.

Virtual memory and real memory are generally easier to confuse, the main difference is: whether physical memory is occupied. For example, if the program uses new or applies for shared memory, the operating system applies for space in the virtual memory table, but if the program does not access these spaces, it will not trigger a page fault, and it will not occupy physical memory, so it will not trigger a page fault. It will be reflected in RES.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327002892&siteId=291194637