1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2e1759c21SAlexey Dobriyan #include <linux/fs.h> 3e1759c21SAlexey Dobriyan #include <linux/init.h> 4e1759c21SAlexey Dobriyan #include <linux/kernel.h> 5e1759c21SAlexey Dobriyan #include <linux/mm.h> 6cb900f41SKirill A. Shutemov #include <linux/hugetlb.h> 7e1759c21SAlexey Dobriyan #include <linux/mman.h> 8e1759c21SAlexey Dobriyan #include <linux/mmzone.h> 9*bd23024bSTomas Mudrunka #include <linux/memblock.h> 10e1759c21SAlexey Dobriyan #include <linux/proc_fs.h> 117e8a6304SDennis Zhou (Facebook) #include <linux/percpu.h> 12e1759c21SAlexey Dobriyan #include <linux/seq_file.h> 13e1759c21SAlexey Dobriyan #include <linux/swap.h> 14e1759c21SAlexey Dobriyan #include <linux/vmstat.h> 1560063497SArun Sharma #include <linux/atomic.h> 16db3808c1SJoonsoo Kim #include <linux/vmalloc.h> 1747f8f929SPintu Kumar #ifdef CONFIG_CMA 1847f8f929SPintu Kumar #include <linux/cma.h> 1947f8f929SPintu Kumar #endif 20e1759c21SAlexey Dobriyan #include <asm/page.h> 21e1759c21SAlexey Dobriyan #include "internal.h" 22e1759c21SAlexey Dobriyan 23e1759c21SAlexey Dobriyan void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) 24e1759c21SAlexey Dobriyan { 25e1759c21SAlexey Dobriyan } 26e1759c21SAlexey Dobriyan 27e16e2d8eSJoe Perches static void show_val_kb(struct seq_file *m, const char *s, unsigned long num) 28e16e2d8eSJoe Perches { 29d1be35cbSAndrei Vagin seq_put_decimal_ull_width(m, s, num << (PAGE_SHIFT - 10), 8); 30e16e2d8eSJoe Perches seq_write(m, " kB\n", 4); 31e16e2d8eSJoe Perches } 32e16e2d8eSJoe Perches 33e1759c21SAlexey Dobriyan static int meminfo_proc_show(struct seq_file *m, void *v) 34e1759c21SAlexey Dobriyan { 35e1759c21SAlexey Dobriyan struct sysinfo i; 36e1759c21SAlexey Dobriyan unsigned long committed; 37e1759c21SAlexey Dobriyan long cached; 3834e431b0SRik van Riel long available; 39e1759c21SAlexey Dobriyan unsigned long pages[NR_LRU_LISTS]; 4061f94e18SVlastimil Babka unsigned long sreclaimable, sunreclaim; 41e1759c21SAlexey Dobriyan int lru; 42e1759c21SAlexey Dobriyan 43e1759c21SAlexey Dobriyan si_meminfo(&i); 44e1759c21SAlexey Dobriyan si_swapinfo(&i); 451455083cSFeng Tang committed = vm_memory_committed(); 46e1759c21SAlexey Dobriyan 4711fb9989SMel Gorman cached = global_node_page_state(NR_FILE_PAGES) - 4833806f06SShaohua Li total_swapcache_pages() - i.bufferram; 49e1759c21SAlexey Dobriyan if (cached < 0) 50e1759c21SAlexey Dobriyan cached = 0; 51e1759c21SAlexey Dobriyan 52e1759c21SAlexey Dobriyan for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 532f95ff90SMel Gorman pages[lru] = global_node_page_state(NR_LRU_BASE + lru); 54e1759c21SAlexey Dobriyan 55d02bd27bSIgor Redko available = si_mem_available(); 56d42f3245SRoman Gushchin sreclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B); 57d42f3245SRoman Gushchin sunreclaim = global_node_page_state_pages(NR_SLAB_UNRECLAIMABLE_B); 5834e431b0SRik van Riel 59e16e2d8eSJoe Perches show_val_kb(m, "MemTotal: ", i.totalram); 60e16e2d8eSJoe Perches show_val_kb(m, "MemFree: ", i.freeram); 61e16e2d8eSJoe Perches show_val_kb(m, "MemAvailable: ", available); 62e16e2d8eSJoe Perches show_val_kb(m, "Buffers: ", i.bufferram); 63e16e2d8eSJoe Perches show_val_kb(m, "Cached: ", cached); 64e16e2d8eSJoe Perches show_val_kb(m, "SwapCached: ", total_swapcache_pages()); 65e16e2d8eSJoe Perches show_val_kb(m, "Active: ", pages[LRU_ACTIVE_ANON] + 66e16e2d8eSJoe Perches pages[LRU_ACTIVE_FILE]); 67e16e2d8eSJoe Perches show_val_kb(m, "Inactive: ", pages[LRU_INACTIVE_ANON] + 68e16e2d8eSJoe Perches pages[LRU_INACTIVE_FILE]); 69e16e2d8eSJoe Perches show_val_kb(m, "Active(anon): ", pages[LRU_ACTIVE_ANON]); 70e16e2d8eSJoe Perches show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]); 71e16e2d8eSJoe Perches show_val_kb(m, "Active(file): ", pages[LRU_ACTIVE_FILE]); 72e16e2d8eSJoe Perches show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]); 73e16e2d8eSJoe Perches show_val_kb(m, "Unevictable: ", pages[LRU_UNEVICTABLE]); 74c41f012aSMichal Hocko show_val_kb(m, "Mlocked: ", global_zone_page_state(NR_MLOCK)); 75e16e2d8eSJoe Perches 76e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 77e16e2d8eSJoe Perches show_val_kb(m, "HighTotal: ", i.totalhigh); 78e16e2d8eSJoe Perches show_val_kb(m, "HighFree: ", i.freehigh); 79e16e2d8eSJoe Perches show_val_kb(m, "LowTotal: ", i.totalram - i.totalhigh); 80e16e2d8eSJoe Perches show_val_kb(m, "LowFree: ", i.freeram - i.freehigh); 81e1759c21SAlexey Dobriyan #endif 82e16e2d8eSJoe Perches 838feae131SDavid Howells #ifndef CONFIG_MMU 84e16e2d8eSJoe Perches show_val_kb(m, "MmapCopy: ", 85e16e2d8eSJoe Perches (unsigned long)atomic_long_read(&mmap_pages_allocated)); 868feae131SDavid Howells #endif 87e16e2d8eSJoe Perches 88e16e2d8eSJoe Perches show_val_kb(m, "SwapTotal: ", i.totalswap); 89e16e2d8eSJoe Perches show_val_kb(m, "SwapFree: ", i.freeswap); 90f6498b77SJohannes Weiner #ifdef CONFIG_ZSWAP 91f6498b77SJohannes Weiner seq_printf(m, "Zswap: %8lu kB\n", 92f6498b77SJohannes Weiner (unsigned long)(zswap_pool_total_size >> 10)); 93f6498b77SJohannes Weiner seq_printf(m, "Zswapped: %8lu kB\n", 94f6498b77SJohannes Weiner (unsigned long)atomic_read(&zswap_stored_pages) << 95f6498b77SJohannes Weiner (PAGE_SHIFT - 10)); 96f6498b77SJohannes Weiner #endif 97e16e2d8eSJoe Perches show_val_kb(m, "Dirty: ", 98e16e2d8eSJoe Perches global_node_page_state(NR_FILE_DIRTY)); 99e16e2d8eSJoe Perches show_val_kb(m, "Writeback: ", 100e16e2d8eSJoe Perches global_node_page_state(NR_WRITEBACK)); 101e16e2d8eSJoe Perches show_val_kb(m, "AnonPages: ", 102e16e2d8eSJoe Perches global_node_page_state(NR_ANON_MAPPED)); 103e16e2d8eSJoe Perches show_val_kb(m, "Mapped: ", 104e16e2d8eSJoe Perches global_node_page_state(NR_FILE_MAPPED)); 105e16e2d8eSJoe Perches show_val_kb(m, "Shmem: ", i.sharedram); 10661f94e18SVlastimil Babka show_val_kb(m, "KReclaimable: ", sreclaimable + 10761f94e18SVlastimil Babka global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE)); 10861f94e18SVlastimil Babka show_val_kb(m, "Slab: ", sreclaimable + sunreclaim); 10961f94e18SVlastimil Babka show_val_kb(m, "SReclaimable: ", sreclaimable); 11061f94e18SVlastimil Babka show_val_kb(m, "SUnreclaim: ", sunreclaim); 111e16e2d8eSJoe Perches seq_printf(m, "KernelStack: %8lu kB\n", 112991e7673SShakeel Butt global_node_page_state(NR_KERNEL_STACK_KB)); 113628d06a4SSami Tolvanen #ifdef CONFIG_SHADOW_CALL_STACK 114628d06a4SSami Tolvanen seq_printf(m, "ShadowCallStack:%8lu kB\n", 115991e7673SShakeel Butt global_node_page_state(NR_KERNEL_SCS_KB)); 116628d06a4SSami Tolvanen #endif 117e16e2d8eSJoe Perches show_val_kb(m, "PageTables: ", 118f0c0c115SShakeel Butt global_node_page_state(NR_PAGETABLE)); 119ebc97a52SYosry Ahmed show_val_kb(m, "SecPageTables: ", 120ebc97a52SYosry Ahmed global_node_page_state(NR_SECONDARY_PAGETABLE)); 121e16e2d8eSJoe Perches 1228d92890bSNeilBrown show_val_kb(m, "NFS_Unstable: ", 0); 123e16e2d8eSJoe Perches show_val_kb(m, "Bounce: ", 124c41f012aSMichal Hocko global_zone_page_state(NR_BOUNCE)); 125e16e2d8eSJoe Perches show_val_kb(m, "WritebackTmp: ", 126e16e2d8eSJoe Perches global_node_page_state(NR_WRITEBACK_TEMP)); 127e16e2d8eSJoe Perches show_val_kb(m, "CommitLimit: ", vm_commit_limit()); 128e16e2d8eSJoe Perches show_val_kb(m, "Committed_AS: ", committed); 129e16e2d8eSJoe Perches seq_printf(m, "VmallocTotal: %8lu kB\n", 130e16e2d8eSJoe Perches (unsigned long)VMALLOC_TOTAL >> 10); 13197105f0aSRoman Gushchin show_val_kb(m, "VmallocUsed: ", vmalloc_nr_pages()); 132e16e2d8eSJoe Perches show_val_kb(m, "VmallocChunk: ", 0ul); 1337e8a6304SDennis Zhou (Facebook) show_val_kb(m, "Percpu: ", pcpu_nr_pages()); 134e16e2d8eSJoe Perches 135*bd23024bSTomas Mudrunka #ifdef CONFIG_MEMTEST 136*bd23024bSTomas Mudrunka if (early_memtest_done) { 137*bd23024bSTomas Mudrunka unsigned long early_memtest_bad_size_kb; 138*bd23024bSTomas Mudrunka 139*bd23024bSTomas Mudrunka early_memtest_bad_size_kb = early_memtest_bad_size>>10; 140*bd23024bSTomas Mudrunka if (early_memtest_bad_size && !early_memtest_bad_size_kb) 141*bd23024bSTomas Mudrunka early_memtest_bad_size_kb = 1; 142*bd23024bSTomas Mudrunka /* When 0 is reported, it means there actually was a successful test */ 143*bd23024bSTomas Mudrunka seq_printf(m, "EarlyMemtestBad: %5lu kB\n", early_memtest_bad_size_kb); 144*bd23024bSTomas Mudrunka } 145*bd23024bSTomas Mudrunka #endif 146*bd23024bSTomas Mudrunka 1476a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 148e16e2d8eSJoe Perches seq_printf(m, "HardwareCorrupted: %5lu kB\n", 149e16e2d8eSJoe Perches atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)); 1506a46079cSAndi Kleen #endif 151e16e2d8eSJoe Perches 15279134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 153e16e2d8eSJoe Perches show_val_kb(m, "AnonHugePages: ", 15469473e5dSMuchun Song global_node_page_state(NR_ANON_THPS)); 155e16e2d8eSJoe Perches show_val_kb(m, "ShmemHugePages: ", 15657b2847dSMuchun Song global_node_page_state(NR_SHMEM_THPS)); 157e16e2d8eSJoe Perches show_val_kb(m, "ShmemPmdMapped: ", 158a1528e21SMuchun Song global_node_page_state(NR_SHMEM_PMDMAPPED)); 15960fbf0abSSong Liu show_val_kb(m, "FileHugePages: ", 160bf9eceadSMuchun Song global_node_page_state(NR_FILE_THPS)); 16160fbf0abSSong Liu show_val_kb(m, "FilePmdMapped: ", 162380780e7SMuchun Song global_node_page_state(NR_FILE_PMDMAPPED)); 16379134171SAndrea Arcangeli #endif 164e16e2d8eSJoe Perches 16547f8f929SPintu Kumar #ifdef CONFIG_CMA 166e16e2d8eSJoe Perches show_val_kb(m, "CmaTotal: ", totalcma_pages); 167e16e2d8eSJoe Perches show_val_kb(m, "CmaFree: ", 168c41f012aSMichal Hocko global_zone_page_state(NR_FREE_CMA_PAGES)); 16947f8f929SPintu Kumar #endif 170e1759c21SAlexey Dobriyan 171e1759c21SAlexey Dobriyan hugetlb_report_meminfo(m); 172e1759c21SAlexey Dobriyan 173e1759c21SAlexey Dobriyan arch_report_meminfo(m); 174e1759c21SAlexey Dobriyan 175e1759c21SAlexey Dobriyan return 0; 176e1759c21SAlexey Dobriyan } 177e1759c21SAlexey Dobriyan 178e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void) 179e1759c21SAlexey Dobriyan { 180ef1d6178SAlexey Dobriyan struct proc_dir_entry *pde; 181ef1d6178SAlexey Dobriyan 182ef1d6178SAlexey Dobriyan pde = proc_create_single("meminfo", 0, NULL, meminfo_proc_show); 183ef1d6178SAlexey Dobriyan pde_make_permanent(pde); 184e1759c21SAlexey Dobriyan return 0; 185e1759c21SAlexey Dobriyan } 186abaf3787SPaul Gortmaker fs_initcall(proc_meminfo_init); 187