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> 1360063497SArun Sharma #include <linux/atomic.h> 14*db3808c1SJoonsoo Kim #include <linux/vmalloc.h> 15e1759c21SAlexey Dobriyan #include <asm/page.h> 16e1759c21SAlexey Dobriyan #include <asm/pgtable.h> 17e1759c21SAlexey Dobriyan #include "internal.h" 18e1759c21SAlexey Dobriyan 19e1759c21SAlexey Dobriyan void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) 20e1759c21SAlexey Dobriyan { 21e1759c21SAlexey Dobriyan } 22e1759c21SAlexey Dobriyan 23e1759c21SAlexey Dobriyan static int meminfo_proc_show(struct seq_file *m, void *v) 24e1759c21SAlexey Dobriyan { 25e1759c21SAlexey Dobriyan struct sysinfo i; 26e1759c21SAlexey Dobriyan unsigned long committed; 27e1759c21SAlexey Dobriyan unsigned long allowed; 28e1759c21SAlexey Dobriyan struct vmalloc_info vmi; 29e1759c21SAlexey Dobriyan long cached; 30e1759c21SAlexey Dobriyan unsigned long pages[NR_LRU_LISTS]; 31e1759c21SAlexey Dobriyan int lru; 32e1759c21SAlexey Dobriyan 33e1759c21SAlexey Dobriyan /* 34e1759c21SAlexey Dobriyan * display in kilobytes. 35e1759c21SAlexey Dobriyan */ 36e1759c21SAlexey Dobriyan #define K(x) ((x) << (PAGE_SHIFT - 10)) 37e1759c21SAlexey Dobriyan si_meminfo(&i); 38e1759c21SAlexey Dobriyan si_swapinfo(&i); 3900a62ce9SKOSAKI Motohiro committed = percpu_counter_read_positive(&vm_committed_as); 40e1759c21SAlexey Dobriyan allowed = ((totalram_pages - hugetlb_total_pages()) 41e1759c21SAlexey Dobriyan * sysctl_overcommit_ratio / 100) + total_swap_pages; 42e1759c21SAlexey Dobriyan 43e1759c21SAlexey Dobriyan cached = global_page_state(NR_FILE_PAGES) - 4433806f06SShaohua Li total_swapcache_pages() - i.bufferram; 45e1759c21SAlexey Dobriyan if (cached < 0) 46e1759c21SAlexey Dobriyan cached = 0; 47e1759c21SAlexey Dobriyan 48e1759c21SAlexey Dobriyan get_vmalloc_info(&vmi); 49e1759c21SAlexey Dobriyan 50e1759c21SAlexey Dobriyan for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 51e1759c21SAlexey Dobriyan pages[lru] = global_page_state(NR_LRU_BASE + lru); 52e1759c21SAlexey Dobriyan 53e1759c21SAlexey Dobriyan /* 54e1759c21SAlexey Dobriyan * Tagged format, for easy grepping and expansion. 55e1759c21SAlexey Dobriyan */ 56e1759c21SAlexey Dobriyan seq_printf(m, 57e1759c21SAlexey Dobriyan "MemTotal: %8lu kB\n" 58e1759c21SAlexey Dobriyan "MemFree: %8lu kB\n" 59e1759c21SAlexey Dobriyan "Buffers: %8lu kB\n" 60e1759c21SAlexey Dobriyan "Cached: %8lu kB\n" 61e1759c21SAlexey Dobriyan "SwapCached: %8lu kB\n" 62e1759c21SAlexey Dobriyan "Active: %8lu kB\n" 63e1759c21SAlexey Dobriyan "Inactive: %8lu kB\n" 64e1759c21SAlexey Dobriyan "Active(anon): %8lu kB\n" 65e1759c21SAlexey Dobriyan "Inactive(anon): %8lu kB\n" 66e1759c21SAlexey Dobriyan "Active(file): %8lu kB\n" 67e1759c21SAlexey Dobriyan "Inactive(file): %8lu kB\n" 68e1759c21SAlexey Dobriyan "Unevictable: %8lu kB\n" 69e1759c21SAlexey Dobriyan "Mlocked: %8lu kB\n" 70e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 71e1759c21SAlexey Dobriyan "HighTotal: %8lu kB\n" 72e1759c21SAlexey Dobriyan "HighFree: %8lu kB\n" 73e1759c21SAlexey Dobriyan "LowTotal: %8lu kB\n" 74e1759c21SAlexey Dobriyan "LowFree: %8lu kB\n" 75e1759c21SAlexey Dobriyan #endif 768feae131SDavid Howells #ifndef CONFIG_MMU 778feae131SDavid Howells "MmapCopy: %8lu kB\n" 788feae131SDavid Howells #endif 79e1759c21SAlexey Dobriyan "SwapTotal: %8lu kB\n" 80e1759c21SAlexey Dobriyan "SwapFree: %8lu kB\n" 81e1759c21SAlexey Dobriyan "Dirty: %8lu kB\n" 82e1759c21SAlexey Dobriyan "Writeback: %8lu kB\n" 83e1759c21SAlexey Dobriyan "AnonPages: %8lu kB\n" 84e1759c21SAlexey Dobriyan "Mapped: %8lu kB\n" 854b02108aSKOSAKI Motohiro "Shmem: %8lu kB\n" 86e1759c21SAlexey Dobriyan "Slab: %8lu kB\n" 87e1759c21SAlexey Dobriyan "SReclaimable: %8lu kB\n" 88e1759c21SAlexey Dobriyan "SUnreclaim: %8lu kB\n" 89c6a7f572SKOSAKI Motohiro "KernelStack: %8lu kB\n" 90e1759c21SAlexey Dobriyan "PageTables: %8lu kB\n" 91e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST 92e1759c21SAlexey Dobriyan "Quicklists: %8lu kB\n" 93e1759c21SAlexey Dobriyan #endif 94e1759c21SAlexey Dobriyan "NFS_Unstable: %8lu kB\n" 95e1759c21SAlexey Dobriyan "Bounce: %8lu kB\n" 96e1759c21SAlexey Dobriyan "WritebackTmp: %8lu kB\n" 97e1759c21SAlexey Dobriyan "CommitLimit: %8lu kB\n" 98e1759c21SAlexey Dobriyan "Committed_AS: %8lu kB\n" 99e1759c21SAlexey Dobriyan "VmallocTotal: %8lu kB\n" 100e1759c21SAlexey Dobriyan "VmallocUsed: %8lu kB\n" 1016a46079cSAndi Kleen "VmallocChunk: %8lu kB\n" 1026a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 103370c28deSHugh Dickins "HardwareCorrupted: %5lu kB\n" 1046a46079cSAndi Kleen #endif 10579134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 10679134171SAndrea Arcangeli "AnonHugePages: %8lu kB\n" 10779134171SAndrea Arcangeli #endif 1086a46079cSAndi Kleen , 109e1759c21SAlexey Dobriyan K(i.totalram), 110e1759c21SAlexey Dobriyan K(i.freeram), 111e1759c21SAlexey Dobriyan K(i.bufferram), 112e1759c21SAlexey Dobriyan K(cached), 11333806f06SShaohua Li K(total_swapcache_pages()), 114e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]), 115e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]), 116e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_ANON]), 117e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_ANON]), 118e1759c21SAlexey Dobriyan K(pages[LRU_ACTIVE_FILE]), 119e1759c21SAlexey Dobriyan K(pages[LRU_INACTIVE_FILE]), 120e1759c21SAlexey Dobriyan K(pages[LRU_UNEVICTABLE]), 121e1759c21SAlexey Dobriyan K(global_page_state(NR_MLOCK)), 122e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 123e1759c21SAlexey Dobriyan K(i.totalhigh), 124e1759c21SAlexey Dobriyan K(i.freehigh), 125e1759c21SAlexey Dobriyan K(i.totalram-i.totalhigh), 126e1759c21SAlexey Dobriyan K(i.freeram-i.freehigh), 127e1759c21SAlexey Dobriyan #endif 1288feae131SDavid Howells #ifndef CONFIG_MMU 12933e5d769SDavid Howells K((unsigned long) atomic_long_read(&mmap_pages_allocated)), 1308feae131SDavid Howells #endif 131e1759c21SAlexey Dobriyan K(i.totalswap), 132e1759c21SAlexey Dobriyan K(i.freeswap), 133e1759c21SAlexey Dobriyan K(global_page_state(NR_FILE_DIRTY)), 134e1759c21SAlexey Dobriyan K(global_page_state(NR_WRITEBACK)), 13579134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 136b53fc7c2SClaudio Scordino K(global_page_state(NR_ANON_PAGES) 13779134171SAndrea Arcangeli + global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * 138b53fc7c2SClaudio Scordino HPAGE_PMD_NR), 139b53fc7c2SClaudio Scordino #else 140b53fc7c2SClaudio Scordino K(global_page_state(NR_ANON_PAGES)), 14179134171SAndrea Arcangeli #endif 142e1759c21SAlexey Dobriyan K(global_page_state(NR_FILE_MAPPED)), 1434b02108aSKOSAKI Motohiro K(global_page_state(NR_SHMEM)), 144e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_RECLAIMABLE) + 145e1759c21SAlexey Dobriyan global_page_state(NR_SLAB_UNRECLAIMABLE)), 146e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_RECLAIMABLE)), 147e1759c21SAlexey Dobriyan K(global_page_state(NR_SLAB_UNRECLAIMABLE)), 148c6a7f572SKOSAKI Motohiro global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024, 149e1759c21SAlexey Dobriyan K(global_page_state(NR_PAGETABLE)), 150e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST 151e1759c21SAlexey Dobriyan K(quicklist_total_size()), 152e1759c21SAlexey Dobriyan #endif 153e1759c21SAlexey Dobriyan K(global_page_state(NR_UNSTABLE_NFS)), 154e1759c21SAlexey Dobriyan K(global_page_state(NR_BOUNCE)), 155e1759c21SAlexey Dobriyan K(global_page_state(NR_WRITEBACK_TEMP)), 156e1759c21SAlexey Dobriyan K(allowed), 157e1759c21SAlexey Dobriyan K(committed), 158e1759c21SAlexey Dobriyan (unsigned long)VMALLOC_TOTAL >> 10, 159e1759c21SAlexey Dobriyan vmi.used >> 10, 160e1759c21SAlexey Dobriyan vmi.largest_chunk >> 10 1616a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 162293c07e3SXishi Qiu ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10) 1636a46079cSAndi Kleen #endif 16479134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 16579134171SAndrea Arcangeli ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * 16679134171SAndrea Arcangeli HPAGE_PMD_NR) 16779134171SAndrea Arcangeli #endif 168e1759c21SAlexey Dobriyan ); 169e1759c21SAlexey Dobriyan 170e1759c21SAlexey Dobriyan hugetlb_report_meminfo(m); 171e1759c21SAlexey Dobriyan 172e1759c21SAlexey Dobriyan arch_report_meminfo(m); 173e1759c21SAlexey Dobriyan 174e1759c21SAlexey Dobriyan return 0; 175e1759c21SAlexey Dobriyan #undef K 176e1759c21SAlexey Dobriyan } 177e1759c21SAlexey Dobriyan 178e1759c21SAlexey Dobriyan static int meminfo_proc_open(struct inode *inode, struct file *file) 179e1759c21SAlexey Dobriyan { 180e1759c21SAlexey Dobriyan return single_open(file, meminfo_proc_show, NULL); 181e1759c21SAlexey Dobriyan } 182e1759c21SAlexey Dobriyan 183e1759c21SAlexey Dobriyan static const struct file_operations meminfo_proc_fops = { 184e1759c21SAlexey Dobriyan .open = meminfo_proc_open, 185e1759c21SAlexey Dobriyan .read = seq_read, 186e1759c21SAlexey Dobriyan .llseek = seq_lseek, 187e1759c21SAlexey Dobriyan .release = single_release, 188e1759c21SAlexey Dobriyan }; 189e1759c21SAlexey Dobriyan 190e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void) 191e1759c21SAlexey Dobriyan { 192e1759c21SAlexey Dobriyan proc_create("meminfo", 0, NULL, &meminfo_proc_fops); 193e1759c21SAlexey Dobriyan return 0; 194e1759c21SAlexey Dobriyan } 195e1759c21SAlexey Dobriyan module_init(proc_meminfo_init); 196