Article Title: Linux memory monitoring. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In Windows, it is very easy to view the memory usage. I think everyone is familiar with it. How can I check the memory usage in Linux? The following is a free command for checking memory usage in Linux:
1. [root @ scs-2 tmp] # free
2. total used free shared buffers cached
3. Mem: 3266180 3250004 16176 0 110652 2668236
4.-/+ buffers/cache: 471116 2795064
5. Swap: 2048276 80160 1968116
The following is an explanation of these values:
Total: total physical memory size.
Used: used.
Free: available.
Shared: The total memory Shared by multiple processes.
Buffers/cached: disk cache size.
Row 3 (-/+ buffers/cached ):
Used: used.
Free: available.
The fourth line won't be explained much.
Difference: used/free of the second row (mem) differs from used/free of the third row (-/+ buffers/cache. The difference between the two is that from the perspective of usage, the first line is from the OS perspective, because for OS, buffers/cached is used, so its available memory is 16176KB, the memory used is kb, including the + buffers + cached used by the kernel (OS) + Application (X, oracle, etc.
The third line indicates that, from the application perspective, for applications, buffers/cached is equivalent to available, because buffer/cached is designed to improve file read performance, when the application needs to use the memory, buffer/cached will be quickly recycled.
From the application perspective, the available memory = system free memory + buffers + cached.
For example:
2795064 = 16176 + 110652 + 2668236
Next, we will explain when the memory will be exchanged and by which side. When the available memory is less than the rated value, a meeting will be held for exchange.
Rating:
1. cat/proc/meminfo
2. [root @ scs-2 tmp] # cat/proc/meminfo
3. MemTotal: 3266180 kB
4. MemFree: 17456 kB
5. Buffers: 111328 kB
6. Cached: 2664024 kB
7. SwapCached: 0 kB
8. "Active": 467236 kB
9. Inactive: 2644928 kB
10. HighTotal: 0 kB
11. HighFree: 0 kB
12. LowTotal: 3266180 kB
13. LowFree: 17456 kB
14. SwapTotal: 2048276 kB
15. SwapFree: 1968116 kB
16. Dirty: 8 kB
17. Writeback: 0 kB
18. Mapped: 345360 kB
19. Slab: 112344 kB
20. Committed_AS: 535292 kB
21. PageTables: 2340 kB
22. VmallocTotal: 536870911 kB
23. VmallocUsed: 272696 kB
24. VmallocChunk: 536598175 kB
25. HugePages_Total: 0
26. HugePages_Free: 0
27. Hugepagesize: 2048 kB
View the result in free-m:
1. [root @ scs-2 tmp] # free-m
2. total used free shared buffers cached
3. Mem: 3189 3173 16 0 107 2605
4.-/+ buffers/cache: 460 2729
5. Swap: 2000 78 1921
View the size of the/proc/kcore file (memory image ):
1. [root @ scs-2 tmp] # ll-h/proc/kcore
2.-r --- 1 root 4.1G Jun 12 12:04/proc/kcore
Note:
Memory usage Measurement
Measure how much memory a process occupies. Linux provides us with a very convenient method. The/proc Directory provides us with all the information, in fact, the top tool also obtains the corresponding information here.
1./proc/meminfo memory usage information of the machine
2./proc/pid/maps pid indicates the process number and displays the virtual address occupied by the current process.
3. Memory occupied by/proc/pid/statm Process
4. [root @ localhost ~] # Cat/proc/self/statm
5.654 57 44 0 0 334 0
Output description
CPU and CPU 0... The meaning of each parameter in each row (in the first behavior example) is:
Parameter description/proc // status
Size (pages) task virtual address space Size VmSize/4
The size of the physical memory that the Resident (pages) application is using VmRSS/4
Shared (pages) Shared pages 0
Size of executable virtual memory owned by the Trs (pages) program VmExe/4
The size of the library that the Lrs (pages) is mapped to the virtual memory space of the task. VmLib/4
Drs (pages) Program Data Segment and user-state stack size (VmData + VmStk) 4
Dt (pages) 04
View available machine memory
1./proc/28248/> free
2. total used free shared buffers cached
3. Mem: 1023788 926400 97388 0 134668 503688
4.-/+ buffers/cache: 288044 735744
5. Swap: 1959920 89608 1870312
When we run the free command to view the idle memory of the machine, we will find that the free value is very small. This is mainly because there is such an idea in the Linux system that the memory does not need to be white, so it tries its best to cache and buffer some data to facilitate the next use. But in fact, these memories can also be used immediately.
So free memory = free + buffers + cached = total-used