]>
Commit | Line | Data |
---|---|---|
e1759c21 | 1 | #include <linux/fs.h> |
e1759c21 AD |
2 | #include <linux/init.h> |
3 | #include <linux/kernel.h> | |
4 | #include <linux/mm.h> | |
cb900f41 | 5 | #include <linux/hugetlb.h> |
e1759c21 AD |
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> | |
60063497 | 13 | #include <linux/atomic.h> |
db3808c1 | 14 | #include <linux/vmalloc.h> |
47f8f929 PK |
15 | #ifdef CONFIG_CMA |
16 | #include <linux/cma.h> | |
17 | #endif | |
e1759c21 AD |
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; | |
e1759c21 AD |
30 | struct vmalloc_info vmi; |
31 | long cached; | |
34e431b0 RR |
32 | long available; |
33 | unsigned long pagecache; | |
34 | unsigned long wmark_low = 0; | |
e1759c21 | 35 | unsigned long pages[NR_LRU_LISTS]; |
34e431b0 | 36 | struct zone *zone; |
e1759c21 AD |
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); | |
00a62ce9 | 45 | committed = percpu_counter_read_positive(&vm_committed_as); |
e1759c21 AD |
46 | |
47 | cached = global_page_state(NR_FILE_PAGES) - | |
33806f06 | 48 | total_swapcache_pages() - i.bufferram; |
e1759c21 AD |
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 | ||
34e431b0 RR |
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 | /* | |
f0b5664b | 79 | * Part of the reclaimable slab consists of items that are in use, |
34e431b0 RR |
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 | ||
e1759c21 AD |
88 | /* |
89 | * Tagged format, for easy grepping and expansion. | |
90 | */ | |
91 | seq_printf(m, | |
92 | "MemTotal: %8lu kB\n" | |
93 | "MemFree: %8lu kB\n" | |
34e431b0 | 94 | "MemAvailable: %8lu kB\n" |
e1759c21 AD |
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" | |
e1759c21 AD |
104 | "Unevictable: %8lu kB\n" |
105 | "Mlocked: %8lu kB\n" | |
e1759c21 AD |
106 | #ifdef CONFIG_HIGHMEM |
107 | "HighTotal: %8lu kB\n" | |
108 | "HighFree: %8lu kB\n" | |
109 | "LowTotal: %8lu kB\n" | |
110 | "LowFree: %8lu kB\n" | |
8feae131 DH |
111 | #endif |
112 | #ifndef CONFIG_MMU | |
113 | "MmapCopy: %8lu kB\n" | |
e1759c21 AD |
114 | #endif |
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" | |
4b02108a | 121 | "Shmem: %8lu kB\n" |
e1759c21 AD |
122 | "Slab: %8lu kB\n" |
123 | "SReclaimable: %8lu kB\n" | |
124 | "SUnreclaim: %8lu kB\n" | |
c6a7f572 | 125 | "KernelStack: %8lu kB\n" |
e1759c21 AD |
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" | |
6a46079c AK |
137 | "VmallocChunk: %8lu kB\n" |
138 | #ifdef CONFIG_MEMORY_FAILURE | |
370c28de | 139 | "HardwareCorrupted: %5lu kB\n" |
79134171 AA |
140 | #endif |
141 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | |
142 | "AnonHugePages: %8lu kB\n" | |
47f8f929 PK |
143 | #endif |
144 | #ifdef CONFIG_CMA | |
145 | "CmaTotal: %8lu kB\n" | |
146 | "CmaFree: %8lu kB\n" | |
6a46079c AK |
147 | #endif |
148 | , | |
e1759c21 AD |
149 | K(i.totalram), |
150 | K(i.freeram), | |
34e431b0 | 151 | K(available), |
e1759c21 AD |
152 | K(i.bufferram), |
153 | K(cached), | |
33806f06 | 154 | K(total_swapcache_pages()), |
e1759c21 AD |
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]), | |
e1759c21 AD |
161 | K(pages[LRU_UNEVICTABLE]), |
162 | K(global_page_state(NR_MLOCK)), | |
e1759c21 AD |
163 | #ifdef CONFIG_HIGHMEM |
164 | K(i.totalhigh), | |
165 | K(i.freehigh), | |
166 | K(i.totalram-i.totalhigh), | |
167 | K(i.freeram-i.freehigh), | |
8feae131 DH |
168 | #endif |
169 | #ifndef CONFIG_MMU | |
33e5d769 | 170 | K((unsigned long) atomic_long_read(&mmap_pages_allocated)), |
e1759c21 AD |
171 | #endif |
172 | K(i.totalswap), | |
173 | K(i.freeswap), | |
174 | K(global_page_state(NR_FILE_DIRTY)), | |
175 | K(global_page_state(NR_WRITEBACK)), | |
b53fc7c2 | 176 | K(global_page_state(NR_ANON_PAGES)), |
e1759c21 | 177 | K(global_page_state(NR_FILE_MAPPED)), |
cc7452b6 | 178 | K(i.sharedram), |
e1759c21 AD |
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)), | |
c6a7f572 | 183 | global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024, |
e1759c21 AD |
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)), | |
00619bcc | 191 | K(vm_commit_limit()), |
e1759c21 AD |
192 | K(committed), |
193 | (unsigned long)VMALLOC_TOTAL >> 10, | |
194 | vmi.used >> 10, | |
195 | vmi.largest_chunk >> 10 | |
6a46079c | 196 | #ifdef CONFIG_MEMORY_FAILURE |
47f8f929 | 197 | , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10) |
79134171 AA |
198 | #endif |
199 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | |
47f8f929 | 200 | , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * |
79134171 | 201 | HPAGE_PMD_NR) |
47f8f929 PK |
202 | #endif |
203 | #ifdef CONFIG_CMA | |
204 | , K(totalcma_pages) | |
205 | , K(global_page_state(NR_FREE_CMA_PAGES)) | |
6a46079c | 206 | #endif |
e1759c21 AD |
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 | } | |
abaf3787 | 234 | fs_initcall(proc_meminfo_init); |