blob: d3ebf2e618535bd2fa7daa0bfe948cb1a9bfc062 [file] [log] [blame]
Alexey Dobriyane1759c22008-10-15 23:50:22 +04001#include <linux/fs.h>
Alexey Dobriyane1759c22008-10-15 23:50:22 +04002#include <linux/init.h>
3#include <linux/kernel.h>
4#include <linux/mm.h>
Kirill A. Shutemovcb900f42013-11-14 14:31:02 -08005#include <linux/hugetlb.h>
Alexey Dobriyane1759c22008-10-15 23:50:22 +04006#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 Sharma600634972011-07-26 16:09:06 -070013#include <linux/atomic.h>
Joonsoo Kimdb3808c2013-04-29 15:07:28 -070014#include <linux/vmalloc.h>
Pintu Kumar47f8f922014-12-18 16:17:18 -080015#ifdef CONFIG_CMA
16#include <linux/cma.h>
17#endif
Alexey Dobriyane1759c22008-10-15 23:50:22 +040018#include <asm/page.h>
19#include <asm/pgtable.h>
20#include "internal.h"
21
22void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
23{
24}
25
26static int meminfo_proc_show(struct seq_file *m, void *v)
27{
28 struct sysinfo i;
29 unsigned long committed;
Alexey Dobriyane1759c22008-10-15 23:50:22 +040030 struct vmalloc_info vmi;
31 long cached;
Rik van Riel34e431b2014-01-21 15:49:05 -080032 long available;
33 unsigned long pagecache;
34 unsigned long wmark_low = 0;
Alexey Dobriyane1759c22008-10-15 23:50:22 +040035 unsigned long pages[NR_LRU_LISTS];
Rik van Riel34e431b2014-01-21 15:49:05 -080036 struct zone *zone;
Alexey Dobriyane1759c22008-10-15 23:50:22 +040037 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 Motohiro00a62ce2009-04-30 15:08:51 -070045 committed = percpu_counter_read_positive(&vm_committed_as);
Alexey Dobriyane1759c22008-10-15 23:50:22 +040046
47 cached = global_page_state(NR_FILE_PAGES) -
Shaohua Li33806f02013-02-22 16:34:37 -080048 total_swapcache_pages() - i.bufferram;
Alexey Dobriyane1759c22008-10-15 23:50:22 +040049 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 Riel34e431b2014-01-21 15:49:05 -080057 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 Capitulinof0b56642014-04-07 15:38:32 -070079 * Part of the reclaimable slab consists of items that are in use,
Rik van Riel34e431b2014-01-21 15:49:05 -080080 * 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 Dobriyane1759c22008-10-15 23:50:22 +040088 /*
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 Riel34e431b2014-01-21 15:49:05 -080094 "MemAvailable: %8lu kB\n"
Alexey Dobriyane1759c22008-10-15 23:50:22 +040095 "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 Dobriyane1759c22008-10-15 23:50:22 +0400104 "Unevictable: %8lu kB\n"
105 "Mlocked: %8lu kB\n"
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400106#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 Howells8feae132009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113 "MmapCopy: %8lu kB\n"
114#endif
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400115 "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 Motohiro4b021082009-09-21 17:01:33 -0700121 "Shmem: %8lu kB\n"
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400122 "Slab: %8lu kB\n"
123 "SReclaimable: %8lu kB\n"
124 "SUnreclaim: %8lu kB\n"
KOSAKI Motohiroc6a7f572009-09-21 17:01:32 -0700125 "KernelStack: %8lu kB\n"
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400126 "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 Kleen6a460792009-09-16 11:50:15 +0200137 "VmallocChunk: %8lu kB\n"
138#ifdef CONFIG_MEMORY_FAILURE
Hugh Dickins370c28d2009-10-26 16:49:32 -0700139 "HardwareCorrupted: %5lu kB\n"
Andi Kleen6a460792009-09-16 11:50:15 +0200140#endif
Andrea Arcangeli79134172011-01-13 15:46:58 -0800141#ifdef CONFIG_TRANSPARENT_HUGEPAGE
142 "AnonHugePages: %8lu kB\n"
143#endif
Pintu Kumar47f8f922014-12-18 16:17:18 -0800144#ifdef CONFIG_CMA
145 "CmaTotal: %8lu kB\n"
146 "CmaFree: %8lu kB\n"
147#endif
Andi Kleen6a460792009-09-16 11:50:15 +0200148 ,
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400149 K(i.totalram),
150 K(i.freeram),
Rik van Riel34e431b2014-01-21 15:49:05 -0800151 K(available),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400152 K(i.bufferram),
153 K(cached),
Shaohua Li33806f02013-02-22 16:34:37 -0800154 K(total_swapcache_pages()),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400155 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 Dobriyane1759c22008-10-15 23:50:22 +0400161 K(pages[LRU_UNEVICTABLE]),
162 K(global_page_state(NR_MLOCK)),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400163#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 Howells8feae132009-01-08 12:04:47 +0000169#ifndef CONFIG_MMU
David Howells33e5d7692009-04-02 16:56:32 -0700170 K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
David Howells8feae132009-01-08 12:04:47 +0000171#endif
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400172 K(i.totalswap),
173 K(i.freeswap),
174 K(global_page_state(NR_FILE_DIRTY)),
175 K(global_page_state(NR_WRITEBACK)),
Claudio Scordinob53fc7c2011-12-08 14:33:56 -0800176 K(global_page_state(NR_ANON_PAGES)),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400177 K(global_page_state(NR_FILE_MAPPED)),
Rafael Aquinicc7452b2014-08-06 16:06:38 -0700178 K(i.sharedram),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400179 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 Motohiroc6a7f572009-09-21 17:01:32 -0700183 global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400184 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 Marchand00619bc2013-11-12 15:08:31 -0800191 K(vm_commit_limit()),
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400192 K(committed),
193 (unsigned long)VMALLOC_TOTAL >> 10,
194 vmi.used >> 10,
195 vmi.largest_chunk >> 10
Andi Kleen6a460792009-09-16 11:50:15 +0200196#ifdef CONFIG_MEMORY_FAILURE
Pintu Kumar47f8f922014-12-18 16:17:18 -0800197 , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
Andi Kleen6a460792009-09-16 11:50:15 +0200198#endif
Andrea Arcangeli79134172011-01-13 15:46:58 -0800199#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Pintu Kumar47f8f922014-12-18 16:17:18 -0800200 , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
Andrea Arcangeli79134172011-01-13 15:46:58 -0800201 HPAGE_PMD_NR)
202#endif
Pintu Kumar47f8f922014-12-18 16:17:18 -0800203#ifdef CONFIG_CMA
204 , K(totalcma_pages)
205 , K(global_page_state(NR_FREE_CMA_PAGES))
206#endif
Alexey Dobriyane1759c22008-10-15 23:50:22 +0400207 );
208
209 hugetlb_report_meminfo(m);
210
211 arch_report_meminfo(m);
212
213 return 0;
214#undef K
215}
216
217static int meminfo_proc_open(struct inode *inode, struct file *file)
218{
219 return single_open(file, meminfo_proc_show, NULL);
220}
221
222static 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
229static int __init proc_meminfo_init(void)
230{
231 proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
232 return 0;
233}
Paul Gortmakerabaf3782014-01-23 15:55:45 -0800234fs_initcall(proc_meminfo_init);