xref: /openbmc/linux/fs/proc/meminfo.c (revision e16e2d8e14a14bd87df8482c637dde8f760a8d5f)
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 
26*e16e2d8eSJoe Perches static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
27*e16e2d8eSJoe Perches {
28*e16e2d8eSJoe Perches 	char v[32];
29*e16e2d8eSJoe Perches 	static const char blanks[7] = {' ', ' ', ' ', ' ',' ', ' ', ' '};
30*e16e2d8eSJoe Perches 	int len;
31*e16e2d8eSJoe Perches 
32*e16e2d8eSJoe Perches 	len = num_to_str(v, sizeof(v), num << (PAGE_SHIFT - 10));
33*e16e2d8eSJoe Perches 
34*e16e2d8eSJoe Perches 	seq_write(m, s, 16);
35*e16e2d8eSJoe Perches 
36*e16e2d8eSJoe Perches 	if (len > 0) {
37*e16e2d8eSJoe Perches 		if (len < 8)
38*e16e2d8eSJoe Perches 			seq_write(m, blanks, 8 - len);
39*e16e2d8eSJoe Perches 
40*e16e2d8eSJoe Perches 		seq_write(m, v, len);
41*e16e2d8eSJoe Perches 	}
42*e16e2d8eSJoe Perches 	seq_write(m, " kB\n", 4);
43*e16e2d8eSJoe Perches }
44*e16e2d8eSJoe 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 
68*e16e2d8eSJoe Perches 	show_val_kb(m, "MemTotal:       ", i.totalram);
69*e16e2d8eSJoe Perches 	show_val_kb(m, "MemFree:        ", i.freeram);
70*e16e2d8eSJoe Perches 	show_val_kb(m, "MemAvailable:   ", available);
71*e16e2d8eSJoe Perches 	show_val_kb(m, "Buffers:        ", i.bufferram);
72*e16e2d8eSJoe Perches 	show_val_kb(m, "Cached:         ", cached);
73*e16e2d8eSJoe Perches 	show_val_kb(m, "SwapCached:     ", total_swapcache_pages());
74*e16e2d8eSJoe Perches 	show_val_kb(m, "Active:         ", pages[LRU_ACTIVE_ANON] +
75*e16e2d8eSJoe Perches 					   pages[LRU_ACTIVE_FILE]);
76*e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive:       ", pages[LRU_INACTIVE_ANON] +
77*e16e2d8eSJoe Perches 					   pages[LRU_INACTIVE_FILE]);
78*e16e2d8eSJoe Perches 	show_val_kb(m, "Active(anon):   ", pages[LRU_ACTIVE_ANON]);
79*e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]);
80*e16e2d8eSJoe Perches 	show_val_kb(m, "Active(file):   ", pages[LRU_ACTIVE_FILE]);
81*e16e2d8eSJoe Perches 	show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]);
82*e16e2d8eSJoe Perches 	show_val_kb(m, "Unevictable:    ", pages[LRU_UNEVICTABLE]);
83*e16e2d8eSJoe Perches 	show_val_kb(m, "Mlocked:        ", global_page_state(NR_MLOCK));
84*e16e2d8eSJoe Perches 
85e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM
86*e16e2d8eSJoe Perches 	show_val_kb(m, "HighTotal:      ", i.totalhigh);
87*e16e2d8eSJoe Perches 	show_val_kb(m, "HighFree:       ", i.freehigh);
88*e16e2d8eSJoe Perches 	show_val_kb(m, "LowTotal:       ", i.totalram - i.totalhigh);
89*e16e2d8eSJoe Perches 	show_val_kb(m, "LowFree:        ", i.freeram - i.freehigh);
90e1759c21SAlexey Dobriyan #endif
91*e16e2d8eSJoe Perches 
928feae131SDavid Howells #ifndef CONFIG_MMU
93*e16e2d8eSJoe Perches 	show_val_kb(m, "MmapCopy:       ",
94*e16e2d8eSJoe Perches 		    (unsigned long)atomic_long_read(&mmap_pages_allocated));
958feae131SDavid Howells #endif
96*e16e2d8eSJoe Perches 
97*e16e2d8eSJoe Perches 	show_val_kb(m, "SwapTotal:      ", i.totalswap);
98*e16e2d8eSJoe Perches 	show_val_kb(m, "SwapFree:       ", i.freeswap);
99*e16e2d8eSJoe Perches 	show_val_kb(m, "Dirty:          ",
100*e16e2d8eSJoe Perches 		    global_node_page_state(NR_FILE_DIRTY));
101*e16e2d8eSJoe Perches 	show_val_kb(m, "Writeback:      ",
102*e16e2d8eSJoe Perches 		    global_node_page_state(NR_WRITEBACK));
103*e16e2d8eSJoe Perches 	show_val_kb(m, "AnonPages:      ",
104*e16e2d8eSJoe Perches 		    global_node_page_state(NR_ANON_MAPPED));
105*e16e2d8eSJoe Perches 	show_val_kb(m, "Mapped:         ",
106*e16e2d8eSJoe Perches 		    global_node_page_state(NR_FILE_MAPPED));
107*e16e2d8eSJoe Perches 	show_val_kb(m, "Shmem:          ", i.sharedram);
108*e16e2d8eSJoe Perches 	show_val_kb(m, "Slab:           ",
109*e16e2d8eSJoe Perches 		    global_page_state(NR_SLAB_RECLAIMABLE) +
110*e16e2d8eSJoe Perches 		    global_page_state(NR_SLAB_UNRECLAIMABLE));
111*e16e2d8eSJoe Perches 
112*e16e2d8eSJoe Perches 	show_val_kb(m, "SReclaimable:   ",
113*e16e2d8eSJoe Perches 		    global_page_state(NR_SLAB_RECLAIMABLE));
114*e16e2d8eSJoe Perches 	show_val_kb(m, "SUnreclaim:     ",
115*e16e2d8eSJoe Perches 		    global_page_state(NR_SLAB_UNRECLAIMABLE));
116*e16e2d8eSJoe Perches 	seq_printf(m, "KernelStack:    %8lu kB\n",
117*e16e2d8eSJoe Perches 		   global_page_state(NR_KERNEL_STACK_KB));
118*e16e2d8eSJoe Perches 	show_val_kb(m, "PageTables:     ",
119*e16e2d8eSJoe Perches 		    global_page_state(NR_PAGETABLE));
120e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST
121*e16e2d8eSJoe Perches 	show_val_kb(m, "Quicklists:     ", quicklist_total_size());
122e1759c21SAlexey Dobriyan #endif
123*e16e2d8eSJoe Perches 
124*e16e2d8eSJoe Perches 	show_val_kb(m, "NFS_Unstable:   ",
125*e16e2d8eSJoe Perches 		    global_node_page_state(NR_UNSTABLE_NFS));
126*e16e2d8eSJoe Perches 	show_val_kb(m, "Bounce:         ",
127*e16e2d8eSJoe Perches 		    global_page_state(NR_BOUNCE));
128*e16e2d8eSJoe Perches 	show_val_kb(m, "WritebackTmp:   ",
129*e16e2d8eSJoe Perches 		    global_node_page_state(NR_WRITEBACK_TEMP));
130*e16e2d8eSJoe Perches 	show_val_kb(m, "CommitLimit:    ", vm_commit_limit());
131*e16e2d8eSJoe Perches 	show_val_kb(m, "Committed_AS:   ", committed);
132*e16e2d8eSJoe Perches 	seq_printf(m, "VmallocTotal:   %8lu kB\n",
133*e16e2d8eSJoe Perches 		   (unsigned long)VMALLOC_TOTAL >> 10);
134*e16e2d8eSJoe Perches 	show_val_kb(m, "VmallocUsed:    ", 0ul);
135*e16e2d8eSJoe Perches 	show_val_kb(m, "VmallocChunk:   ", 0ul);
136*e16e2d8eSJoe Perches 
1376a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
138*e16e2d8eSJoe Perches 	seq_printf(m, "HardwareCorrupted: %5lu kB\n",
139*e16e2d8eSJoe Perches 		   atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10));
1406a46079cSAndi Kleen #endif
141*e16e2d8eSJoe Perches 
14279134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE
143*e16e2d8eSJoe Perches 	show_val_kb(m, "AnonHugePages:  ",
144*e16e2d8eSJoe Perches 		    global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR);
145*e16e2d8eSJoe Perches 	show_val_kb(m, "ShmemHugePages: ",
146*e16e2d8eSJoe Perches 		    global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);
147*e16e2d8eSJoe Perches 	show_val_kb(m, "ShmemPmdMapped: ",
148*e16e2d8eSJoe Perches 		    global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
14979134171SAndrea Arcangeli #endif
150*e16e2d8eSJoe Perches 
15147f8f929SPintu Kumar #ifdef CONFIG_CMA
152*e16e2d8eSJoe Perches 	show_val_kb(m, "CmaTotal:       ", totalcma_pages);
153*e16e2d8eSJoe Perches 	show_val_kb(m, "CmaFree:        ",
154*e16e2d8eSJoe Perches 		    global_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