1e1759c21SAlexey Dobriyan #include <linux/fs.h> 2e1759c21SAlexey Dobriyan #include <linux/hugetlb.h> 3e1759c21SAlexey Dobriyan #include <linux/init.h> 4e1759c21SAlexey Dobriyan #include <linux/kernel.h> 5e1759c21SAlexey Dobriyan #include <linux/mm.h> 6e1759c21SAlexey Dobriyan #include <linux/mman.h> 7e1759c21SAlexey Dobriyan #include <linux/mmzone.h> 8e1759c21SAlexey Dobriyan #include <linux/proc_fs.h> 9e1759c21SAlexey Dobriyan #include <linux/quicklist.h> 10e1759c21SAlexey Dobriyan #include <linux/seq_file.h> 11e1759c21SAlexey Dobriyan #include <linux/swap.h> 12e1759c21SAlexey Dobriyan #include <linux/vmstat.h> 13e1759c21SAlexey Dobriyan #include <asm/atomic.h> 14e1759c21SAlexey Dobriyan #include <asm/page.h> 15e1759c21SAlexey Dobriyan #include <asm/pgtable.h> 16e1759c21SAlexey Dobriyan #include "internal.h" 17e1759c21SAlexey Dobriyan 18e1759c21SAlexey Dobriyan void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) 19e1759c21SAlexey Dobriyan { 20e1759c21SAlexey Dobriyan } 21e1759c21SAlexey Dobriyan 22e1759c21SAlexey Dobriyan static int meminfo_proc_show(struct seq_file *m, void *v) 23e1759c21SAlexey Dobriyan { 24e1759c21SAlexey Dobriyan struct sysinfo i; 25e1759c21SAlexey Dobriyan unsigned long committed; 26e1759c21SAlexey Dobriyan unsigned long allowed; 27e1759c21SAlexey Dobriyan struct vmalloc_info vmi; 28e1759c21SAlexey Dobriyan long cached; 29e1759c21SAlexey Dobriyan unsigned long pages[NR_LRU_LISTS]; 30e1759c21SAlexey Dobriyan int lru; 31e1759c21SAlexey Dobriyan 32e1759c21SAlexey Dobriyan /* 33e1759c21SAlexey Dobriyan * display in kilobytes. 34e1759c21SAlexey Dobriyan */ 35e1759c21SAlexey Dobriyan #define K(x) ((x) << (PAGE_SHIFT - 10)) 36e1759c21SAlexey Dobriyan si_meminfo(&i); 37e1759c21SAlexey Dobriyan si_swapinfo(&i); 3800a62ce9SKOSAKI Motohiro committed = percpu_counter_read_positive(&vm_committed_as); 39e1759c21SAlexey Dobriyan allowed = ((totalram_pages - hugetlb_total_pages()) 40e1759c21SAlexey Dobriyan * sysctl_overcommit_ratio / 100) + total_swap_pages; 41e1759c21SAlexey Dobriyan 42e1759c21SAlexey Dobriyan cached = global_page_state(NR_FILE_PAGES) - 43e1759c21SAlexey Dobriyan total_swapcache_pages - i.bufferram; 44e1759c21SAlexey Dobriyan if (cached < 0) 45e1759c21SAlexey Dobriyan cached = 0; 46e1759c21SAlexey Dobriyan 47e1759c21SAlexey Dobriyan get_vmalloc_info(&vmi); 48e1759c21SAlexey Dobriyan 49e1759c21SAlexey Dobriyan for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 50e1759c21SAlexey Dobriyan pages[lru] = global_page_state(NR_LRU_BASE + lru); 51e1759c21SAlexey Dobriyan 52e1759c21SAlexey Dobriyan /* 53e1759c21SAlexey Dobriyan * Tagged format, for easy grepping and expansion. 54e1759c21SAlexey Dobriyan */ 55e1759c21SAlexey Dobriyan seq_printf(m, 56e1759c21SAlexey Dobriyan "MemTotal: %8lu kB\n" 57e1759c21SAlexey Dobriyan "MemFree: %8lu kB\n" 58e1759c21SAlexey Dobriyan "Buffers: %8lu kB\n" 59e1759c21SAlexey Dobriyan "Cached: %8lu kB\n" 60e1759c21SAlexey Dobriyan "SwapCached: %8lu kB\n" 61e1759c21SAlexey Dobriyan "Active: %8lu kB\n" 62e1759c21SAlexey Dobriyan "Inactive: %8lu kB\n" 63e1759c21SAlexey Dobriyan "Active(anon): %8lu kB\n" 64e1759c21SAlexey Dobriyan "Inactive(anon): %8lu kB\n" 65e1759c21SAlexey Dobriyan "Active(file): %8lu kB\n" 66e1759c21SAlexey Dobriyan "Inactive(file): %8lu kB\n" 67e1759c21SAlexey Dobriyan "Unevictable: %8lu kB\n" 68e1759c21SAlexey Dobriyan "Mlocked: %8lu kB\n" 69e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 70e1759c21SAlexey Dobriyan "HighTotal: %8lu kB\n" 71e1759c21SAlexey Dobriyan "HighFree: %8lu kB\n" 72e1759c21SAlexey Dobriyan "LowTotal: %8lu kB\n" 73e1759c21SAlexey Dobriyan "LowFree: %8lu kB\n" 74e1759c21SAlexey Dobriyan #endif 758feae131SDavid Howells #ifndef CONFIG_MMU 768feae131SDavid Howells "MmapCopy: %8lu kB\n" 778feae131SDavid Howells #endif 78e1759c21SAlexey Dobriyan "SwapTotal: %8lu kB\n" 79e1759c21SAlexey Dobriyan "SwapFree: %8lu kB\n" 80e1759c21SAlexey Dobriyan "Dirty: %8lu kB\n" 81e1759c21SAlexey Dobriyan "Writeback: %8lu kB\n" 82e1759c21SAlexey Dobriyan "AnonPages: %8lu kB\n" 83e1759c21SAlexey Dobriyan "Mapped: %8lu kB\n" 844b02108aSKOSAKI Motohiro "Shmem: %8lu kB\n" 85e1759c21SAlexey Dobriyan "Slab: %8lu kB\n" 86e1759c21SAlexey Dobriyan "SReclaimable: %8lu kB\n" 87e1759c21SAlexey Dobriyan "SUnreclaim: %8lu kB\n" 88c6a7f572SKOSAKI Motohiro "KernelStack: %8lu kB\n" 89e1759c21SAlexey Dobriyan "PageTables: %8lu kB\n" 90e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST 91e1759c21SAlexey Dobriyan "Quicklists: %8lu kB\n" 92e1759c21SAlexey Dobriyan #endif 93e1759c21SAlexey Dobriyan "NFS_Unstable: %8lu kB\n" 94e1759c21SAlexey Dobriyan "Bounce: %8lu kB\n" 95e1759c21SAlexey Dobriyan "WritebackTmp: %8lu kB\n" 96e1759c21SAlexey Dobriyan "CommitLimit: %8lu kB\n" 97e1759c21SAlexey Dobriyan "Committed_AS: %8lu kB\n" 98e1759c21SAlexey Dobriyan "VmallocTotal: %8lu kB\n" 99e1759c21SAlexey Dobriyan "VmallocUsed: %8lu kB\n" 1006a46079cSAndi Kleen "VmallocChunk: %8lu kB\n" 1016a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 102370c28deSHugh Dickins "HardwareCorrupted: %5lu kB\n" 1036a46079cSAndi Kleen #endif 104*79134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 105*79134171SAndrea Arcangeli "AnonHugePages: %8lu kB\n" 106*79134171SAndrea Arcangeli #endif 1076a46079cSAndi Kleen , 108e1759c21SAlexey Dobriyan K(i.totalram), 109e1759c21SAlexey Dobriyan K(i.freeram), 110e1759c21SAlexey Dobriyan K(i.bufferram), 111e1759c21SAlexey Dobriyan K(cached), 112e1759c21SAlexey Dobriyan K(total_swapcache_pages), 113e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]), 114e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]), 115e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_ANON]), 116e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_ANON]), 117e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_FILE]), 118e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_FILE]), 119e1759c21SAlexey Dobriyan K(pages[LRU_UNEVICTABLE]), 120e1759c21SAlexey Dobriyan K(global_page_state(NR_MLOCK)), 121e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 122e1759c21SAlexey Dobriyan K(i.totalhigh), 123e1759c21SAlexey Dobriyan K(i.freehigh), 124e1759c21SAlexey Dobriyan K(i.totalram-i.totalhigh), 125e1759c21SAlexey Dobriyan K(i.freeram-i.freehigh), 126e1759c21SAlexey Dobriyan #endif 1278feae131SDavid Howells #ifndef CONFIG_MMU 12833e5d769SDavid Howells K((unsigned long) atomic_long_read(&mmap_pages_allocated)), 1298feae131SDavid Howells #endif 130e1759c21SAlexey Dobriyan K(i.totalswap), 131e1759c21SAlexey Dobriyan K(i.freeswap), 132e1759c21SAlexey Dobriyan K(global_page_state(NR_FILE_DIRTY)), 133e1759c21SAlexey Dobriyan K(global_page_state(NR_WRITEBACK)), 134*79134171SAndrea Arcangeli K(global_page_state(NR_ANON_PAGES) 135*79134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 136*79134171SAndrea Arcangeli + global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * 137*79134171SAndrea Arcangeli HPAGE_PMD_NR 138*79134171SAndrea Arcangeli #endif 139*79134171SAndrea Arcangeli ), 140e1759c21SAlexey Dobriyan K(global_page_state(NR_FILE_MAPPED)), 1414b02108aSKOSAKI Motohiro K(global_page_state(NR_SHMEM)), 142e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_RECLAIMABLE) + 143e1759c21SAlexey Dobriyan global_page_state(NR_SLAB_UNRECLAIMABLE)), 144e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_RECLAIMABLE)), 145e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_UNRECLAIMABLE)), 146c6a7f572SKOSAKI Motohiro global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024, 147e1759c21SAlexey Dobriyan K(global_page_state(NR_PAGETABLE)), 148e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST 149e1759c21SAlexey Dobriyan K(quicklist_total_size()), 150e1759c21SAlexey Dobriyan #endif 151e1759c21SAlexey Dobriyan K(global_page_state(NR_UNSTABLE_NFS)), 152e1759c21SAlexey Dobriyan K(global_page_state(NR_BOUNCE)), 153e1759c21SAlexey Dobriyan K(global_page_state(NR_WRITEBACK_TEMP)), 154e1759c21SAlexey Dobriyan K(allowed), 155e1759c21SAlexey Dobriyan K(committed), 156e1759c21SAlexey Dobriyan (unsigned long)VMALLOC_TOTAL >> 10, 157e1759c21SAlexey Dobriyan vmi.used >> 10, 158e1759c21SAlexey Dobriyan vmi.largest_chunk >> 10 1596a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 1606a46079cSAndi Kleen ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10) 1616a46079cSAndi Kleen #endif 162*79134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 163*79134171SAndrea Arcangeli ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * 164*79134171SAndrea Arcangeli HPAGE_PMD_NR) 165*79134171SAndrea Arcangeli #endif 166e1759c21SAlexey Dobriyan ); 167e1759c21SAlexey Dobriyan 168e1759c21SAlexey Dobriyan hugetlb_report_meminfo(m); 169e1759c21SAlexey Dobriyan 170e1759c21SAlexey Dobriyan arch_report_meminfo(m); 171e1759c21SAlexey Dobriyan 172e1759c21SAlexey Dobriyan return 0; 173e1759c21SAlexey Dobriyan #undef K 174e1759c21SAlexey Dobriyan } 175e1759c21SAlexey Dobriyan 176e1759c21SAlexey Dobriyan static int meminfo_proc_open(struct inode *inode, struct file *file) 177e1759c21SAlexey Dobriyan { 178e1759c21SAlexey Dobriyan return single_open(file, meminfo_proc_show, NULL); 179e1759c21SAlexey Dobriyan } 180e1759c21SAlexey Dobriyan 181e1759c21SAlexey Dobriyan static const struct file_operations meminfo_proc_fops = { 182e1759c21SAlexey Dobriyan .open = meminfo_proc_open, 183e1759c21SAlexey Dobriyan .read = seq_read, 184e1759c21SAlexey Dobriyan .llseek = seq_lseek, 185e1759c21SAlexey Dobriyan .release = single_release, 186e1759c21SAlexey Dobriyan }; 187e1759c21SAlexey Dobriyan 188e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void) 189e1759c21SAlexey Dobriyan { 190e1759c21SAlexey Dobriyan proc_create("meminfo", 0, NULL, &meminfo_proc_fops); 191e1759c21SAlexey Dobriyan return 0; 192e1759c21SAlexey Dobriyan } 193e1759c21SAlexey Dobriyan module_init(proc_meminfo_init); 194