xref: /openbmc/linux/fs/proc/meminfo.c (revision c41f012ade0b95b0a6e25c7150673e0554736165)
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 
26e16e2d8eSJoe Perches static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
27e16e2d8eSJoe Perches {
28e16e2d8eSJoe Perches 	char v[32];
29e16e2d8eSJoe Perches 	static const char blanks[7] = {' ', ' ', ' ', ' ',' ', ' ', ' '};
30e16e2d8eSJoe Perches 	int len;
31e16e2d8eSJoe Perches 
32e16e2d8eSJoe Perches 	len = num_to_str(v, sizeof(v), num << (PAGE_SHIFT - 10));
33e16e2d8eSJoe Perches 
34e16e2d8eSJoe Perches 	seq_write(m, s, 16);
35e16e2d8eSJoe Perches 
36e16e2d8eSJoe Perches 	if (len > 0) {
37e16e2d8eSJoe Perches 		if (len < 8)
38e16e2d8eSJoe Perches 			seq_write(m, blanks, 8 - len);
39e16e2d8eSJoe Perches 
40e16e2d8eSJoe Perches 		seq_write(m, v, len);
41e16e2d8eSJoe Perches 	}
42e16e2d8eSJoe Perches 	seq_write(m, " kB\n", 4);
43e16e2d8eSJoe Perches }
44e16e2d8eSJoe Perches 
45e1759c21SAlexey Dobriyan static int meminfo_proc_show(struct seq_file *m, void *v)
46e1759c21SAlexey Dobriyan {
47e1759c21SAlexey Dobriyan 	struct sysinfo i;
48e1759c21SAlexey Dobriyan 	unsigned long committed;
49e1759c21SAlexey Dobriyan 	long cached;
5034e431b0SRik van Riel 	long available;
51e1759c21SAlexey Dobriyan 	unsigned long pages[NR_LRU_LISTS];
52e1759c21SAlexey Dobriyan 	int lru;
53e1759c21SAlexey Dobriyan 
54e1759c21SAlexey Dobriyan 	si_meminfo(&i);
55e1759c21SAlexey Dobriyan 	si_swapinfo(&i);
5600a62ce9SKOSAKI Motohiro 	committed = percpu_counter_read_positive(&vm_committed_as);
57e1759c21SAlexey Dobriyan 
5811fb9989SMel Gorman 	cached = global_node_page_state(NR_FILE_PAGES) -
5933806f06SShaohua Li 			total_swapcache_pages() - i.bufferram;
60e1759c21SAlexey Dobriyan 	if (cached < 0)
61e1759c21SAlexey Dobriyan 		cached = 0;
62e1759c21SAlexey Dobriyan 
63e1759c21SAlexey Dobriyan 	for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
642f95ff90SMel Gorman 		pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
65e1759c21SAlexey Dobriyan 
66d02bd27bSIgor Redko 	available = si_mem_available();
6734e431b0SRik van Riel 
68e16e2d8eSJoe Perches 	show_val_kb(m, "MemTotal:       ", i.totalram);
69e16e2d8eSJoe Perches 	show_val_kb(m, "MemFree:        ", i.freeram);
70e16e2d8eSJoe Perches 	show_val_kb(m, "MemAvailable:   ", available);
71e16e2d8eSJoe Perches 	show_val_kb(m, "Buffers:        ", i.bufferram);
72e16e2d8eSJoe Perches 	show_val_kb(m, "Cached:         ", cached);
73e16e2d8eSJoe Perches 	show_val_kb(m, "SwapCached:     ", total_swapcache_pages());
74e16e2d8eSJoe Perches 	show_val_kb(m, "Active:         ", pages[LRU_ACTIVE_ANON] +
75e16e2d8eSJoe Perches 					   pages[LRU_ACTIVE_FILE]);
76e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive:       ", pages[LRU_INACTIVE_ANON] +
77e16e2d8eSJoe Perches 					   pages[LRU_INACTIVE_FILE]);
78e16e2d8eSJoe Perches 	show_val_kb(m, "Active(anon):   ", pages[LRU_ACTIVE_ANON]);
79e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]);
80e16e2d8eSJoe Perches 	show_val_kb(m, "Active(file):   ", pages[LRU_ACTIVE_FILE]);
81e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]);
82e16e2d8eSJoe Perches 	show_val_kb(m, "Unevictable:    ", pages[LRU_UNEVICTABLE]);
83*c41f012aSMichal Hocko 	show_val_kb(m, "Mlocked:        ", global_zone_page_state(NR_MLOCK));
84e16e2d8eSJoe Perches 
85e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM
86e16e2d8eSJoe Perches 	show_val_kb(m, "HighTotal:      ", i.totalhigh);
87e16e2d8eSJoe Perches 	show_val_kb(m, "HighFree:       ", i.freehigh);
88e16e2d8eSJoe Perches 	show_val_kb(m, "LowTotal:       ", i.totalram - i.totalhigh);
89e16e2d8eSJoe Perches 	show_val_kb(m, "LowFree:        ", i.freeram - i.freehigh);
90e1759c21SAlexey Dobriyan #endif
91e16e2d8eSJoe Perches 
928feae131SDavid Howells #ifndef CONFIG_MMU
93e16e2d8eSJoe Perches 	show_val_kb(m, "MmapCopy:       ",
94e16e2d8eSJoe Perches 		    (unsigned long)atomic_long_read(&mmap_pages_allocated));
958feae131SDavid Howells #endif
96e16e2d8eSJoe Perches 
97e16e2d8eSJoe Perches 	show_val_kb(m, "SwapTotal:      ", i.totalswap);
98e16e2d8eSJoe Perches 	show_val_kb(m, "SwapFree:       ", i.freeswap);
99e16e2d8eSJoe Perches 	show_val_kb(m, "Dirty:          ",
100e16e2d8eSJoe Perches 		    global_node_page_state(NR_FILE_DIRTY));
101e16e2d8eSJoe Perches 	show_val_kb(m, "Writeback:      ",
102e16e2d8eSJoe Perches 		    global_node_page_state(NR_WRITEBACK));
103e16e2d8eSJoe Perches 	show_val_kb(m, "AnonPages:      ",
104e16e2d8eSJoe Perches 		    global_node_page_state(NR_ANON_MAPPED));
105e16e2d8eSJoe Perches 	show_val_kb(m, "Mapped:         ",
106e16e2d8eSJoe Perches 		    global_node_page_state(NR_FILE_MAPPED));
107e16e2d8eSJoe Perches 	show_val_kb(m, "Shmem:          ", i.sharedram);
108e16e2d8eSJoe Perches 	show_val_kb(m, "Slab:           ",
109d507e2ebSJohannes Weiner 		    global_node_page_state(NR_SLAB_RECLAIMABLE) +
110d507e2ebSJohannes Weiner 		    global_node_page_state(NR_SLAB_UNRECLAIMABLE));
111e16e2d8eSJoe Perches 
112e16e2d8eSJoe Perches 	show_val_kb(m, "SReclaimable:   ",
113d507e2ebSJohannes Weiner 		    global_node_page_state(NR_SLAB_RECLAIMABLE));
114e16e2d8eSJoe Perches 	show_val_kb(m, "SUnreclaim:     ",
115d507e2ebSJohannes Weiner 		    global_node_page_state(NR_SLAB_UNRECLAIMABLE));
116e16e2d8eSJoe Perches 	seq_printf(m, "KernelStack:    %8lu kB\n",
117*c41f012aSMichal Hocko 		   global_zone_page_state(NR_KERNEL_STACK_KB));
118e16e2d8eSJoe Perches 	show_val_kb(m, "PageTables:     ",
119*c41f012aSMichal Hocko 		    global_zone_page_state(NR_PAGETABLE));
120e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST
121e16e2d8eSJoe Perches 	show_val_kb(m, "Quicklists:     ", quicklist_total_size());
122e1759c21SAlexey Dobriyan #endif
123e16e2d8eSJoe Perches 
124e16e2d8eSJoe Perches 	show_val_kb(m, "NFS_Unstable:   ",
125e16e2d8eSJoe Perches 		    global_node_page_state(NR_UNSTABLE_NFS));
126e16e2d8eSJoe Perches 	show_val_kb(m, "Bounce:         ",
127*c41f012aSMichal Hocko 		    global_zone_page_state(NR_BOUNCE));
128e16e2d8eSJoe Perches 	show_val_kb(m, "WritebackTmp:   ",
129e16e2d8eSJoe Perches 		    global_node_page_state(NR_WRITEBACK_TEMP));
130e16e2d8eSJoe Perches 	show_val_kb(m, "CommitLimit:    ", vm_commit_limit());
131e16e2d8eSJoe Perches 	show_val_kb(m, "Committed_AS:   ", committed);
132e16e2d8eSJoe Perches 	seq_printf(m, "VmallocTotal:   %8lu kB\n",
133e16e2d8eSJoe Perches 		   (unsigned long)VMALLOC_TOTAL >> 10);
134e16e2d8eSJoe Perches 	show_val_kb(m, "VmallocUsed:    ", 0ul);
135e16e2d8eSJoe Perches 	show_val_kb(m, "VmallocChunk:   ", 0ul);
136e16e2d8eSJoe Perches 
1376a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
138e16e2d8eSJoe Perches 	seq_printf(m, "HardwareCorrupted: %5lu kB\n",
139e16e2d8eSJoe Perches 		   atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10));
1406a46079cSAndi Kleen #endif
141e16e2d8eSJoe Perches 
14279134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE
143e16e2d8eSJoe Perches 	show_val_kb(m, "AnonHugePages:  ",
144e16e2d8eSJoe Perches 		    global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR);
145e16e2d8eSJoe Perches 	show_val_kb(m, "ShmemHugePages: ",
146e16e2d8eSJoe Perches 		    global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);
147e16e2d8eSJoe Perches 	show_val_kb(m, "ShmemPmdMapped: ",
148e16e2d8eSJoe Perches 		    global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
14979134171SAndrea Arcangeli #endif
150e16e2d8eSJoe Perches 
15147f8f929SPintu Kumar #ifdef CONFIG_CMA
152e16e2d8eSJoe Perches 	show_val_kb(m, "CmaTotal:       ", totalcma_pages);
153e16e2d8eSJoe Perches 	show_val_kb(m, "CmaFree:        ",
154*c41f012aSMichal Hocko 		    global_zone_page_state(NR_FREE_CMA_PAGES));
15547f8f929SPintu Kumar #endif
156e1759c21SAlexey Dobriyan 
157e1759c21SAlexey Dobriyan 	hugetlb_report_meminfo(m);
158e1759c21SAlexey Dobriyan 
159e1759c21SAlexey Dobriyan 	arch_report_meminfo(m);
160e1759c21SAlexey Dobriyan 
161e1759c21SAlexey Dobriyan 	return 0;
162e1759c21SAlexey Dobriyan }
163e1759c21SAlexey Dobriyan 
164e1759c21SAlexey Dobriyan static int meminfo_proc_open(struct inode *inode, struct file *file)
165e1759c21SAlexey Dobriyan {
166e1759c21SAlexey Dobriyan 	return single_open(file, meminfo_proc_show, NULL);
167e1759c21SAlexey Dobriyan }
168e1759c21SAlexey Dobriyan 
169e1759c21SAlexey Dobriyan static const struct file_operations meminfo_proc_fops = {
170e1759c21SAlexey Dobriyan 	.open		= meminfo_proc_open,
171e1759c21SAlexey Dobriyan 	.read		= seq_read,
172e1759c21SAlexey Dobriyan 	.llseek		= seq_lseek,
173e1759c21SAlexey Dobriyan 	.release	= single_release,
174e1759c21SAlexey Dobriyan };
175e1759c21SAlexey Dobriyan 
176e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void)
177e1759c21SAlexey Dobriyan {
178e1759c21SAlexey Dobriyan 	proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
179e1759c21SAlexey Dobriyan 	return 0;
180e1759c21SAlexey Dobriyan }
181abaf3787SPaul Gortmaker fs_initcall(proc_meminfo_init);
182