基于msm-5.4
一、打印内容
1. 打印格式
# cat /proc/vmstat /* 1. 打印全局数组 vm_zone_stat[] 的值,enum zone_stat_item 描述各条目 */ nr_free_pages 617775 nr_zone_inactive_anon 16518 nr_zone_active_anon 979541 nr_zone_inactive_file 698879 nr_zone_active_file 172233 nr_zone_unevictable 799 nr_zone_write_pending 23 nr_mlock 799 nr_page_table_pages 30669 nr_kernel_stack 62368 nr_shadow_call_stack_bytes 15966208 nr_bounce 0 nr_zspages 3271 nr_free_cma 0 /* 2. 打印全局数组 vm_node_stat[] 的值,enum node_stat_item 描述各条目 */ nr_inactive_anon 16518 nr_active_anon 979541 nr_inactive_file 698879 nr_active_file 172233 nr_unevictable 799 nr_slab_reclaimable 35540 nr_slab_unreclaimable 56547 nr_isolated_anon 0 nr_isolated_file 0 workingset_nodes 10 workingset_refault 6019 workingset_activate 6019 workingset_restore 0 workingset_nodereclaim 0 nr_anon_pages 982470 nr_mapped 537561 nr_file_pages 899517 nr_dirty 23 nr_writeback 0 nr_writeback_temp 0 nr_shmem 13782 nr_shmem_hugepages 0 nr_shmem_pmdmapped 0 nr_file_hugepages 0 nr_file_pmdmapped 0 nr_anon_transparent_hugepages 0 nr_unstable 0 nr_vmscan_write 18979 nr_vmscan_immediate_reclaim 8 nr_dirtied 77330 nr_written 93219 nr_kernel_misc_reclaimable 40568 nr_unreclaimable_pages 156794 /* 3. 收集全局变量 struct wb_domain global_wb_domain 的成员,分别是 thresh 和 bg_thresh */ nr_dirty_threshold 293883 nr_dirty_background_threshold 73201 /* 4. 以每个cpu为单位,收集 per_cpu(vm_event_states, cpu) 的和,各元素由 enum vm_event_item 描述 */ pgpgin 2174532 pgpgout 297144 pswpin 9200 pswpout 18979 pgalloc_normal 20942336 pgalloc_movable 0 allocstall_normal 0 allocstall_movable 0 pgskip_normal 0 pgskip_movable 0 pgfree 21569479 pgactivate 408312 pgdeactivate 49 pglazyfree 0 pgfault 5143535 pgmajfault 17558 pglazyfreed 0 pgrefill 0 pgsteal_kswapd 0 pgsteal_direct 0 pgscan_kswapd 0 pgscan_direct 0 pgscan_direct_throttle 0 pginodesteal 0 slabs_scanned 0 kswapd_inodesteal 0 kswapd_low_wmark_hit_quickly 0 kswapd_high_wmark_hit_quickly 0 pageoutrun 0 pgrotated 1613 drop_pagecache 0 drop_slab 0 oom_kill 0 pgmigrate_success 806 pgmigrate_fail 0 compact_migrate_scanned 0 compact_free_scanned 0 compact_isolated 8531 compact_stall 0 compact_fail 0 compact_success 0 compact_daemon_wake 0 compact_daemon_migrate_scanned 0 compact_daemon_free_scanned 0 unevictable_pgs_culled 802 unevictable_pgs_scanned 0 unevictable_pgs_rescued 3 unevictable_pgs_mlocked 803 unevictable_pgs_munlocked 4 unevictable_pgs_cleared 0 unevictable_pgs_stranded 0 thp_fault_alloc 0 thp_fault_fallback 0 thp_collapse_alloc 0 thp_collapse_alloc_failed 0 thp_file_alloc 0 thp_file_mapped 0 thp_split_page 0 thp_split_page_failed 0 thp_deferred_split_page 0 thp_split_pmd 0 thp_zero_page_alloc 0 thp_zero_page_alloc_failed 0 thp_swpout 0 thp_swpout_fallback 0 swap_ra 57 swap_ra_hit 39
打印的各个条目的字符串来自 vmstat_text[], 各条目的值分别来自全局数组 vm_zone_stat[]、全局数组 vm_node_stat[]、全局变量 struct wb_domain global_wb_domain 的成员、以每个cpu为单位收集 per_cpu(vm_event_states, cpu) 的和。
2. 成员说明
二、实现
void __init init_mm_internals(void) //vmstat.c { proc_create_seq("vmstat", 0444, NULL, &vmstat_op); } static void *vmstat_start(struct seq_file *m, loff_t *pos) //vmstat.c { unsigned long *v; int i, stat_items_size; /* 表示要分配内存的大小,这些条目的信息都会在这里进行打印 */ stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) + NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) + NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) + NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long); #ifdef CONFIG_VM_EVENT_COUNTERS stat_items_size += sizeof(struct vm_event_state); #endif m->private = v = kmalloc(stat_items_size, GFP_KERNEL); /* 1. 收集全局数组 vm_zone_stat[] 的信息 */ for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) //enum zone_stat_item条目的个数 v[i] = global_zone_page_state(i); //v[i] = vm_zone_stat[i] v += NR_VM_ZONE_STAT_ITEMS; /* 2. 收集全局数组 vm_node_stat[] 的信息 */ for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) //enum node_stat_item 条目的个数 v[i] = global_node_page_state(i); //v[i] = vm_node_stat[i]; v += NR_VM_NODE_STAT_ITEMS; /* 3. 收集全局变量 struct wb_domain global_wb_domain 的成员。 * v[0]=dirty_throttle_control.thresh; v[1]=dirty_throttle_control.bg_thresh; */ global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, v + NR_DIRTY_THRESHOLD); v += NR_VM_WRITEBACK_STAT_ITEMS; #ifdef CONFIG_VM_EVENT_COUNTERS /* 4. 以每个cpu为单位收集 per_cpu(vm_event_states, cpu) 的和 */ all_vm_events(v); //enum vm_event_item 有 NR_VM_EVENT_ITEMS 个条目 v[PGPGIN] /= 2; /* sectors -> kbytes */ v[PGPGOUT] /= 2; #endif return (unsigned long *)m->private + *pos; }
标签:stat,zone,32,vm,thp,vmstat,VM,内存,nr From: https://www.cnblogs.com/hellokitty2/p/18390061