• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/fs.h>
3 #include <linux/init.h>
4 #include <linux/kernel.h>
5 #include <linux/mm.h>
6 #include <linux/hugetlb.h>
7 #include <linux/mman.h>
8 #include <linux/mmzone.h>
9 #include <linux/proc_fs.h>
10 #include <linux/percpu.h>
11 #include <linux/seq_file.h>
12 #include <linux/swap.h>
13 #include <linux/vmstat.h>
14 #include <linux/atomic.h>
15 #include <linux/vmalloc.h>
16 #ifdef CONFIG_CMA
17 #include <linux/cma.h>
18 #endif
19 #ifdef CONFIG_MEM_PURGEABLE
20 #include <linux/mm_purgeable.h>
21 #endif
22 #include <asm/page.h>
23 #include "internal.h"
24 
arch_report_meminfo(struct seq_file * m)25 void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
26 {
27 }
28 
show_val_kb(struct seq_file * m,const char * s,unsigned long num)29 static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
30 {
31 	seq_put_decimal_ull_width(m, s, num << (PAGE_SHIFT - 10), 8);
32 	seq_write(m, " kB\n", 4);
33 }
34 
meminfo_proc_show(struct seq_file * m,void * v)35 static int meminfo_proc_show(struct seq_file *m, void *v)
36 {
37 	struct sysinfo i;
38 	unsigned long committed;
39 	long cached;
40 	long available;
41 	unsigned long pages[NR_LRU_LISTS];
42 	unsigned long sreclaimable, sunreclaim;
43 	int lru;
44 	unsigned long nr_purg_active = 0;
45 	unsigned long nr_purg_inactive = 0;
46 #ifdef CONFIG_MEM_PURGEABLE
47 	unsigned long nr_purg_pined = 0;
48 #endif
49 
50 	si_meminfo(&i);
51 	si_swapinfo(&i);
52 	committed = vm_memory_committed();
53 
54 	cached = global_node_page_state(NR_FILE_PAGES) -
55 			total_swapcache_pages() - i.bufferram;
56 	if (cached < 0)
57 		cached = 0;
58 
59 	for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
60 		pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
61 
62 #ifdef CONFIG_MEM_PURGEABLE
63 	nr_purg_active = pages[LRU_ACTIVE_PURGEABLE];
64 	nr_purg_inactive = pages[LRU_INACTIVE_PURGEABLE];
65 	purg_pages_info(NULL, &nr_purg_pined);
66 	nr_purg_pined = min(nr_purg_pined, nr_purg_active + nr_purg_inactive);
67 #endif
68 
69 	available = si_mem_available();
70 	sreclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B);
71 	sunreclaim = global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B);
72 
73 	show_val_kb(m, "MemTotal:       ", i.totalram);
74 	show_val_kb(m, "MemFree:        ", i.freeram);
75 	show_val_kb(m, "MemAvailable:   ", available);
76 	show_val_kb(m, "Buffers:        ", i.bufferram);
77 	show_val_kb(m, "Cached:         ", cached);
78 	show_val_kb(m, "SwapCached:     ", total_swapcache_pages());
79 	show_val_kb(m, "Active:         ", pages[LRU_ACTIVE_ANON] +
80 					   pages[LRU_ACTIVE_FILE] +
81 					   nr_purg_active);
82 	show_val_kb(m, "Inactive:       ", pages[LRU_INACTIVE_ANON] +
83 					   pages[LRU_INACTIVE_FILE] +
84 					   nr_purg_inactive);
85 	show_val_kb(m, "Active(anon):   ", pages[LRU_ACTIVE_ANON]);
86 	show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]);
87 	show_val_kb(m, "Active(file):   ", pages[LRU_ACTIVE_FILE]);
88 	show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]);
89 #ifdef CONFIG_MEM_PURGEABLE
90 	show_val_kb(m, "Active(purg):   ", nr_purg_active);
91 	show_val_kb(m, "Inactive(purg): ", nr_purg_inactive);
92 	show_val_kb(m, "Pined(purg):    ", nr_purg_pined);
93 #endif
94 	show_val_kb(m, "Unevictable:    ", pages[LRU_UNEVICTABLE]);
95 	show_val_kb(m, "Mlocked:        ", global_zone_page_state(NR_MLOCK));
96 
97 #ifdef CONFIG_HIGHMEM
98 	show_val_kb(m, "HighTotal:      ", i.totalhigh);
99 	show_val_kb(m, "HighFree:       ", i.freehigh);
100 	show_val_kb(m, "LowTotal:       ", i.totalram - i.totalhigh);
101 	show_val_kb(m, "LowFree:        ", i.freeram - i.freehigh);
102 #endif
103 
104 #ifndef CONFIG_MMU
105 	show_val_kb(m, "MmapCopy:       ",
106 		    (unsigned long)atomic_long_read(&mmap_pages_allocated));
107 #endif
108 
109 	show_val_kb(m, "SwapTotal:      ", i.totalswap);
110 	show_val_kb(m, "SwapFree:       ", i.freeswap);
111 	show_val_kb(m, "Dirty:          ",
112 		    global_node_page_state(NR_FILE_DIRTY));
113 	show_val_kb(m, "Writeback:      ",
114 		    global_node_page_state(NR_WRITEBACK));
115 	show_val_kb(m, "AnonPages:      ",
116 		    global_node_page_state(NR_ANON_MAPPED));
117 	show_val_kb(m, "Mapped:         ",
118 		    global_node_page_state(NR_FILE_MAPPED));
119 	show_val_kb(m, "Shmem:          ", i.sharedram);
120 	show_val_kb(m, "KReclaimable:   ", sreclaimable +
121 		    global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE));
122 	show_val_kb(m, "Slab:           ", sreclaimable + sunreclaim);
123 	show_val_kb(m, "SReclaimable:   ", sreclaimable);
124 	show_val_kb(m, "SUnreclaim:     ", sunreclaim);
125 	seq_printf(m, "KernelStack:    %8lu kB\n",
126 		   global_node_page_state(NR_KERNEL_STACK_KB));
127 #ifdef CONFIG_SHADOW_CALL_STACK
128 	seq_printf(m, "ShadowCallStack:%8lu kB\n",
129 		   global_node_page_state(NR_KERNEL_SCS_KB));
130 #endif
131 	show_val_kb(m, "PageTables:     ",
132 		    global_zone_page_state(NR_PAGETABLE));
133 
134 	show_val_kb(m, "NFS_Unstable:   ", 0);
135 	show_val_kb(m, "Bounce:         ",
136 		    global_zone_page_state(NR_BOUNCE));
137 	show_val_kb(m, "WritebackTmp:   ",
138 		    global_node_page_state(NR_WRITEBACK_TEMP));
139 	show_val_kb(m, "CommitLimit:    ", vm_commit_limit());
140 	show_val_kb(m, "Committed_AS:   ", committed);
141 	seq_printf(m, "VmallocTotal:   %8lu kB\n",
142 		   (unsigned long)VMALLOC_TOTAL >> 10);
143 	show_val_kb(m, "VmallocUsed:    ", vmalloc_nr_pages());
144 	show_val_kb(m, "VmallocChunk:   ", 0ul);
145 	show_val_kb(m, "Percpu:         ", pcpu_nr_pages());
146 
147 #ifdef CONFIG_PAGE_TRACING
148 	show_val_kb(m, "Skb:            ", global_zone_page_state(NR_SKB_PAGES));
149 #endif
150 
151 #ifdef CONFIG_MEMORY_FAILURE
152 	seq_printf(m, "HardwareCorrupted: %5lu kB\n",
153 		   atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10));
154 #endif
155 
156 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
157 	show_val_kb(m, "AnonHugePages:  ",
158 		    global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR);
159 	show_val_kb(m, "ShmemHugePages: ",
160 		    global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);
161 	show_val_kb(m, "ShmemPmdMapped: ",
162 		    global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
163 	show_val_kb(m, "FileHugePages:  ",
164 		    global_node_page_state(NR_FILE_THPS) * HPAGE_PMD_NR);
165 	show_val_kb(m, "FilePmdMapped:  ",
166 		    global_node_page_state(NR_FILE_PMDMAPPED) * HPAGE_PMD_NR);
167 #endif
168 
169 #ifdef CONFIG_CMA
170 	show_val_kb(m, "CmaTotal:       ", totalcma_pages);
171 	show_val_kb(m, "CmaFree:        ",
172 		    global_zone_page_state(NR_FREE_CMA_PAGES));
173 #endif
174 
175 #ifdef CONFIG_PAGE_TRACING
176 	seq_puts(m, "GLTrack:               - kB\n");
177 	show_val_kb(m, "ZspageUsed:	", global_zone_page_state(NR_ZSPAGES));
178 #endif
179 
180 	hugetlb_report_meminfo(m);
181 
182 	arch_report_meminfo(m);
183 
184 	return 0;
185 }
186 
proc_meminfo_init(void)187 static int __init proc_meminfo_init(void)
188 {
189 	proc_create_single("meminfo", 0, NULL, meminfo_proc_show);
190 	return 0;
191 }
192 fs_initcall(proc_meminfo_init);
193