blob: 7643dc1c94ae0a1ba7f08f1fb9acaea38fa69848 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <linux/fs.h>
2#include <linux/hugetlb.h>
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/mm.h>
6#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>
13#include <linux/atomic.h>
14#include <asm/page.h>
15#include <asm/pgtable.h>
16#include "internal.h"
17
18extern unsigned long pagecache_alloc_failed;
19
20void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
21{
22}
23extern atomic_t _code_page_count;
24static int meminfo_proc_show(struct seq_file *m, void *v)
25{
26 struct sysinfo i;
27 unsigned long committed;
28 unsigned long allowed;
29 struct vmalloc_info vmi;
30 long cached;
31 unsigned long pages[NR_LRU_LISTS];
32 int lru;
33#ifdef CONFIG_LIMIT_PAGE_CACHE
34 struct zone *zone;
35 unsigned long max_pagecache = 0;
36#endif
37
38/*
39 * display in kilobytes.
40 */
41#define K(x) ((x) << (PAGE_SHIFT - 10))
42 si_meminfo(&i);
43 si_swapinfo(&i);
44 committed = percpu_counter_read_positive(&vm_committed_as);
45 allowed = ((totalram_pages - hugetlb_total_pages())
46 * sysctl_overcommit_ratio / 100) + total_swap_pages;
47
48#ifdef CONFIG_LIMIT_PAGE_CACHE
49 cached = global_page_state(NR_FILE_PAGES) - i.bufferram;
50#else
51 cached = global_page_state(NR_FILE_PAGES) -
52 total_swapcache_pages - i.bufferram;
53#endif
54 if (cached < 0)
55 cached = 0;
56
57 get_vmalloc_info(&vmi);
58
59 for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
60 pages[lru] = global_page_state(NR_LRU_BASE + lru);
61
62#ifdef CONFIG_LIMIT_PAGE_CACHE
63 for_each_zone(zone)
64 max_pagecache += zone->max_pagecache_pages;
65#endif
66
67 /*
68 * Tagged format, for easy grepping and expansion.
69 */
70 seq_printf(m,
71 "MemTotal: %8lu kB\n"
72 "MemFree: %8lu kB\n"
73 "Buffers: %8lu kB\n"
74 "Cached: %8lu kB\n"
75 "SwapCached: %8lu kB\n"
76#ifdef CONFIG_LIMIT_PAGE_CACHE
77 "RAMFS: %8lu kB\n"
78 "TMPFS: %8lu kB\n"
79#endif
80 "Active: %8lu kB\n"
81 "Inactive: %8lu kB\n"
82 "Active(anon): %8lu kB\n"
83 "Inactive(anon): %8lu kB\n"
84 "Active(file): %8lu kB\n"
85 "Inactive(file): %8lu kB\n"
86 "Unevictable: %8lu kB\n"
87 "Mlocked: %8lu kB\n"
88#ifdef CONFIG_HIGHMEM
89 "HighTotal: %8lu kB\n"
90 "HighFree: %8lu kB\n"
91 "LowTotal: %8lu kB\n"
92 "LowFree: %8lu kB\n"
93#endif
94#ifndef CONFIG_MMU
95 "MmapCopy: %8lu kB\n"
96#endif
97 "SwapTotal: %8lu kB\n"
98 "SwapFree: %8lu kB\n"
99 "Dirty: %8lu kB\n"
100 "Writeback: %8lu kB\n"
101 "AnonPages: %8lu kB\n"
102 "Mapped: %8lu kB\n"
103 "Shmem: %8lu kB\n"
104 "Slab: %8lu kB\n"
105 "SReclaimable: %8lu kB\n"
106 "SUnreclaim: %8lu kB\n"
107 "KernelStack: %8lu kB\n"
108 "PageTables: %8lu kB\n"
109#ifdef CONFIG_QUICKLIST
110 "Quicklists: %8lu kB\n"
111#endif
112 "NFS_Unstable: %8lu kB\n"
113 "Bounce: %8lu kB\n"
114 "WritebackTmp: %8lu kB\n"
115 "CommitLimit: %8lu kB\n"
116 "Committed_AS: %8lu kB\n"
117 "VmallocTotal: %8lu kB\n"
118 "VmallocUsed: %8lu kB\n"
119 "VmallocChunk: %8lu kB\n"
120#ifdef CONFIG_MODEM_CODE_IS_MAPPING
121 "CodeMemTotal: %8lu kB\n"
122#endif
123#ifdef CONFIG_MEMORY_FAILURE
124 "HardwareCorrupted: %5lu kB\n"
125#endif
126#ifdef CONFIG_TRANSPARENT_HUGEPAGE
127 "AnonHugePages: %8lu kB\n"
128#endif
129#ifdef CONFIG_LIMIT_PAGE_CACHE
130 "MaxPageCache: %8lu kB\n"
131 "AllocFailed: %8lu\n"
132#endif
133 ,
134 K(i.totalram),
135 K(i.freeram),
136 K(i.bufferram),
137 K(cached),
138 K(total_swapcache_pages),
139#ifdef CONFIG_LIMIT_PAGE_CACHE
140 K(global_page_state(NR_RAMFS_PAGES)),
141 K(global_page_state(NR_TMPFS_PAGES)),
142#endif
143 K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
144 K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
145 K(pages[LRU_ACTIVE_ANON]),
146 K(pages[LRU_INACTIVE_ANON]),
147 K(pages[LRU_ACTIVE_FILE]),
148 K(pages[LRU_INACTIVE_FILE]),
149 K(pages[LRU_UNEVICTABLE]),
150 K(global_page_state(NR_MLOCK)),
151#ifdef CONFIG_HIGHMEM
152 K(i.totalhigh),
153 K(i.freehigh),
154 K(i.totalram-i.totalhigh),
155 K(i.freeram-i.freehigh),
156#endif
157#ifndef CONFIG_MMU
158 K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
159#endif
160 K(i.totalswap),
161 K(i.freeswap),
162 K(global_page_state(NR_FILE_DIRTY)),
163 K(global_page_state(NR_WRITEBACK)),
164#ifdef CONFIG_TRANSPARENT_HUGEPAGE
165 K(global_page_state(NR_ANON_PAGES)
166 + global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
167 HPAGE_PMD_NR),
168#else
169 K(global_page_state(NR_ANON_PAGES)),
170#endif
171 K(global_page_state(NR_FILE_MAPPED)),
172 K(global_page_state(NR_SHMEM)),
173 K(global_page_state(NR_SLAB_RECLAIMABLE) +
174 global_page_state(NR_SLAB_UNRECLAIMABLE)),
175 K(global_page_state(NR_SLAB_RECLAIMABLE)),
176 K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
177 global_page_state(NR_KERNEL_STACK) * THREAD_SIZE / 1024,
178 K(global_page_state(NR_PAGETABLE)),
179#ifdef CONFIG_QUICKLIST
180 K(quicklist_total_size()),
181#endif
182 K(global_page_state(NR_UNSTABLE_NFS)),
183 K(global_page_state(NR_BOUNCE)),
184 K(global_page_state(NR_WRITEBACK_TEMP)),
185 K(allowed),
186 K(committed),
187 (unsigned long)VMALLOC_TOTAL >> 10,
188 vmi.used >> 10,
189 vmi.largest_chunk >> 10
190#ifdef CONFIG_MODEM_CODE_IS_MAPPING
191 ,_code_page_count.counter << 2
192#endif
193#ifdef CONFIG_MEMORY_FAILURE
194 ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
195#endif
196#ifdef CONFIG_TRANSPARENT_HUGEPAGE
197 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
198 HPAGE_PMD_NR)
199#endif
200#ifdef CONFIG_LIMIT_PAGE_CACHE
201 , K(max_pagecache)
202 , pagecache_alloc_failed
203#endif
204 );
205
206#ifdef CONFIG_LIMIT_PAGE_CACHE
207 for_each_zone(zone)
208 seq_printf(m, "cached for zone(%s): %d\n", zone->name, zone_page_state(zone, NR_FILE_PAGES));
209#endif
210
211 hugetlb_report_meminfo(m);
212
213 arch_report_meminfo(m);
214
215 return 0;
216#undef K
217}
218
219static int meminfo_proc_open(struct inode *inode, struct file *file)
220{
221 return single_open(file, meminfo_proc_show, NULL);
222}
223
224static const struct file_operations meminfo_proc_fops = {
225 .open = meminfo_proc_open,
226 .read = seq_read,
227 .llseek = seq_lseek,
228 .release = single_release,
229};
230
231static int __init proc_meminfo_init(void)
232{
233 proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
234 return 0;
235}
236module_init(proc_meminfo_init);