2 #include <linux/init.h>
3 #include <linux/kernel.h>
5 #include <linux/hugetlb.h>
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>
13 #include <linux/atomic.h>
14 #include <linux/vmalloc.h>
16 #include <linux/cma.h>
19 #include <asm/pgtable.h>
22 void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
26 static int meminfo_proc_show(struct seq_file *m, void *v)
29 unsigned long committed;
30 struct vmalloc_info vmi;
33 unsigned long pagecache;
34 unsigned long wmark_low = 0;
35 unsigned long pages[NR_LRU_LISTS];
40 * display in kilobytes.
42 #define K(x) ((x) << (PAGE_SHIFT - 10))
45 committed = percpu_counter_read_positive(&vm_committed_as);
47 cached = global_page_state(NR_FILE_PAGES) -
48 total_swapcache_pages() - i.bufferram;
52 get_vmalloc_info(&vmi);
54 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
55 pages[lru] = global_page_state(NR_LRU_BASE + lru);
58 wmark_low += zone->watermark[WMARK_LOW];
61 * Estimate the amount of memory available for userspace allocations,
62 * without causing swapping.
64 * Free memory cannot be taken below the low watermark, before the
65 * system starts swapping.
67 available = i.freeram - wmark_low;
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.
74 pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE];
75 pagecache -= min(pagecache / 2, wmark_low);
76 available += pagecache;
79 * Part of the reclaimable slab consists of items that are in use,
80 * and cannot be freed. Cap this estimate at the low watermark.
82 available += global_page_state(NR_SLAB_RECLAIMABLE) -
83 min(global_page_state(NR_SLAB_RECLAIMABLE) / 2, wmark_low);
89 * Tagged format, for easy grepping and expansion.
94 "MemAvailable: %8lu kB\n"
97 "SwapCached: %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"
104 "Unevictable: %8lu kB\n"
106 #ifdef CONFIG_HIGHMEM
107 "HighTotal: %8lu kB\n"
108 "HighFree: %8lu kB\n"
109 "LowTotal: %8lu kB\n"
113 "MmapCopy: %8lu kB\n"
115 "SwapTotal: %8lu kB\n"
116 "SwapFree: %8lu kB\n"
118 "Writeback: %8lu kB\n"
119 "AnonPages: %8lu kB\n"
123 "SReclaimable: %8lu kB\n"
124 "SUnreclaim: %8lu kB\n"
125 "KernelStack: %8lu kB\n"
126 "PageTables: %8lu kB\n"
127 #ifdef CONFIG_QUICKLIST
128 "Quicklists: %8lu kB\n"
130 "NFS_Unstable: %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"
137 "VmallocChunk: %8lu kB\n"
138 #ifdef CONFIG_MEMORY_FAILURE
139 "HardwareCorrupted: %5lu kB\n"
141 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
142 "AnonHugePages: %8lu kB\n"
145 "CmaTotal: %8lu kB\n"
154 K(total_swapcache_pages()),
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]),
161 K(pages[LRU_UNEVICTABLE]),
162 K(global_page_state(NR_MLOCK)),
163 #ifdef CONFIG_HIGHMEM
166 K(i.totalram-i.totalhigh),
167 K(i.freeram-i.freehigh),
170 K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
174 K(global_page_state(NR_FILE_DIRTY)),
175 K(global_page_state(NR_WRITEBACK)),
176 K(global_page_state(NR_ANON_PAGES)),
177 K(global_page_state(NR_FILE_MAPPED)),
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)),
183 global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
184 K(global_page_state(NR_PAGETABLE)),
185 #ifdef CONFIG_QUICKLIST
186 K(quicklist_total_size()),
188 K(global_page_state(NR_UNSTABLE_NFS)),
189 K(global_page_state(NR_BOUNCE)),
190 K(global_page_state(NR_WRITEBACK_TEMP)),
191 K(vm_commit_limit()),
193 (unsigned long)VMALLOC_TOTAL >> 10,
195 vmi.largest_chunk >> 10
196 #ifdef CONFIG_MEMORY_FAILURE
197 , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
199 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
200 , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
205 , K(global_page_state(NR_FREE_CMA_PAGES))
209 hugetlb_report_meminfo(m);
211 arch_report_meminfo(m);
217 static int meminfo_proc_open(struct inode *inode, struct file *file)
219 return single_open(file, meminfo_proc_show, NULL);
222 static const struct file_operations meminfo_proc_fops = {
223 .open = meminfo_proc_open,
226 .release = single_release,
229 static int __init proc_meminfo_init(void)
231 proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
234 fs_initcall(proc_meminfo_init);