meminfo.c 5.7 KB

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