linux meminfo cache计算方式

aarch32 linux4.14

static int meminfo_proc_show(struct seq_file *m, void *v) 
{
    struct sysinfo i;
......
    si_meminfo(&i);
    si_swapinfo(&i);

    cached = global_node_page_state(NR_FILE_PAGES) -
            total_swapcache_pages() - i.bufferram;
    if (cached < 0)
        cached = 0;


    available = si_mem_available();

    show_val_kb(m, "MemTotal:       ", i.totalram);
    show_val_kb(m, "MemFree:        ", i.freeram);
    show_val_kb(m, "MemAvailable:   ", available);
    show_val_kb(m, "Buffers:        ", i.bufferram);
    show_val_kb(m, "Cached:         ", cached);
......
}

cached = global_node_page_state(NR_FILE_PAGES) - total_swapcache_pages() - i.bufferram;

NR_FILE_PAGES 表示所有缓存页的总和包含了cache 和buffers

total_swapcache_pages ,swap cache是交换分区的缓存,匿名页被swap out 和swap in的缓存的位置

bufferram 是块设备的缓存页

page cache 对于文件页的缓存(加速对磁盘上文件的读写),例如mmap 文件,可执行文件和库文件的代码段,open的文件

所以cache可以认为是文件页的缓存,这部分是可以被丢弃并回收的,后面再用的时候重新建立缓存

参考自 http://linuxperf.com/?p=32

oom中的log  total pagecache pages 会打印NR_FILE_PAGES

show_mem
-->
show_free_areas
{
......
    printk("%ld total pagecache pages\n", global_node_page_state(NR_FILE_PAGES));
......
}

Mem-Info:
active_anon:26820 inactive_anon:0 isolated_anon:0
active_file:10 inactive_file:5 isolated_file:0
unevictable:11293 dirty:0 writeback:0 unstable:0
slab_reclaimable:1493 slab_unreclaimable:1802
mapped:3528 shmem:0 pagetables:202 bounce:0
free:262 free_pcp:0 free_cma:4
Node 0 active_anon:107280kB inactive_anon:0kB active_file:40kB inactive_file:20kB unevictable:45172kBs
Normal free:1048kB min:1476kB low:1844kB high:2212kB active_anon:107296kB inactive_anon:0kB active_fiB
lowmem_reserve[]: 0 0 0 
Normal: 17*4kB (UM) 2*8kB (U) 37*16kB (M) 5*32kB (M) 1*64kB (M) 0*128kB 1*256kB (M) 0*512kB 0*1024kB B
11299 total pagecache pages

 

你可能感兴趣的:(LINUX,ARM)