Linux system memory information retrieval

Source: Internet
Author: User
Memory, CPU, and I/O are the main bottlenecks of type servers, especially database servers. The CPU is a renewable resource, and it will be available if it is not enough. The memory and the land are the same as non-renewable resources and are occupied, and the subsequent usage must wait until the resource is released. IO is also very dependent on memory usage... memory, CPU, and I/O are the main bottlenecks of type servers, especially database servers. The CPU is a renewable resource, and it will be available if it is not enough. The memory and the land are the same as non-renewable resources and are occupied, and the subsequent usage must wait until the resource is released. IO is also very dependent on the memory usage, so the memory efficiency will greatly affect the server efficiency, so it is very important to understand the server memory usage.
 
The memory information of the Linux kernel mainly includes the following several obtaining pipelines. here we mainly discuss the system level, not specific to each process level:
 
1. During kernel startup, VM memory-related module initialization information is viewed through dmesg.
For details, refer to here
For example:
 
NUMA: Using 30 for the hash shift.
Bootmem setup node 0 0000000000000000-0000000340000000
Bootmem setup node 1 0000000340000000-0000000640000000
On node 0 totalpages: 3095549
DMA zones: 2613 pages, LIFO batch: 0
DMA32 zone: 765896 pages, LIFO batch: 31
Normal zone: 2327040 pages, LIFO batch: 31
On node 1 totalpages: 3102720
Normal zone: 3102720 pages, LIFO batch: 31
...
Memory: 24543920 k/26214400 k available (2547 k kernel code, 612792 k reserved, 1289 k data, 208 k init)
...
Total HugeTLB memory allocated, 0
...
 
2./proc/meminfo.
For the meaning of each field, see here
For example:
$ Cat/proc/meminfo
MemTotal: 24545764 kB
MemFree: 957064 kB
Buffers': 1739164 kB
Cached: 10699300 kB
SwapCached: 3816 kB
Active: 17884180 kB
Inactive: 4479128 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 24545764 kB
LowFree: 957064 kB
SwapTotal: 6289320 kB
SwapFree: 5005124 kB
Dirty: 28 kB
Writeback: 0 kB
AnonPages: 9923908 kB
Mapped: 27068 kB
Slab: 1132452 kB
PageTables: 41560 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 18562200 kB
Committed_AS: 33474640 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 268160 kB
VmallocChunk: 34359470063 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
 
3. the m key of sysrq-trigger.
First enable this feature:
Sudo sysctl kernel. sysrq = 1
Get help:
Echo h | sudo tee/proc/sysrq-trigger
SysRq: HELP: loglevel0-8 reBoot Crashdump tErm Full kIll thaw-filesystems (J) saK showMem Nice powerOff showPc unRaw Sync showTasks Unmount shoWcpus
Obtain memory information:
Echo m | sudo tee/proc/sysrq-trigger
 
