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