meminfo.c 5.8 KB

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