SysRq: Show Memory
Mem-info:
Node 0 DMA per-cpu:
Cpu 0 hot: high 0, batch 1 used: 0
Cpu 0 cold: high 0, batch 1 used: 0
Cpu 1 hot: high 0, batch 1 used: 0
Cpu 1 cold: high 0, batch 1 used: 0
Cpu 2 hot: high 0, batch 1 used: 0
Cpu 2 cold: high 0, batch 1 used: 0
Cpu 3 hot: high 0, batch 1 used: 0
Cpu 3 cold: high 0, batch 1 used: 0
Cpu 4 hot: high 0, batch 1 used: 0
Cpu 4 cold: high 0, batch 1 used: 0
Cpu 5 hot: high 0, batch 1 used: 0
Cpu 5 cold: high 0, batch 1 used: 0
Cpu 6 hot: high 0, batch 1 used: 0
Cpu 6 cold: high 0, batch 1 used: 0
Cpu 7 hot: high 0, batch 1 used: 0
Cpu 7 cold: high 0, batch 1 used: 0
Cpu 8 hot: high 0, batch 1 used: 0
Cpu 8 cold: high 0, batch 1 used: 0
Cpu 9 hot: high 0, batch 1 used: 0
Cpu 9 cold: high 0, batch 1 used: 0
Cpu 10 hot: high 0, batch 1 used: 0
Cpu 10 cold: high 0, batch 1 used: 0
Cpu 11 hot: high 0, batch 1 used: 0
Cpu 11 cold: high 0, batch 1 used: 0
Cpu 12 hot: high 0, batch 1 used: 0
Cpu 12 cold: high 0, batch 1 used: 0
Cpu 13 hot: high 0, batch 1 used: 0
Cpu 13 cold: high 0, batch 1 used: 0
Cpu 14 hot: high 0, batch 1 used: 0
Cpu 14 cold: high 0, batch 1 used: 0
Cpu 15 hot: high 0, batch 1 used: 0
Cpu 15 cold: high 0, batch 1 used: 0
Node 0 DMA32 per-cpu:
Cpu 0 hot: high 186, batch 31 used: 70
Cpu 0 cold: high 62, batch 15 used: 59
Cpu 1 hot: high 186, batch 31 used: 24
Cpu 1 cold: high 62, batch 15 used: 13
Cpu 2 hot: high 186, batch 31 used: 7
Cpu 2 cold: high 62, batch 15 used: 11
Cpu 3 hot: high 186, batch 31 used: 19
Cpu 3 cold: high 62, batch 15 used: 54
Cpu 4 hot: high 186, batch 31 used: 0
Cpu 4 cold: high 62, batch 15 used: 0
Cpu 5 hot: high 186, batch 31 used: 0
Cpu 5 cold: high 62, batch 15 used: 0
Cpu 6 hot: high 186, batch 31 used: 0
Cpu 6 cold: high 62, batch 15 used: 0
Cpu 7 hot: high 186, batch 31 used: 0
Cpu 7 cold: high 62, batch 15 used: 0
Cpu 8 hot: high 186, batch 31 used: 16
Cpu 8 cold: high 62, batch 15 used: 50
Cpu 9 hot: high 186, batch 31 used: 23
Cpu 9 cold: high 62, batch 15 used: 2
Cpu 10 hot: high 186, batch 31 used: 40
Cpu 10 cold: high 62, batch 15 used: 41
Cpu 11 hot: high 186, batch 31 used: 157
Cpu 11 cold: high 62, batch 15 used: 5
Cpu 12 hot: high 186, batch 31 used: 0
Cpu 12 cold: high 62, batch 15 used: 0
Cpu 13 hot: high 186, batch 31 used: 0
Cpu 13 cold: high 62, batch 15 used: 0
Cpu 14 hot: high 186, batch 31 used: 0
Cpu 14 cold: high 62, batch 15 used: 0
Cpu 15 hot: high 186, batch 31 used: 0
Cpu 15 cold: high 62, batch 15 used: 0
Node 0 Normal per-cpu:
Cpu 0 hot: high 186, batch 31 used: 50
Cpu 0 cold: high 62, batch 15 used: 13
Cpu 1 hot: high 186, batch 31 used: 159
Cpu 1 cold: high 62, batch 15 used: 14
Cpu 2 hot: high 186, batch 31 used: 155
Cpu 2 cold: high 62, batch 15 used: 9
Cpu 3 hot: high 186, batch 31 used: 13
Cpu 3 cold: high 62, batch 15 used: 14
Cpu 4 hot: high 186, batch 31 used: 0
Cpu 4 cold: high 62, batch 15 used: 0
Cpu 5 hot: high 186, batch 31 used: 0
Cpu 5 cold: high 62, batch 15 used: 0
Cpu 6 hot: high 186, batch 31 used: 0
Cpu 6 cold: high 62, batch 15 used: 0
Cpu 7 hot: high 186, batch 31 used: 0
Cpu 7 cold: high 62, batch 15 used: 0
Cpu 8 hot: high 186, batch 31 used: 81
Cpu 8 cold: high 62, batch 15 used: 8
Cpu 9 hot: high 186, batch 31 used: 1
Cpu 9 cold: high 62, batch 15 used: 13
Cpu 10 hot: high 186, batch 31 used: 69
Cpu 10 cold: high 62, batch 15 used: 14
Cpu 11 hot: high 186, batch 31 used: 77
Cpu 11 cold: high 62, batch 15 used: 10
Cpu 12 hot: high 186, batch 31 used: 0
Cpu 12 cold: high 62, batch 15 used: 0
Cpu 13 hot: high 186, batch 31 used: 135
Cpu 13 cold: high 62, batch 15 used: 0
Cpu 14 hot: high 186, batch 31 used: 0
Cpu 14 cold: high 62, batch 15 used: 0
Cpu 15 hot: high 186, batch 31 used: 0
Cpu 15 cold: high 62, batch 15 used: 0
Node 0 HighMem per-cpu: empty
Node 1 DMA per-cpu: empty
Node 1 DMA32 per-cpu: empty
Node 1 Normal per-cpu:
Cpu 0 hot: high 186, batch 31 used: 1
Cpu 0 cold: high 62, batch 15 used: 0
Cpu 1 hot: high 186, batch 31 used: 0
Cpu 1 cold: high 62, batch 15 used: 0
Cpu 2 hot: high 186, batch 31 used: 0
Cpu 2 cold: high 62, batch 15 used: 0
Cpu 3 hot: high 186, batch 31 used: 0
Cpu 3 cold: high 62, batch 15 used: 0
Cpu 4 hot: high 186, batch 31 used: 87
Cpu 4 cold: high 62, batch 15 used: 10
Cpu 5 hot: high 186, batch 31 used: 30
Cpu 5 cold: high 62, batch 15 used: 12
Cpu 6 hot: high 186, batch 31 used: 77
Cpu 6 cold: high 62, batch 15 used: 13
Cpu 7 hot: high 186, batch 31 used: 28
Cpu 7 cold: high 62, batch 15 used: 2
Cpu 8 hot: high 186, batch 31 used: 34
Cpu 8 cold: high 62, batch 15 used: 0
Cpu 9 hot: high 186, batch 31 used: 94
Cpu 9 cold: high 62, batch 15 used: 0
Cpu 10 hot: high 186, batch 31 used: 0
Cpu 10 cold: high 62, batch 15 used: 0
Cpu 11 hot: high 186, batch 31 used: 0
Cpu 11 cold: high 62, batch 15 used: 0
Cpu 12 hot: high 186, batch 31 used: 0
Cpu 12 cold: high 62, batch 15 used: 8
Cpu 13 hot: high 186, batch 31 used: 33
Cpu 13 cold: high 62, batch 15 used: 8
Cpu 14 hot: high 186, batch 31 used: 133
Cpu 14 cold: high 62, batch 15 used: 2
Cpu 15 hot: high 186, batch 31 used: 155
Cpu 15 cold: high 62, batch 15 used: 5
Node 1 HighMem per-cpu: empty
Free pages: 962792kB (0kB HighMem)
Active: 4471040 inactive: 1118163 dirty: 52 writeback: 0 unstable: 0 free: 240698 slab: 283135 mapped-file: 6766 mapped-anon: 2481065 pagetables: 10524
Node 0 DMA free: 10836kB min: 8kB low: 8kB high: 12kB active: 0kB inactive: 0kB present: 10452kB pages_scanned: 0 all_unreclaimable? Yes
Lowmem_reserve []: 0 2991 12081 12081
Node 0 DMA32 free: 66704kB min: 2460kB low: 3072kB high: 450kb active: 2650608kB inactive: 122492kB present: 3063584kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 9090 9090
Node 0 Normal free: 39604kB min: 7476kB low: 9344kB high: 41512kb active: 8293932kB inactive: 618776kB present: 9308160kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 0 0
Node 0 HighMem free: 0kB min: 128kB low: 128kB high: 128kB active: 0kB inactive: 0kB present: 0kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 0 0
Node 1 DMA free: 0kB min: 0kB low: 0kB high: 0kB active: 0kB inactive: 0kB present: 0kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 12120 12120
Node 1 DMA32 free: 0kB min: 0kB low: 0kB high: 0kB active: 0kB inactive: 0kB present: 0kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 12120 12120
Node 1 Normal free: 845648kB min: 9968kB low: 12460kB high: 14952kB active: 6921320kb inactive: 3731384kB present: 12379880kb pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 0 0
Node 1 HighMem free: 0kB min: 128kB low: 128kB high: 128kB active: 0kB inactive: 0kB present: 0kB pages_scanned: 0 all_unreclaimable? No
Lowmem_reserve []: 0 0 0 0
Node 0 DMA: 3 * 4kB 3 * 8kB 3 * 16kB 2 * 32kB 3 * 64kB 2 * 128kB 2 * 256kB 1 * 512kB 1 * 1024kB 0 * 2048kB 2 * 4096kB = 41536kb
Node 0 DMA32: 4260 * 4kB 1224 * 8kB 26 * 16kB 1 * 32kB 2 * 64kB 1 * 128kB 1 * 256kB 0 * 512kB 0 * 1024kB 1 * 2048kB 9 * 4096kB = 66704kB
Node 0 Normal: 201 * 4kB 884 * 8kB 1117 * 16kB 141 * 32kB 2 * 64kB 2 * 128kB 1 * 256kB 1 * 512kB 0 * 1024kB 0 * 2048kB 2 * 4096kB = 39604kB
Node 0 HighMem: empty
Node 1 DMA: empty
Node 1 DMA32: empty
Node 1 Normal: 31200 * 4kB 39388 * 8kB 14353 * 16kB 3307 * 32kB 906 * 64kB 2 * 128kB 1 * 256kB 1 * 512kB 1 * 1024kB 1 * 2048kB 2 * 4096kB = 845648kB
Node 1 HighMem: empty
3108846 pagecache pages
Swap cache: add 337062, delete 336108, find 261230/261555, race 0 + 0
Free swap = 5005124kB
Total swap = 6289320kB
Free swap: 5005124kB
6553600 pages of RAM
417159 reserved pages
2320912 pages shared
954 pages swap cached
 
