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> 9e1759c21SAlexey Dobriyan #include <linux/proc_fs.h> 10e1759c21SAlexey Dobriyan #include <linux/quicklist.h> 11e1759c21SAlexey Dobriyan #include <linux/seq_file.h> 12e1759c21SAlexey Dobriyan #include <linux/swap.h> 13e1759c21SAlexey Dobriyan #include <linux/vmstat.h> 1460063497SArun Sharma #include <linux/atomic.h> 15db3808c1SJoonsoo Kim #include <linux/vmalloc.h> 1647f8f929SPintu Kumar #ifdef CONFIG_CMA 1747f8f929SPintu Kumar #include <linux/cma.h> 1847f8f929SPintu Kumar #endif 19e1759c21SAlexey Dobriyan #include <asm/page.h> 20e1759c21SAlexey Dobriyan #include <asm/pgtable.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]; 40e1759c21SAlexey Dobriyan int lru; 41e1759c21SAlexey Dobriyan 42e1759c21SAlexey Dobriyan si_meminfo(&i); 43e1759c21SAlexey Dobriyan si_swapinfo(&i); 4400a62ce9SKOSAKI Motohiro committed = percpu_counter_read_positive(&vm_committed_as); 45e1759c21SAlexey Dobriyan 4611fb9989SMel Gorman cached = global_node_page_state(NR_FILE_PAGES) - 4733806f06SShaohua Li total_swapcache_pages() - i.bufferram; 48e1759c21SAlexey Dobriyan if (cached < 0) 49e1759c21SAlexey Dobriyan cached = 0; 50e1759c21SAlexey Dobriyan 51e1759c21SAlexey Dobriyan for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) 522f95ff90SMel Gorman pages[lru] = global_node_page_state(NR_LRU_BASE + lru); 53e1759c21SAlexey Dobriyan 54d02bd27bSIgor Redko available = si_mem_available(); 5534e431b0SRik van Riel 56e16e2d8eSJoe Perches show_val_kb(m, "MemTotal: ", i.totalram); 57e16e2d8eSJoe Perches show_val_kb(m, "MemFree: ", i.freeram); 58e16e2d8eSJoe Perches show_val_kb(m, "MemAvailable: ", available); 59e16e2d8eSJoe Perches show_val_kb(m, "Buffers: ", i.bufferram); 60e16e2d8eSJoe Perches show_val_kb(m, "Cached: ", cached); 61e16e2d8eSJoe Perches show_val_kb(m, "SwapCached: ", total_swapcache_pages()); 62e16e2d8eSJoe Perches show_val_kb(m, "Active: ", pages[LRU_ACTIVE_ANON] + 63e16e2d8eSJoe Perches pages[LRU_ACTIVE_FILE]); 64e16e2d8eSJoe Perches show_val_kb(m, "Inactive: ", pages[LRU_INACTIVE_ANON] + 65e16e2d8eSJoe Perches pages[LRU_INACTIVE_FILE]); 66e16e2d8eSJoe Perches show_val_kb(m, "Active(anon): ", pages[LRU_ACTIVE_ANON]); 67e16e2d8eSJoe Perches show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]); 68e16e2d8eSJoe Perches show_val_kb(m, "Active(file): ", pages[LRU_ACTIVE_FILE]); 69e16e2d8eSJoe Perches show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]); 70e16e2d8eSJoe Perches show_val_kb(m, "Unevictable: ", pages[LRU_UNEVICTABLE]); 71c41f012aSMichal Hocko show_val_kb(m, "Mlocked: ", global_zone_page_state(NR_MLOCK)); 72e16e2d8eSJoe Perches 73e1759c21SAlexey Dobriyan #ifdef CONFIG_HIGHMEM 74e16e2d8eSJoe Perches show_val_kb(m, "HighTotal: ", i.totalhigh); 75e16e2d8eSJoe Perches show_val_kb(m, "HighFree: ", i.freehigh); 76e16e2d8eSJoe Perches show_val_kb(m, "LowTotal: ", i.totalram - i.totalhigh); 77e16e2d8eSJoe Perches show_val_kb(m, "LowFree: ", i.freeram - i.freehigh); 78e1759c21SAlexey Dobriyan #endif 79e16e2d8eSJoe Perches 808feae131SDavid Howells #ifndef CONFIG_MMU 81e16e2d8eSJoe Perches show_val_kb(m, "MmapCopy: ", 82e16e2d8eSJoe Perches (unsigned long)atomic_long_read(&mmap_pages_allocated)); 838feae131SDavid Howells #endif 84e16e2d8eSJoe Perches 85e16e2d8eSJoe Perches show_val_kb(m, "SwapTotal: ", i.totalswap); 86e16e2d8eSJoe Perches show_val_kb(m, "SwapFree: ", i.freeswap); 87e16e2d8eSJoe Perches show_val_kb(m, "Dirty: ", 88e16e2d8eSJoe Perches global_node_page_state(NR_FILE_DIRTY)); 89e16e2d8eSJoe Perches show_val_kb(m, "Writeback: ", 90e16e2d8eSJoe Perches global_node_page_state(NR_WRITEBACK)); 91e16e2d8eSJoe Perches show_val_kb(m, "AnonPages: ", 92e16e2d8eSJoe Perches global_node_page_state(NR_ANON_MAPPED)); 93e16e2d8eSJoe Perches show_val_kb(m, "Mapped: ", 94e16e2d8eSJoe Perches global_node_page_state(NR_FILE_MAPPED)); 95e16e2d8eSJoe Perches show_val_kb(m, "Shmem: ", i.sharedram); 96e16e2d8eSJoe Perches show_val_kb(m, "Slab: ", 97d507e2ebSJohannes Weiner global_node_page_state(NR_SLAB_RECLAIMABLE) + 98d507e2ebSJohannes Weiner global_node_page_state(NR_SLAB_UNRECLAIMABLE)); 99e16e2d8eSJoe Perches 100e16e2d8eSJoe Perches show_val_kb(m, "SReclaimable: ", 101d507e2ebSJohannes Weiner global_node_page_state(NR_SLAB_RECLAIMABLE)); 102e16e2d8eSJoe Perches show_val_kb(m, "SUnreclaim: ", 103d507e2ebSJohannes Weiner global_node_page_state(NR_SLAB_UNRECLAIMABLE)); 104e16e2d8eSJoe Perches seq_printf(m, "KernelStack: %8lu kB\n", 105c41f012aSMichal Hocko global_zone_page_state(NR_KERNEL_STACK_KB)); 106e16e2d8eSJoe Perches show_val_kb(m, "PageTables: ", 107c41f012aSMichal Hocko global_zone_page_state(NR_PAGETABLE)); 108e1759c21SAlexey Dobriyan #ifdef CONFIG_QUICKLIST 109e16e2d8eSJoe Perches show_val_kb(m, "Quicklists: ", quicklist_total_size()); 110e1759c21SAlexey Dobriyan #endif 111e16e2d8eSJoe Perches 112e16e2d8eSJoe Perches show_val_kb(m, "NFS_Unstable: ", 113e16e2d8eSJoe Perches global_node_page_state(NR_UNSTABLE_NFS)); 114e16e2d8eSJoe Perches show_val_kb(m, "Bounce: ", 115c41f012aSMichal Hocko global_zone_page_state(NR_BOUNCE)); 116e16e2d8eSJoe Perches show_val_kb(m, "WritebackTmp: ", 117e16e2d8eSJoe Perches global_node_page_state(NR_WRITEBACK_TEMP)); 118e16e2d8eSJoe Perches show_val_kb(m, "CommitLimit: ", vm_commit_limit()); 119e16e2d8eSJoe Perches show_val_kb(m, "Committed_AS: ", committed); 120e16e2d8eSJoe Perches seq_printf(m, "VmallocTotal: %8lu kB\n", 121e16e2d8eSJoe Perches (unsigned long)VMALLOC_TOTAL >> 10); 122e16e2d8eSJoe Perches show_val_kb(m, "VmallocUsed: ", 0ul); 123e16e2d8eSJoe Perches show_val_kb(m, "VmallocChunk: ", 0ul); 124e16e2d8eSJoe Perches 1256a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 126e16e2d8eSJoe Perches seq_printf(m, "HardwareCorrupted: %5lu kB\n", 127e16e2d8eSJoe Perches atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)); 1286a46079cSAndi Kleen #endif 129e16e2d8eSJoe Perches 13079134171SAndrea Arcangeli #ifdef CONFIG_TRANSPARENT_HUGEPAGE 131e16e2d8eSJoe Perches show_val_kb(m, "AnonHugePages: ", 132e16e2d8eSJoe Perches global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR); 133e16e2d8eSJoe Perches show_val_kb(m, "ShmemHugePages: ", 134e16e2d8eSJoe Perches global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR); 135e16e2d8eSJoe Perches show_val_kb(m, "ShmemPmdMapped: ", 136e16e2d8eSJoe Perches global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR); 13779134171SAndrea Arcangeli #endif 138e16e2d8eSJoe Perches 13947f8f929SPintu Kumar #ifdef CONFIG_CMA 140e16e2d8eSJoe Perches show_val_kb(m, "CmaTotal: ", totalcma_pages); 141e16e2d8eSJoe Perches show_val_kb(m, "CmaFree: ", 142c41f012aSMichal Hocko global_zone_page_state(NR_FREE_CMA_PAGES)); 14347f8f929SPintu Kumar #endif 144e1759c21SAlexey Dobriyan 145e1759c21SAlexey Dobriyan hugetlb_report_meminfo(m); 146e1759c21SAlexey Dobriyan 147e1759c21SAlexey Dobriyan arch_report_meminfo(m); 148e1759c21SAlexey Dobriyan 149e1759c21SAlexey Dobriyan return 0; 150e1759c21SAlexey Dobriyan } 151e1759c21SAlexey Dobriyan 152e1759c21SAlexey Dobriyan static int __init proc_meminfo_init(void) 153e1759c21SAlexey Dobriyan { 154*3f3942acSChristoph Hellwig proc_create_single("meminfo", 0, NULL, meminfo_proc_show); 155e1759c21SAlexey Dobriyan return 0; 156e1759c21SAlexey Dobriyan } 157abaf3787SPaul Gortmaker fs_initcall(proc_meminfo_init); 158