Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / fs / proc / meminfo.c
1 #include <linux/fs.h>
2 #include <linux/init.h>
3 #include <linux/kernel.h>
4 #include <linux/mm.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>
15 #ifdef CONFIG_CMA
16 #include <linux/cma.h>
17 #endif
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;
30         struct vmalloc_info vmi;
31         long cached;
32         long available;
33         unsigned long pagecache;
34         unsigned long wmark_low = 0;
35         unsigned long pages[NR_LRU_LISTS];
36         struct zone *zone;
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);
45         committed = percpu_counter_read_positive(&vm_committed_as);
46
47         cached = global_page_state(NR_FILE_PAGES) -
48                         total_swapcache_pages() - i.bufferram;
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
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         /*
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.
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
88         /*
89          * Tagged format, for easy grepping and expansion.
90          */
91         seq_printf(m,
92                 "MemTotal:       %8lu kB\n"
93                 "MemFree:        %8lu kB\n"
94                 "MemAvailable:   %8lu kB\n"
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"
104                 "Unevictable:    %8lu kB\n"
105                 "Mlocked:        %8lu kB\n"
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
112 #ifndef CONFIG_MMU
113                 "MmapCopy:       %8lu kB\n"
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"
121                 "Shmem:          %8lu kB\n"
122                 "Slab:           %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"
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"
137                 "VmallocChunk:   %8lu kB\n"
138 #ifdef CONFIG_MEMORY_FAILURE
139                 "HardwareCorrupted: %5lu kB\n"
140 #endif
141 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
142                 "AnonHugePages:  %8lu kB\n"
143 #endif
144 #ifdef CONFIG_CMA
145                 "CmaTotal:       %8lu kB\n"
146                 "CmaFree:        %8lu kB\n"
147 #endif
148                 ,
149                 K(i.totalram),
150                 K(i.freeram),
151                 K(available),
152                 K(i.bufferram),
153                 K(cached),
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
164                 K(i.totalhigh),
165                 K(i.freehigh),
166                 K(i.totalram-i.totalhigh),
167                 K(i.freeram-i.freehigh),
168 #endif
169 #ifndef CONFIG_MMU
170                 K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
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)),
176                 K(global_page_state(NR_ANON_PAGES)),
177                 K(global_page_state(NR_FILE_MAPPED)),
178                 K(i.sharedram),
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()),
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)),
191                 K(vm_commit_limit()),
192                 K(committed),
193                 (unsigned long)VMALLOC_TOTAL >> 10,
194                 vmi.used >> 10,
195                 vmi.largest_chunk >> 10
196 #ifdef CONFIG_MEMORY_FAILURE
197                 , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
198 #endif
199 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
200                 , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
201                    HPAGE_PMD_NR)
202 #endif
203 #ifdef CONFIG_CMA
204                 , K(totalcma_pages)
205                 , K(global_page_state(NR_FREE_CMA_PAGES))
206 #endif
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 }
234 fs_initcall(proc_meminfo_init);