xref: /openbmc/linux/fs/proc/meminfo.c (revision 2f95ff90b99600f53df4a0aa652322d349d67957)
1e1759c21SAlexey Dobriyan #include <linux/fs.h>
2e1759c21SAlexey Dobriyan #include <linux/init.h>
3e1759c21SAlexey Dobriyan #include <linux/kernel.h>
4e1759c21SAlexey Dobriyan #include <linux/mm.h>
5cb900f41SKirill A. Shutemov #include <linux/hugetlb.h>
6e1759c21SAlexey Dobriyan #include <linux/mman.h>
7e1759c21SAlexey Dobriyan #include <linux/mmzone.h>
8e1759c21SAlexey Dobriyan #include <linux/proc_fs.h>
9e1759c21SAlexey Dobriyan #include <linux/quicklist.h>
10e1759c21SAlexey Dobriyan #include <linux/seq_file.h>
11e1759c21SAlexey Dobriyan #include <linux/swap.h>
12e1759c21SAlexey Dobriyan #include <linux/vmstat.h>
1360063497SArun Sharma #include <linux/atomic.h>
14db3808c1SJoonsoo Kim #include <linux/vmalloc.h>
1547f8f929SPintu Kumar #ifdef CONFIG_CMA
1647f8f929SPintu Kumar #include <linux/cma.h>
1747f8f929SPintu Kumar #endif
18e1759c21SAlexey Dobriyan #include <asm/page.h>
19e1759c21SAlexey Dobriyan #include <asm/pgtable.h>
20e1759c21SAlexey Dobriyan #include "internal.h"
21e1759c21SAlexey Dobriyan 
22e1759c21SAlexey Dobriyan void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
23e1759c21SAlexey Dobriyan {
24e1759c21SAlexey Dobriyan }
25e1759c21SAlexey Dobriyan 
26e1759c21SAlexey Dobriyan static int meminfo_proc_show(struct seq_file *m, void *v)
27e1759c21SAlexey Dobriyan {
28e1759c21SAlexey Dobriyan 	struct sysinfo i;
29e1759c21SAlexey Dobriyan 	unsigned long committed;
30e1759c21SAlexey Dobriyan 	long cached;
3134e431b0SRik van Riel 	long available;
32e1759c21SAlexey Dobriyan 	unsigned long pages[NR_LRU_LISTS];
33e1759c21SAlexey Dobriyan 	int lru;
34e1759c21SAlexey Dobriyan 
35e1759c21SAlexey Dobriyan /*
36e1759c21SAlexey Dobriyan  * display in kilobytes.
37e1759c21SAlexey Dobriyan  */
38e1759c21SAlexey Dobriyan #define K(x) ((x) << (PAGE_SHIFT - 10))
39e1759c21SAlexey Dobriyan 	si_meminfo(&i);
40e1759c21SAlexey Dobriyan 	si_swapinfo(&i);
4100a62ce9SKOSAKI Motohiro 	committed = percpu_counter_read_positive(&vm_committed_as);
42e1759c21SAlexey Dobriyan 
4311fb9989SMel Gorman 	cached = global_node_page_state(NR_FILE_PAGES) -
4433806f06SShaohua Li 			total_swapcache_pages() - i.bufferram;
45e1759c21SAlexey Dobriyan 	if (cached < 0)
46e1759c21SAlexey Dobriyan 		cached = 0;
47e1759c21SAlexey Dobriyan 
48e1759c21SAlexey Dobriyan 	for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
49*2f95ff90SMel Gorman 		pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
50e1759c21SAlexey Dobriyan 
51d02bd27bSIgor Redko 	available = si_mem_available();
5234e431b0SRik van Riel 
53e1759c21SAlexey Dobriyan 	/*
54e1759c21SAlexey Dobriyan 	 * Tagged format, for easy grepping and expansion.
55e1759c21SAlexey Dobriyan 	 */
56e1759c21SAlexey Dobriyan 	seq_printf(m,
57e1759c21SAlexey Dobriyan 		"MemTotal:       %8lu kB\n"
58e1759c21SAlexey Dobriyan 		"MemFree:        %8lu kB\n"
5934e431b0SRik van Riel 		"MemAvailable:   %8lu kB\n"
60e1759c21SAlexey Dobriyan 		"Buffers:        %8lu kB\n"
61e1759c21SAlexey Dobriyan 		"Cached:         %8lu kB\n"
62e1759c21SAlexey Dobriyan 		"SwapCached:     %8lu kB\n"
63e1759c21SAlexey Dobriyan 		"Active:         %8lu kB\n"
64e1759c21SAlexey Dobriyan 		"Inactive:       %8lu kB\n"
65e1759c21SAlexey Dobriyan 		"Active(anon):   %8lu kB\n"
66e1759c21SAlexey Dobriyan 		"Inactive(anon): %8lu kB\n"
67e1759c21SAlexey Dobriyan 		"Active(file):   %8lu kB\n"
68e1759c21SAlexey Dobriyan 		"Inactive(file): %8lu kB\n"
69e1759c21SAlexey Dobriyan 		"Unevictable:    %8lu kB\n"
70e1759c21SAlexey Dobriyan 		"Mlocked:        %8lu kB\n"
71e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM
72e1759c21SAlexey Dobriyan 		"HighTotal:      %8lu kB\n"
73e1759c21SAlexey Dobriyan 		"HighFree:       %8lu kB\n"
74e1759c21SAlexey Dobriyan 		"LowTotal:       %8lu kB\n"
75e1759c21SAlexey Dobriyan 		"LowFree:        %8lu kB\n"
76e1759c21SAlexey Dobriyan #endif
778feae131SDavid Howells #ifndef CONFIG_MMU
788feae131SDavid Howells 		"MmapCopy:       %8lu kB\n"
798feae131SDavid Howells #endif
80e1759c21SAlexey Dobriyan 		"SwapTotal:      %8lu kB\n"
81e1759c21SAlexey Dobriyan 		"SwapFree:       %8lu kB\n"
82e1759c21SAlexey Dobriyan 		"Dirty:          %8lu kB\n"
83e1759c21SAlexey Dobriyan 		"Writeback:      %8lu kB\n"
84e1759c21SAlexey Dobriyan 		"AnonPages:      %8lu kB\n"
85e1759c21SAlexey Dobriyan 		"Mapped:         %8lu kB\n"
864b02108aSKOSAKI Motohiro 		"Shmem:          %8lu kB\n"
87e1759c21SAlexey Dobriyan 		"Slab:           %8lu kB\n"
88e1759c21SAlexey Dobriyan 		"SReclaimable:   %8lu kB\n"
89e1759c21SAlexey Dobriyan 		"SUnreclaim:     %8lu kB\n"
90c6a7f572SKOSAKI Motohiro 		"KernelStack:    %8lu kB\n"
91e1759c21SAlexey Dobriyan 		"PageTables:     %8lu kB\n"
92e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST
93e1759c21SAlexey Dobriyan 		"Quicklists:     %8lu kB\n"
94e1759c21SAlexey Dobriyan #endif
95e1759c21SAlexey Dobriyan 		"NFS_Unstable:   %8lu kB\n"
96e1759c21SAlexey Dobriyan 		"Bounce:         %8lu kB\n"
97e1759c21SAlexey Dobriyan 		"WritebackTmp:   %8lu kB\n"
98e1759c21SAlexey Dobriyan 		"CommitLimit:    %8lu kB\n"
99e1759c21SAlexey Dobriyan 		"Committed_AS:   %8lu kB\n"
100e1759c21SAlexey Dobriyan 		"VmallocTotal:   %8lu kB\n"
101e1759c21SAlexey Dobriyan 		"VmallocUsed:    %8lu kB\n"
1026a46079cSAndi Kleen 		"VmallocChunk:   %8lu kB\n"
1036a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
104370c28deSHugh Dickins 		"HardwareCorrupted: %5lu kB\n"
1056a46079cSAndi Kleen #endif
10679134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE
10779134171SAndrea Arcangeli 		"AnonHugePages:  %8lu kB\n"
10865c45377SKirill A. Shutemov 		"ShmemHugePages: %8lu kB\n"
10965c45377SKirill A. Shutemov 		"ShmemPmdMapped: %8lu kB\n"
11079134171SAndrea Arcangeli #endif
11147f8f929SPintu Kumar #ifdef CONFIG_CMA
11247f8f929SPintu Kumar 		"CmaTotal:       %8lu kB\n"
11347f8f929SPintu Kumar 		"CmaFree:        %8lu kB\n"
11447f8f929SPintu Kumar #endif
1156a46079cSAndi Kleen 		,
116e1759c21SAlexey Dobriyan 		K(i.totalram),
117e1759c21SAlexey Dobriyan 		K(i.freeram),
11834e431b0SRik van Riel 		K(available),
119e1759c21SAlexey Dobriyan 		K(i.bufferram),
120e1759c21SAlexey Dobriyan 		K(cached),
12133806f06SShaohua Li 		K(total_swapcache_pages()),
122e1759c21SAlexey Dobriyan 		K(pages[LRU_ACTIVE_ANON]   + pages[LRU_ACTIVE_FILE]),
123e1759c21SAlexey Dobriyan 		K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
124e1759c21SAlexey Dobriyan 		K(pages[LRU_ACTIVE_ANON]),
125e1759c21SAlexey Dobriyan 		K(pages[LRU_INACTIVE_ANON]),
126e1759c21SAlexey Dobriyan 		K(pages[LRU_ACTIVE_FILE]),
127e1759c21SAlexey Dobriyan 		K(pages[LRU_INACTIVE_FILE]),
128e1759c21SAlexey Dobriyan 		K(pages[LRU_UNEVICTABLE]),
129e1759c21SAlexey Dobriyan 		K(global_page_state(NR_MLOCK)),
130e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM
131e1759c21SAlexey Dobriyan 		K(i.totalhigh),
132e1759c21SAlexey Dobriyan 		K(i.freehigh),
133e1759c21SAlexey Dobriyan 		K(i.totalram-i.totalhigh),
134e1759c21SAlexey Dobriyan 		K(i.freeram-i.freehigh),
135e1759c21SAlexey Dobriyan #endif
1368feae131SDavid Howells #ifndef CONFIG_MMU
13733e5d769SDavid Howells 		K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
1388feae131SDavid Howells #endif
139e1759c21SAlexey Dobriyan 		K(i.totalswap),
140e1759c21SAlexey Dobriyan 		K(i.freeswap),
14111fb9989SMel Gorman 		K(global_node_page_state(NR_FILE_DIRTY)),
14211fb9989SMel Gorman 		K(global_node_page_state(NR_WRITEBACK)),
1434b9d0fabSMel Gorman 		K(global_node_page_state(NR_ANON_MAPPED)),
14450658e2eSMel Gorman 		K(global_node_page_state(NR_FILE_MAPPED)),
145cc7452b6SRafael Aquini 		K(i.sharedram),
146e1759c21SAlexey Dobriyan 		K(global_page_state(NR_SLAB_RECLAIMABLE) +
147e1759c21SAlexey Dobriyan 				global_page_state(NR_SLAB_UNRECLAIMABLE)),
148e1759c21SAlexey Dobriyan 		K(global_page_state(NR_SLAB_RECLAIMABLE)),
149e1759c21SAlexey Dobriyan 		K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
150d30dd8beSAndy Lutomirski 		global_page_state(NR_KERNEL_STACK_KB),
151e1759c21SAlexey Dobriyan 		K(global_page_state(NR_PAGETABLE)),
152e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST
153e1759c21SAlexey Dobriyan 		K(quicklist_total_size()),
154e1759c21SAlexey Dobriyan #endif
15511fb9989SMel Gorman 		K(global_node_page_state(NR_UNSTABLE_NFS)),
156e1759c21SAlexey Dobriyan 		K(global_page_state(NR_BOUNCE)),
15711fb9989SMel Gorman 		K(global_node_page_state(NR_WRITEBACK_TEMP)),
15800619bccSJerome Marchand 		K(vm_commit_limit()),
159e1759c21SAlexey Dobriyan 		K(committed),
160e1759c21SAlexey Dobriyan 		(unsigned long)VMALLOC_TOTAL >> 10,
161a5ad88ceSLinus Torvalds 		0ul, // used to be vmalloc 'used'
162a5ad88ceSLinus Torvalds 		0ul  // used to be vmalloc 'largest_chunk'
1636a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
164293c07e3SXishi Qiu 		, atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
1656a46079cSAndi Kleen #endif
16679134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE
16711fb9989SMel Gorman 		, K(global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR)
16811fb9989SMel Gorman 		, K(global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR)
16911fb9989SMel Gorman 		, K(global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR)
17079134171SAndrea Arcangeli #endif
17147f8f929SPintu Kumar #ifdef CONFIG_CMA
17247f8f929SPintu Kumar 		, K(totalcma_pages)
17347f8f929SPintu Kumar 		, K(global_page_state(NR_FREE_CMA_PAGES))
17447f8f929SPintu Kumar #endif
175e1759c21SAlexey Dobriyan 		);
176e1759c21SAlexey Dobriyan 
177e1759c21SAlexey Dobriyan 	hugetlb_report_meminfo(m);
178e1759c21SAlexey Dobriyan 
179e1759c21SAlexey Dobriyan 	arch_report_meminfo(m);
180e1759c21SAlexey Dobriyan 
181e1759c21SAlexey Dobriyan 	return 0;
182e1759c21SAlexey Dobriyan #undef K
183e1759c21SAlexey Dobriyan }
184e1759c21SAlexey Dobriyan 
185e1759c21SAlexey Dobriyan static int meminfo_proc_open(struct inode *inode, struct file *file)
186e1759c21SAlexey Dobriyan {
187e1759c21SAlexey Dobriyan 	return single_open(file, meminfo_proc_show, NULL);
188e1759c21SAlexey Dobriyan }
189e1759c21SAlexey Dobriyan 
190e1759c21SAlexey Dobriyan static const struct file_operations meminfo_proc_fops = {
191e1759c21SAlexey Dobriyan 	.open		= meminfo_proc_open,
192e1759c21SAlexey Dobriyan 	.read		= seq_read,
193e1759c21SAlexey Dobriyan 	.llseek		= seq_lseek,
194e1759c21SAlexey Dobriyan 	.release	= single_release,
195e1759c21SAlexey Dobriyan };
196e1759c21SAlexey Dobriyan 
197e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void)
198e1759c21SAlexey Dobriyan {
199e1759c21SAlexey Dobriyan 	proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
200e1759c21SAlexey Dobriyan 	return 0;
201e1759c21SAlexey Dobriyan }
202abaf3787SPaul Gortmaker fs_initcall(proc_meminfo_init);
203