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