4. vm activity,/proc/vmstat
 
$ Cat/proc/vmstat
Nr_anon_pages 2480490
Nr_mapped 6548
Nr_file_pages 3110632
Nr_slab 283141
Nr_page_table_pages 10334
Nr_dirty 1
Nr_writeback 0
Nr_unstable 0
Nr_bounce 0
Numa_hit 59784369537
Numa_mis44505232088
Numa_foreign 44505232088
Numa_interleave 288929
Numa_local 59783481501
Numa_other 44506120124
Pgpgin 6085462783
Pgpgout 16203578552
Pswpin 2556
Pswpout 334506
Pgalloc_dma 1
Pgalloc_dma32 12614733
Pgalloc_normal 104277734751
Pgalloc_high 0
Pgfree 104290591256
Pgactivate 50646465
Pgdeactivate 4822484
Pgfault 104165467862
Pgmajfault 16210
Pgrefill_dma 0
Pgrefill_dma32 7653915
Pgrefill_normal 26774426
Pgrefill_high 0
Pgsteal_dma 0
Pgsteal_dma32 256875
Pgsteal_normal 4129645
Pgsteal_high 0
Pgscan_kswapd_dma 0
Pgscan_kswapd_dma32 343521
Pgscan_kswapd_normal 4447936
Pgscan_kswapd_high 0
Pgscan_direct_dma 0
Pgscan_direct_dma32 0
Pgscan_direct_normal 0
Pgscan_direct_high 0
Pginodesteal 0
Slabs_scanned 4000512
Kswapd_steal 4386520
Kswapd_inodesteal 2810883
Pageoutrun 37456
Allocstall 0
Pgrotated 337233.
 
