| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 1 | #include <linux/fs.h> | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 2 | #include <linux/init.h> | 
|  | 3 | #include <linux/kernel.h> | 
|  | 4 | #include <linux/mm.h> | 
| Kirill A. Shutemov | cb900f4 | 2013-11-14 14:31:02 -0800 | [diff] [blame] | 5 | #include <linux/hugetlb.h> | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 6 | #include <linux/mman.h> | 
|  | 7 | #include <linux/mmzone.h> | 
|  | 8 | #include <linux/proc_fs.h> | 
|  | 9 | #include <linux/quicklist.h> | 
|  | 10 | #include <linux/seq_file.h> | 
|  | 11 | #include <linux/swap.h> | 
|  | 12 | #include <linux/vmstat.h> | 
| Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 13 | #include <linux/atomic.h> | 
| Joonsoo Kim | db3808c | 2013-04-29 15:07:28 -0700 | [diff] [blame] | 14 | #include <linux/vmalloc.h> | 
| Pintu Kumar | 47f8f92 | 2014-12-18 16:17:18 -0800 | [diff] [blame^] | 15 | #ifdef CONFIG_CMA | 
|  | 16 | #include <linux/cma.h> | 
|  | 17 | #endif | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 18 | #include <asm/page.h> | 
|  | 19 | #include <asm/pgtable.h> | 
|  | 20 | #include "internal.h" | 
|  | 21 |  | 
|  | 22 | void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) | 
|  | 23 | { | 
|  | 24 | } | 
|  | 25 |  | 
|  | 26 | static int meminfo_proc_show(struct seq_file *m, void *v) | 
|  | 27 | { | 
|  | 28 | struct sysinfo i; | 
|  | 29 | unsigned long committed; | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 30 | struct vmalloc_info vmi; | 
|  | 31 | long cached; | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 32 | long available; | 
|  | 33 | unsigned long pagecache; | 
|  | 34 | unsigned long wmark_low = 0; | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 35 | unsigned long pages[NR_LRU_LISTS]; | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 36 | struct zone *zone; | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 37 | int lru; | 
|  | 38 |  | 
|  | 39 | /* | 
|  | 40 | * display in kilobytes. | 
|  | 41 | */ | 
|  | 42 | #define K(x) ((x) << (PAGE_SHIFT - 10)) | 
|  | 43 | si_meminfo(&i); | 
|  | 44 | si_swapinfo(&i); | 
| KOSAKI Motohiro | 00a62ce | 2009-04-30 15:08:51 -0700 | [diff] [blame] | 45 | committed = percpu_counter_read_positive(&vm_committed_as); | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 46 |  | 
|  | 47 | cached = global_page_state(NR_FILE_PAGES) - | 
| Shaohua Li | 33806f0 | 2013-02-22 16:34:37 -0800 | [diff] [blame] | 48 | total_swapcache_pages() - i.bufferram; | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 49 | if (cached < 0) | 
|  | 50 | cached = 0; | 
|  | 51 |  | 
|  | 52 | get_vmalloc_info(&vmi); | 
|  | 53 |  | 
|  | 54 | for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) | 
|  | 55 | pages[lru] = global_page_state(NR_LRU_BASE + lru); | 
|  | 56 |  | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 57 | for_each_zone(zone) | 
|  | 58 | wmark_low += zone->watermark[WMARK_LOW]; | 
|  | 59 |  | 
|  | 60 | /* | 
|  | 61 | * Estimate the amount of memory available for userspace allocations, | 
|  | 62 | * without causing swapping. | 
|  | 63 | * | 
|  | 64 | * Free memory cannot be taken below the low watermark, before the | 
|  | 65 | * system starts swapping. | 
|  | 66 | */ | 
|  | 67 | available = i.freeram - wmark_low; | 
|  | 68 |  | 
|  | 69 | /* | 
|  | 70 | * Not all the page cache can be freed, otherwise the system will | 
|  | 71 | * start swapping. Assume at least half of the page cache, or the | 
|  | 72 | * low watermark worth of cache, needs to stay. | 
|  | 73 | */ | 
|  | 74 | pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE]; | 
|  | 75 | pagecache -= min(pagecache / 2, wmark_low); | 
|  | 76 | available += pagecache; | 
|  | 77 |  | 
|  | 78 | /* | 
| Luiz Capitulino | f0b5664 | 2014-04-07 15:38:32 -0700 | [diff] [blame] | 79 | * Part of the reclaimable slab consists of items that are in use, | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 80 | * and cannot be freed. Cap this estimate at the low watermark. | 
|  | 81 | */ | 
|  | 82 | available += global_page_state(NR_SLAB_RECLAIMABLE) - | 
|  | 83 | min(global_page_state(NR_SLAB_RECLAIMABLE) / 2, wmark_low); | 
|  | 84 |  | 
|  | 85 | if (available < 0) | 
|  | 86 | available = 0; | 
|  | 87 |  | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 88 | /* | 
|  | 89 | * Tagged format, for easy grepping and expansion. | 
|  | 90 | */ | 
|  | 91 | seq_printf(m, | 
|  | 92 | "MemTotal:       %8lu kB\n" | 
|  | 93 | "MemFree:        %8lu kB\n" | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 94 | "MemAvailable:   %8lu kB\n" | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 95 | "Buffers:        %8lu kB\n" | 
|  | 96 | "Cached:         %8lu kB\n" | 
|  | 97 | "SwapCached:     %8lu kB\n" | 
|  | 98 | "Active:         %8lu kB\n" | 
|  | 99 | "Inactive:       %8lu kB\n" | 
|  | 100 | "Active(anon):   %8lu kB\n" | 
|  | 101 | "Inactive(anon): %8lu kB\n" | 
|  | 102 | "Active(file):   %8lu kB\n" | 
|  | 103 | "Inactive(file): %8lu kB\n" | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 104 | "Unevictable:    %8lu kB\n" | 
|  | 105 | "Mlocked:        %8lu kB\n" | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 106 | #ifdef CONFIG_HIGHMEM | 
|  | 107 | "HighTotal:      %8lu kB\n" | 
|  | 108 | "HighFree:       %8lu kB\n" | 
|  | 109 | "LowTotal:       %8lu kB\n" | 
|  | 110 | "LowFree:        %8lu kB\n" | 
|  | 111 | #endif | 
| David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 112 | #ifndef CONFIG_MMU | 
|  | 113 | "MmapCopy:       %8lu kB\n" | 
|  | 114 | #endif | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 115 | "SwapTotal:      %8lu kB\n" | 
|  | 116 | "SwapFree:       %8lu kB\n" | 
|  | 117 | "Dirty:          %8lu kB\n" | 
|  | 118 | "Writeback:      %8lu kB\n" | 
|  | 119 | "AnonPages:      %8lu kB\n" | 
|  | 120 | "Mapped:         %8lu kB\n" | 
| KOSAKI Motohiro | 4b02108 | 2009-09-21 17:01:33 -0700 | [diff] [blame] | 121 | "Shmem:          %8lu kB\n" | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 122 | "Slab:           %8lu kB\n" | 
|  | 123 | "SReclaimable:   %8lu kB\n" | 
|  | 124 | "SUnreclaim:     %8lu kB\n" | 
| KOSAKI Motohiro | c6a7f57 | 2009-09-21 17:01:32 -0700 | [diff] [blame] | 125 | "KernelStack:    %8lu kB\n" | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 126 | "PageTables:     %8lu kB\n" | 
|  | 127 | #ifdef CONFIG_QUICKLIST | 
|  | 128 | "Quicklists:     %8lu kB\n" | 
|  | 129 | #endif | 
|  | 130 | "NFS_Unstable:   %8lu kB\n" | 
|  | 131 | "Bounce:         %8lu kB\n" | 
|  | 132 | "WritebackTmp:   %8lu kB\n" | 
|  | 133 | "CommitLimit:    %8lu kB\n" | 
|  | 134 | "Committed_AS:   %8lu kB\n" | 
|  | 135 | "VmallocTotal:   %8lu kB\n" | 
|  | 136 | "VmallocUsed:    %8lu kB\n" | 
| Andi Kleen | 6a46079 | 2009-09-16 11:50:15 +0200 | [diff] [blame] | 137 | "VmallocChunk:   %8lu kB\n" | 
|  | 138 | #ifdef CONFIG_MEMORY_FAILURE | 
| Hugh Dickins | 370c28d | 2009-10-26 16:49:32 -0700 | [diff] [blame] | 139 | "HardwareCorrupted: %5lu kB\n" | 
| Andi Kleen | 6a46079 | 2009-09-16 11:50:15 +0200 | [diff] [blame] | 140 | #endif | 
| Andrea Arcangeli | 7913417 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 141 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | 
|  | 142 | "AnonHugePages:  %8lu kB\n" | 
|  | 143 | #endif | 
| Pintu Kumar | 47f8f92 | 2014-12-18 16:17:18 -0800 | [diff] [blame^] | 144 | #ifdef CONFIG_CMA | 
|  | 145 | "CmaTotal:       %8lu kB\n" | 
|  | 146 | "CmaFree:        %8lu kB\n" | 
|  | 147 | #endif | 
| Andi Kleen | 6a46079 | 2009-09-16 11:50:15 +0200 | [diff] [blame] | 148 | , | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 149 | K(i.totalram), | 
|  | 150 | K(i.freeram), | 
| Rik van Riel | 34e431b | 2014-01-21 15:49:05 -0800 | [diff] [blame] | 151 | K(available), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 152 | K(i.bufferram), | 
|  | 153 | K(cached), | 
| Shaohua Li | 33806f0 | 2013-02-22 16:34:37 -0800 | [diff] [blame] | 154 | K(total_swapcache_pages()), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 155 | K(pages[LRU_ACTIVE_ANON]   + pages[LRU_ACTIVE_FILE]), | 
|  | 156 | K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]), | 
|  | 157 | K(pages[LRU_ACTIVE_ANON]), | 
|  | 158 | K(pages[LRU_INACTIVE_ANON]), | 
|  | 159 | K(pages[LRU_ACTIVE_FILE]), | 
|  | 160 | K(pages[LRU_INACTIVE_FILE]), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 161 | K(pages[LRU_UNEVICTABLE]), | 
|  | 162 | K(global_page_state(NR_MLOCK)), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 163 | #ifdef CONFIG_HIGHMEM | 
|  | 164 | K(i.totalhigh), | 
|  | 165 | K(i.freehigh), | 
|  | 166 | K(i.totalram-i.totalhigh), | 
|  | 167 | K(i.freeram-i.freehigh), | 
|  | 168 | #endif | 
| David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 169 | #ifndef CONFIG_MMU | 
| David Howells | 33e5d769 | 2009-04-02 16:56:32 -0700 | [diff] [blame] | 170 | K((unsigned long) atomic_long_read(&mmap_pages_allocated)), | 
| David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 171 | #endif | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 172 | K(i.totalswap), | 
|  | 173 | K(i.freeswap), | 
|  | 174 | K(global_page_state(NR_FILE_DIRTY)), | 
|  | 175 | K(global_page_state(NR_WRITEBACK)), | 
| Claudio Scordino | b53fc7c | 2011-12-08 14:33:56 -0800 | [diff] [blame] | 176 | K(global_page_state(NR_ANON_PAGES)), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 177 | K(global_page_state(NR_FILE_MAPPED)), | 
| Rafael Aquini | cc7452b | 2014-08-06 16:06:38 -0700 | [diff] [blame] | 178 | K(i.sharedram), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 179 | K(global_page_state(NR_SLAB_RECLAIMABLE) + | 
|  | 180 | global_page_state(NR_SLAB_UNRECLAIMABLE)), | 
|  | 181 | K(global_page_state(NR_SLAB_RECLAIMABLE)), | 
|  | 182 | K(global_page_state(NR_SLAB_UNRECLAIMABLE)), | 
| KOSAKI Motohiro | c6a7f57 | 2009-09-21 17:01:32 -0700 | [diff] [blame] | 183 | global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024, | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 184 | K(global_page_state(NR_PAGETABLE)), | 
|  | 185 | #ifdef CONFIG_QUICKLIST | 
|  | 186 | K(quicklist_total_size()), | 
|  | 187 | #endif | 
|  | 188 | K(global_page_state(NR_UNSTABLE_NFS)), | 
|  | 189 | K(global_page_state(NR_BOUNCE)), | 
|  | 190 | K(global_page_state(NR_WRITEBACK_TEMP)), | 
| Jerome Marchand | 00619bc | 2013-11-12 15:08:31 -0800 | [diff] [blame] | 191 | K(vm_commit_limit()), | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 192 | K(committed), | 
|  | 193 | (unsigned long)VMALLOC_TOTAL >> 10, | 
|  | 194 | vmi.used >> 10, | 
|  | 195 | vmi.largest_chunk >> 10 | 
| Andi Kleen | 6a46079 | 2009-09-16 11:50:15 +0200 | [diff] [blame] | 196 | #ifdef CONFIG_MEMORY_FAILURE | 
| Pintu Kumar | 47f8f92 | 2014-12-18 16:17:18 -0800 | [diff] [blame^] | 197 | , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10) | 
| Andi Kleen | 6a46079 | 2009-09-16 11:50:15 +0200 | [diff] [blame] | 198 | #endif | 
| Andrea Arcangeli | 7913417 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 199 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | 
| Pintu Kumar | 47f8f92 | 2014-12-18 16:17:18 -0800 | [diff] [blame^] | 200 | , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * | 
| Andrea Arcangeli | 7913417 | 2011-01-13 15:46:58 -0800 | [diff] [blame] | 201 | HPAGE_PMD_NR) | 
|  | 202 | #endif | 
| Pintu Kumar | 47f8f92 | 2014-12-18 16:17:18 -0800 | [diff] [blame^] | 203 | #ifdef CONFIG_CMA | 
|  | 204 | , K(totalcma_pages) | 
|  | 205 | , K(global_page_state(NR_FREE_CMA_PAGES)) | 
|  | 206 | #endif | 
| Alexey Dobriyan | e1759c2 | 2008-10-15 23:50:22 +0400 | [diff] [blame] | 207 | ); | 
|  | 208 |  | 
|  | 209 | hugetlb_report_meminfo(m); | 
|  | 210 |  | 
|  | 211 | arch_report_meminfo(m); | 
|  | 212 |  | 
|  | 213 | return 0; | 
|  | 214 | #undef K | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | static int meminfo_proc_open(struct inode *inode, struct file *file) | 
|  | 218 | { | 
|  | 219 | return single_open(file, meminfo_proc_show, NULL); | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | static const struct file_operations meminfo_proc_fops = { | 
|  | 223 | .open		= meminfo_proc_open, | 
|  | 224 | .read		= seq_read, | 
|  | 225 | .llseek		= seq_lseek, | 
|  | 226 | .release	= single_release, | 
|  | 227 | }; | 
|  | 228 |  | 
|  | 229 | static int __init proc_meminfo_init(void) | 
|  | 230 | { | 
|  | 231 | proc_create("meminfo", 0, NULL, &meminfo_proc_fops); | 
|  | 232 | return 0; | 
|  | 233 | } | 
| Paul Gortmaker | abaf378 | 2014-01-23 15:55:45 -0800 | [diff] [blame] | 234 | fs_initcall(proc_meminfo_init); |