meminfo.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/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 <linux/vmalloc.h>
  15. #ifdef CONFIG_CMA
  16. #include <linux/cma.h>
  17. #endif
  18. #include <asm/page.h>
  19. #include <asm/pgtable.h>
  20. #include "internal.h"
  21. void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
  22. {
  23. }
  24. static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
  25. {
  26. char v[32];
  27. static const char blanks[7] = {' ', ' ', ' ', ' ',' ', ' ', ' '};
  28. int len;
  29. len = num_to_str(v, sizeof(v), num << (PAGE_SHIFT - 10));
  30. seq_write(m, s, 16);
  31. if (len > 0) {
  32. if (len < 8)
  33. seq_write(m, blanks, 8 - len);
  34. seq_write(m, v, len);
  35. }
  36. seq_write(m, " kB\n", 4);
  37. }
  38. static int meminfo_proc_show(struct seq_file *m, void *v)
  39. {
  40. struct sysinfo i;
  41. unsigned long committed;
  42. long cached;
  43. long available;
  44. unsigned long pages[NR_LRU_LISTS];
  45. int lru;
  46. si_meminfo(&i);
  47. si_swapinfo(&i);
  48. committed = percpu_counter_read_positive(&vm_committed_as);
  49. cached = global_node_page_state(NR_FILE_PAGES) -
  50. total_swapcache_pages() - i.bufferram;
  51. if (cached < 0)
  52. cached = 0;
  53. for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
  54. pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
  55. available = si_mem_available();
  56. show_val_kb(m, "MemTotal: ", i.totalram);
  57. show_val_kb(m, "MemFree: ", i.freeram);
  58. show_val_kb(m, "MemAvailable: ", available);
  59. show_val_kb(m, "Buffers: ", i.bufferram);
  60. show_val_kb(m, "Cached: ", cached);
  61. show_val_kb(m, "SwapCached: ", total_swapcache_pages());
  62. show_val_kb(m, "Active: ", pages[LRU_ACTIVE_ANON] +
  63. pages[LRU_ACTIVE_FILE]);
  64. show_val_kb(m, "Inactive: ", pages[LRU_INACTIVE_ANON] +
  65. pages[LRU_INACTIVE_FILE]);
  66. show_val_kb(m, "Active(anon): ", pages[LRU_ACTIVE_ANON]);
  67. show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]);
  68. show_val_kb(m, "Active(file): ", pages[LRU_ACTIVE_FILE]);
  69. show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]);
  70. show_val_kb(m, "Unevictable: ", pages[LRU_UNEVICTABLE]);
  71. show_val_kb(m, "Mlocked: ", global_page_state(NR_MLOCK));
  72. #ifdef CONFIG_HIGHMEM
  73. show_val_kb(m, "HighTotal: ", i.totalhigh);
  74. show_val_kb(m, "HighFree: ", i.freehigh);
  75. show_val_kb(m, "LowTotal: ", i.totalram - i.totalhigh);
  76. show_val_kb(m, "LowFree: ", i.freeram - i.freehigh);
  77. #endif
  78. #ifndef CONFIG_MMU
  79. show_val_kb(m, "MmapCopy: ",
  80. (unsigned long)atomic_long_read(&mmap_pages_allocated));
  81. #endif
  82. show_val_kb(m, "SwapTotal: ", i.totalswap);
  83. show_val_kb(m, "SwapFree: ", i.freeswap);
  84. show_val_kb(m, "Dirty: ",
  85. global_node_page_state(NR_FILE_DIRTY));
  86. show_val_kb(m, "Writeback: ",
  87. global_node_page_state(NR_WRITEBACK));
  88. show_val_kb(m, "AnonPages: ",
  89. global_node_page_state(NR_ANON_MAPPED));
  90. show_val_kb(m, "Mapped: ",
  91. global_node_page_state(NR_FILE_MAPPED));
  92. show_val_kb(m, "Shmem: ", i.sharedram);
  93. show_val_kb(m, "Slab: ",
  94. global_page_state(NR_SLAB_RECLAIMABLE) +
  95. global_page_state(NR_SLAB_UNRECLAIMABLE));
  96. show_val_kb(m, "SReclaimable: ",
  97. global_page_state(NR_SLAB_RECLAIMABLE));
  98. show_val_kb(m, "SUnreclaim: ",
  99. global_page_state(NR_SLAB_UNRECLAIMABLE));
  100. seq_printf(m, "KernelStack: %8lu kB\n",
  101. global_page_state(NR_KERNEL_STACK_KB));
  102. show_val_kb(m, "PageTables: ",
  103. global_page_state(NR_PAGETABLE));
  104. #ifdef CONFIG_QUICKLIST
  105. show_val_kb(m, "Quicklists: ", quicklist_total_size());
  106. #endif
  107. show_val_kb(m, "NFS_Unstable: ",
  108. global_node_page_state(NR_UNSTABLE_NFS));
  109. show_val_kb(m, "Bounce: ",
  110. global_page_state(NR_BOUNCE));
  111. show_val_kb(m, "WritebackTmp: ",
  112. global_node_page_state(NR_WRITEBACK_TEMP));
  113. show_val_kb(m, "CommitLimit: ", vm_commit_limit());
  114. show_val_kb(m, "Committed_AS: ", committed);
  115. seq_printf(m, "VmallocTotal: %8lu kB\n",
  116. (unsigned long)VMALLOC_TOTAL >> 10);
  117. show_val_kb(m, "VmallocUsed: ", 0ul);
  118. show_val_kb(m, "VmallocChunk: ", 0ul);
  119. #ifdef CONFIG_MEMORY_FAILURE
  120. seq_printf(m, "HardwareCorrupted: %5lu kB\n",
  121. atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10));
  122. #endif
  123. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  124. show_val_kb(m, "AnonHugePages: ",
  125. global_node_page_state(NR_ANON_THPS) * HPAGE_PMD_NR);
  126. show_val_kb(m, "ShmemHugePages: ",
  127. global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);
  128. show_val_kb(m, "ShmemPmdMapped: ",
  129. global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
  130. #endif
  131. #ifdef CONFIG_CMA
  132. show_val_kb(m, "CmaTotal: ", totalcma_pages);
  133. show_val_kb(m, "CmaFree: ",
  134. global_page_state(NR_FREE_CMA_PAGES));
  135. #endif
  136. hugetlb_report_meminfo(m);
  137. arch_report_meminfo(m);
  138. return 0;
  139. }
  140. static int meminfo_proc_open(struct inode *inode, struct file *file)
  141. {
  142. return single_open(file, meminfo_proc_show, NULL);
  143. }
  144. static const struct file_operations meminfo_proc_fops = {
  145. .open = meminfo_proc_open,
  146. .read = seq_read,
  147. .llseek = seq_lseek,
  148. .release = single_release,
  149. };
  150. static int __init proc_meminfo_init(void)
  151. {
  152. proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
  153. return 0;
  154. }
  155. fs_initcall(proc_meminfo_init);