5. memory usage in each zone:/proc/zoneinfo
 
$ Cat/proc/zoneinfo
Node 0, zone DMA32
Pages free 668878
Min 615
Low 1, 768
High 1, 922
Active 71404
Inactive 7034
Scanned 0 (a: 0 I: 0)
Spanned 1044480
Present 765896
Nr_anon_pages 75672
Nr_mapped 759
Nr_file_pages 2766
Nr_slab 551
Nr_page_table_pages 266
Nr_dirty 2
Nr_writeback 0
Nr_unstable 0
Nr_bounce 0
Numa_hit 444062598
Numa_mis11649541
Numa_foreign 0
Numa_interleave 0
Numa_local 443992176
Numa_other 11719963
Protection: (0, 0, 9090,909 0)
Pagesets
Cpu: 0 pcp: 0
Number: 180
High: 186
Batch: 31
Cpu: 0 pcp: 1
Count: 58
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 1 pcp: 0
Number: 178
High: 186
Batch: 31
Cpu: 1 pcp: 1
Count: 12
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 2 pcp: 0
Number: 184
High: 186
Batch: 31
Cpu: 2 pcp: 1
Count: 51
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 3 pcp: 0
Number: 155
High: 186
Batch: 31
Cpu: 3 pcp: 1
Count: 9
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 8 pcp: 0
Number: 181
High: 186
Batch: 31
Cpu: 8 pcp: 1
Count: 53
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 9 pcp: 0
Number: 157
High: 186
Batch: 31
Cpu: 9 pcp: 1
Count: 14
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 10 pcp: 0
Number: 162
High: 186
Batch: 31
Cpu: 10 pcp: 1
Count: 1
High: 62
Batch: 15
Vm stats threshold: 60
Cpu: 11 pcp: 0
Number: 158
High: 186
Batch: 31
Cpu: 11 pcp: 1
Count: 23
High: 62
Batch: 15
Vm stats threshold: 60
All_unreclaimable: 0
Prev_priority: 12
Start_pfn: 4096
 
6. Partner page information for each region:/proc/buddyinfo
 
$ Cat/proc/buddyinfo
Node 0, zone DMA 3 3 3 2 2 2 1 1 0 2
Node 0, zone DMA32 12238 4658 2889 2209 1697 1331 1008 750 467 238 143
Node 0, zone Normal 266 201 169 354 64 51 172 118 87 47 306
Node 1, zone Normal 102 288 500 394 255 1877 5161 3788 2053 826 372
 
With this information, we can learn in detail how memory resources are used and the remaining conditions, and make decisions for the next optimization. The explanation of information can be keywords related to google. however, to fully understand these information points, you must be familiar with the VM-related part of the kernel.
 
PS. I have listed the rough points above. other students can further add them. thank you!
 
Have a good time!
 
Link: http://blog.yufeng.info/archives/2051
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.