/proc和内存管理 相关的内容

本文平台是 x86虚拟云服务器,kernel版本时 4.15
主要分析以下几个文件节点信息

sh@tencent_cloud:/ $ ls /proc/ |grep info
buddyinfo     #伙伴系统信息
cpuinfo     #cpu硬件相关信息
meminfo     #内存总览信息
pagetypeinfo     #伙伴系统信息,比buddyinfo更加详细
slabinfo     #slab分配器当前情况
vmallocinfo     #vmalloc分配器相关信息
zoneinfo     #zone节点信息

meminfo

/proc/meminfo 是系统中 汇总的 内存信息

sh@tencent_cloud:/ $ sudo cat /proc/meminfo
MemTotal:        1877504 kB   #系统中有的总共内存
MemFree:          350448 kB  #系统中空闲的内存
MemAvailable:    1007712 kB     #系统中可获得内存一般 <= Memfree + Buffers + Cached
Buffers:          207976 kB
Cached:           464604 kB
SwapCached:        52812 kB
Active:           689112 kB
Inactive:         501844 kB
Active(anon):     252108 kB
Inactive(anon):   280312 kB
Active(file):     437004 kB
Inactive(file):   221532 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       1049596 kB
SwapFree:         576764 kB
Dirty:               696 kB
Writeback:             0 kB
AnonPages:        509408 kB
Mapped:           132704 kB
Shmem:             14016 kB
Slab:             260092 kB
SReclaimable:     185924 kB
SUnreclaim:        74168 kB
KernelStack:        6752 kB
PageTables:        30656 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1988348 kB
Committed_AS:    3351132 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:     22528 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      937976 kB
DirectMap2M:     1159168 kB

zone

sh@tencent_cloud:/ $ cat /proc/zoneinfo
Node 0, zone      DMA
  per-node stats
      nr_inactive_anon 69990      #不活跃的匿名页面数量
      nr_active_anon 63512       #活跃的匿名页面数量
      nr_inactive_file 66070      #不活跃的文件数量
      nr_active_file 106456       #活跃的文件数量
      nr_unevictable 0
      nr_slab_reclaimable 46500
      nr_slab_unreclaimable 18531
      nr_isolated_anon 0
      nr_isolated_file 0
      workingset_refault 9595434
      workingset_activate 1613846
      workingset_nodereclaim 273918
      nr_anon_pages 127743
      nr_mapped    32598
      nr_file_pages 189232
      nr_dirty     125
      nr_writeback 0
      nr_writeback_temp 0
      nr_shmem     3504
      nr_shmem_hugepages 0
      nr_shmem_pmdmapped 0
      nr_anon_transparent_hugepages 11
      nr_unstable  0
      nr_vmscan_write 611232
      nr_vmscan_immediate_reclaim 117183
      nr_dirtied   10693130
      nr_written   11016332
  pages free     2360
        min      99
        low      123
        high     147
        spanned  4095
        present  3998
        managed  3977
        protection: (0, 1750, 1750, 1750, 1750)
      nr_free_pages 2360
      nr_zone_inactive_anon 298
      nr_zone_active_anon 141
      nr_zone_inactive_file 6
      nr_zone_active_file 535
      nr_zone_unevictable 0
      nr_zone_write_pending 0
      nr_mlock     0
      nr_page_table_pages 7
      nr_kernel_stack 0
      nr_bounce    0
      nr_zspages   0
      nr_free_cma  0
      numa_hit     759691
      numa_miss    0
      numa_foreign 0
      numa_interleave 0
      numa_local   759691
      numa_other   0
  pagesets
    cpu: 0
              count: 0
              high:  0
              batch: 1
  vm stats threshold: 2
  node_unreclaimable:  0
  start_pfn:           1
Node 0, zone    DMA32
  pages free     76925
        min      11164
        low      13955
        high     16746
        spanned  520190
        present  520190
        managed  465399
        protection: (0, 0, 0, 0, 0)
      nr_free_pages 76925
      nr_zone_inactive_anon 69692
      nr_zone_active_anon 63371
      nr_zone_inactive_file 66064
      nr_zone_active_file 105921
      nr_zone_unevictable 0
      nr_zone_write_pending 125
      nr_mlock     0
      nr_page_table_pages 7667
      nr_kernel_stack 6796
      nr_bounce    0
      nr_zspages   0
      nr_free_cma  0
      numa_hit     569528359
      numa_miss    0
      numa_foreign 0
      numa_interleave 47596
      numa_local   569528359
      numa_other   0
  pagesets
    cpu: 0
              count: 109
              high:  186
              batch: 31
  vm stats threshold: 10
  node_unreclaimable:  0
  start_pfn:           4096
Node 0, zone   Normal
  pages free     0
        min      0
        low      0
        high     0
        spanned  0
        present  0
        managed  0
        protection: (0, 0, 0, 0, 0)
Node 0, zone  Movable
  pages free     0
        min      0
        low      0
        high     0
        spanned  0
        present  0
        managed  0
        protection: (0, 0, 0, 0, 0)
