meminfo.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <asm/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. struct vmalloc_info vmi;
  26. long cached;
  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 = atomic_long_read(&vm_committed_space);
  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. get_vmalloc_info(&vmi);
  43. for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
  44. pages[lru] = global_page_state(NR_LRU_BASE + lru);
  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. "Buffers: %8lu kB\n"
  52. "Cached: %8lu kB\n"
  53. "SwapCached: %8lu kB\n"
  54. "Active: %8lu kB\n"
  55. "Inactive: %8lu kB\n"
  56. "Active(anon): %8lu kB\n"
  57. "Inactive(anon): %8lu kB\n"
  58. "Active(file): %8lu kB\n"
  59. "Inactive(file): %8lu kB\n"
  60. #ifdef CONFIG_UNEVICTABLE_LRU
  61. "Unevictable: %8lu kB\n"
  62. "Mlocked: %8lu kB\n"
  63. #endif
  64. #ifdef CONFIG_HIGHMEM
  65. "HighTotal: %8lu kB\n"
  66. "HighFree: %8lu kB\n"
  67. "LowTotal: %8lu kB\n"
  68. "LowFree: %8lu kB\n"
  69. #endif
  70. #ifndef CONFIG_MMU
  71. "MmapCopy: %8lu kB\n"
  72. #endif
  73. "SwapTotal: %8lu kB\n"
  74. "SwapFree: %8lu kB\n"
  75. "Dirty: %8lu kB\n"
  76. "Writeback: %8lu kB\n"
  77. "AnonPages: %8lu kB\n"
  78. "Mapped: %8lu kB\n"
  79. "Slab: %8lu kB\n"
  80. "SReclaimable: %8lu kB\n"
  81. "SUnreclaim: %8lu kB\n"
  82. "PageTables: %8lu kB\n"
  83. #ifdef CONFIG_QUICKLIST
  84. "Quicklists: %8lu kB\n"
  85. #endif
  86. "NFS_Unstable: %8lu kB\n"
  87. "Bounce: %8lu kB\n"
  88. "WritebackTmp: %8lu kB\n"
  89. "CommitLimit: %8lu kB\n"
  90. "Committed_AS: %8lu kB\n"
  91. "VmallocTotal: %8lu kB\n"
  92. "VmallocUsed: %8lu kB\n"
  93. "VmallocChunk: %8lu kB\n",
  94. K(i.totalram),
  95. K(i.freeram),
  96. K(i.bufferram),
  97. K(cached),
  98. K(total_swapcache_pages),
  99. K(pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE]),
  100. K(pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE]),
  101. K(pages[LRU_ACTIVE_ANON]),
  102. K(pages[LRU_INACTIVE_ANON]),
  103. K(pages[LRU_ACTIVE_FILE]),
  104. K(pages[LRU_INACTIVE_FILE]),
  105. #ifdef CONFIG_UNEVICTABLE_LRU
  106. K(pages[LRU_UNEVICTABLE]),
  107. K(global_page_state(NR_MLOCK)),
  108. #endif
  109. #ifdef CONFIG_HIGHMEM
  110. K(i.totalhigh),
  111. K(i.freehigh),
  112. K(i.totalram-i.totalhigh),
  113. K(i.freeram-i.freehigh),
  114. #endif
  115. #ifndef CONFIG_MMU
  116. K((unsigned long) atomic_long_read(&mmap_pages_allocated)),
  117. #endif
  118. K(i.totalswap),
  119. K(i.freeswap),
  120. K(global_page_state(NR_FILE_DIRTY)),
  121. K(global_page_state(NR_WRITEBACK)),
  122. K(global_page_state(NR_ANON_PAGES)),
  123. K(global_page_state(NR_FILE_MAPPED)),
  124. K(global_page_state(NR_SLAB_RECLAIMABLE) +
  125. global_page_state(NR_SLAB_UNRECLAIMABLE)),
  126. K(global_page_state(NR_SLAB_RECLAIMABLE)),
  127. K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
  128. K(global_page_state(NR_PAGETABLE)),
  129. #ifdef CONFIG_QUICKLIST
  130. K(quicklist_total_size()),
  131. #endif
  132. K(global_page_state(NR_UNSTABLE_NFS)),
  133. K(global_page_state(NR_BOUNCE)),
  134. K(global_page_state(NR_WRITEBACK_TEMP)),
  135. K(allowed),
  136. K(committed),
  137. (unsigned long)VMALLOC_TOTAL >> 10,
  138. vmi.used >> 10,
  139. vmi.largest_chunk >> 10
  140. );
  141. hugetlb_report_meminfo(m);
  142. arch_report_meminfo(m);
  143. return 0;
  144. #undef K
  145. }
  146. static int meminfo_proc_open(struct inode *inode, struct file *file)
  147. {
  148. return single_open(file, meminfo_proc_show, NULL);
  149. }
  150. static const struct file_operations meminfo_proc_fops = {
  151. .open = meminfo_proc_open,
  152. .read = seq_read,
  153. .llseek = seq_lseek,
  154. .release = single_release,
  155. };
  156. static int __init proc_meminfo_init(void)
  157. {
  158. proc_create("meminfo", 0, NULL, &meminfo_proc_fops);
  159. return 0;
  160. }
  161. module_init(proc_meminfo_init);