meminfo.c 4.8 KB

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