Node 0, zone   Device
  pages free     0
        min      0
        low      0
        high     0
        spanned  0
        present  0
        managed  0
        protection: (0, 0, 0, 0, 0)

buddyinfo

/proc/buddyinfo 是系统中伙伴系统的信息
伙伴系统中 是以 page_block为单位去管理 内存的,page_block的单位也是 2^ORDER,
其中 0 < ORDER < 11.
每一行 是以 type 作为区分的
下面每一列 都是以 page_block size作为区分的

sh@tencent_cloud:/ $ cat /proc/buddyinfo
Node 0, zone      DMA     88     70     73     18     12     11      6      2      2      0      0
Node 0, zone    DMA32   2453    511   2158   1859   1063    561     75     20     11      0      0

slabinfo

/proc/slabinfo 是系统中 slab 结构的信息

sh@tencent_cloud:/ $ sudo cat /proc/slabinfo
slabinfo - version: 2.1
# name                 : tunables    : slabdata   
au_finfo               0      0    192   21    1 : tunables    0    0    0 : slabdata      0      0      0
au_icntnr              0      0    768   10    2 : tunables    0    0    0 : slabdata      0      0      0
…………

vmallocinfo

/proc/vmallocinfo 是系统中伙伴系统的信息

sh@tencent_cloud:/ $ sudo cat /proc/vmallocinfo
0xffffbf3040000000-0xffffbf3040002000    8192 acpi_os_map_iomem+0x17c/0x1b0 phys=0x000000007ffff000 ioremap
0xffffbf3040002000-0xffffbf3040005000   12288 acpi_os_map_iomem+0x17c/0x1b0 phys=0x000000007fffe000 ioremap
0xffffbf3040005000-0xffffbf3040206000 2101248 alloc_large_system_hash+0x19c/0x259 pages=512 vmalloc N0=512
0xffffbf3040206000-0xffffbf3040307000 1052672 alloc_large_system_hash+0x19c/0x259 pages=256 vmalloc N0=256
0xffffbf3040307000-0xffffbf3040310000   36864 alloc_large_system_hash+0x19c/0x259 pages=8 vmalloc N0=8
0xffffbf3040310000-0xffffbf3040319000   36864 alloc_large_system_hash+0x19c/0x259 pages=8 vmalloc N0=8
0xffffbf3040319000-0xffffbf304031b000    8192 bpf_prog_alloc+0x4c/0xc0 pages=1 vmalloc N0=1
0xffffbf304031c000-0xffffbf3040321000   20480 _do_fork+0xdf/0x400 pages=4 vmalloc N0=4
0xffffbf3040321000-0xffffbf3040323000    8192 acpi_os_map_iomem+0x17c/0x1b0 phys=0x00000000fed00000 ioremap
0xffffbf3040324000-0xffffbf3040329000   20480 _do_fork+0xdf/0x400 pages=4 vmalloc N0=4
0xffffbf3040329000-0xffffbf304032b000    8192 memremap+0x122/0x180 phys=0x00000000000fd000 ioremap

pagetypeinfo

/proc/pagetypeinfo 是系统中伙伴系统的信息
不过比 buddy_info更加详细,这里把 page_block 更加细分 为 Unmovable Movable HighAtomic CMA Isolate 这几种类型

sh@tencent_cloud:/ $ sudo cat /proc/pagetypeinfo
Page block order: 9
Pages per block:  512

Free pages count per migrate type at order       0      1      2      3      4      5      6      7      8      9     10
Node    0, zone      DMA, type    Unmovable      8     12     13      5      9      3      3      1      1      0      0
Node    0, zone      DMA, type      Movable     75     56     50     10      0      1      0      1      1      0      0
Node    0, zone      DMA, type  Reclaimable      5      2     10      3      3      7      3      0      0      0      0
Node    0, zone      DMA, type   HighAtomic      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone      DMA, type          CMA      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone      DMA, type      Isolate      0      0      0      0      0      0      0      0      0      0      0
Node    0, zone    DMA32, type    Unmovable    140    172    139     46     30     17     11      4      2      0      0
Node    0, zone    DMA32, type      Movable   8325   3763   2401   1616    969    496     39      4      8      0      0
Node    0, zone    DMA32, type  Reclaimable   1062    357    155    226     57     47     24     12      0      0      0

cpuinfo

/proc/cpuinfo 是系统中伙伴系统 CPU 的详细信息

sh@tencent_cloud:/ $ sudo cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 79
model name	: Intel(R) Xeon(R) CPU E5-26xx v4
stepping	: 1
microcode	: 0x1
cpu MHz		: 2394.454
cache size	: 4096 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch pti bmi1 avx2 bmi2 rdseed adx xsaveopt
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds
bogomips	: 4788.90
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:

可参考: https://www.cnblogs.com/arnoldlu/p/8568330.html
由于 参数太多,一时半会儿 无法全部注释完,还有一部分我也不知道啥意思,后面有空
会 慢慢补充,结合代码分析这些参数具体在代码中使用的什么数据结构

你可能感兴趣的:(内存管理,linux内存管理,/proc文件系统)