vmstat.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef _LINUX_VMSTAT_H
  2. #define _LINUX_VMSTAT_H
  3. #include <linux/types.h>
  4. #include <linux/percpu.h>
  5. #include <linux/mm.h>
  6. #include <linux/mmzone.h>
  7. #include <asm/atomic.h>
  8. #ifdef CONFIG_ZONE_DMA
  9. #define DMA_ZONE(xx) xx##_DMA,
  10. #else
  11. #define DMA_ZONE(xx)
  12. #endif
  13. #ifdef CONFIG_ZONE_DMA32
  14. #define DMA32_ZONE(xx) xx##_DMA32,
  15. #else
  16. #define DMA32_ZONE(xx)
  17. #endif
  18. #ifdef CONFIG_HIGHMEM
  19. #define HIGHMEM_ZONE(xx) , xx##_HIGH
  20. #else
  21. #define HIGHMEM_ZONE(xx)
  22. #endif
  23. #define FOR_ALL_ZONES(xx) DMA_ZONE(xx) DMA32_ZONE(xx) xx##_NORMAL HIGHMEM_ZONE(xx) , xx##_MOVABLE
  24. enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
  25. FOR_ALL_ZONES(PGALLOC),
  26. PGFREE, PGACTIVATE, PGDEACTIVATE,
  27. PGFAULT, PGMAJFAULT,
  28. FOR_ALL_ZONES(PGREFILL),
  29. FOR_ALL_ZONES(PGSTEAL),
  30. FOR_ALL_ZONES(PGSCAN_KSWAPD),
  31. FOR_ALL_ZONES(PGSCAN_DIRECT),
  32. #ifdef CONFIG_NUMA
  33. PGSCAN_ZONE_RECLAIM_FAILED,
  34. #endif
  35. PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL,
  36. KSWAPD_PREMATURE_FAST, KSWAPD_PREMATURE_SLOW,
  37. PAGEOUTRUN, ALLOCSTALL, PGROTATED,
  38. #ifdef CONFIG_HUGETLB_PAGE
  39. HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL,
  40. #endif
  41. UNEVICTABLE_PGCULLED, /* culled to noreclaim list */
  42. UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */
  43. UNEVICTABLE_PGRESCUED, /* rescued from noreclaim list */
  44. UNEVICTABLE_PGMLOCKED,
  45. UNEVICTABLE_PGMUNLOCKED,
  46. UNEVICTABLE_PGCLEARED, /* on COW, page truncate */
  47. UNEVICTABLE_PGSTRANDED, /* unable to isolate on unlock */
  48. UNEVICTABLE_MLOCKFREED,
  49. NR_VM_EVENT_ITEMS
  50. };
  51. extern int sysctl_stat_interval;
  52. #ifdef CONFIG_VM_EVENT_COUNTERS
  53. /*
  54. * Light weight per cpu counter implementation.
  55. *
  56. * Counters should only be incremented and no critical kernel component
  57. * should rely on the counter values.
  58. *
  59. * Counters are handled completely inline. On many platforms the code
  60. * generated will simply be the increment of a global address.
  61. */
  62. struct vm_event_state {
  63. unsigned long event[NR_VM_EVENT_ITEMS];
  64. };
  65. DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
  66. static inline void __count_vm_event(enum vm_event_item item)
  67. {
  68. __this_cpu_inc(per_cpu_var(vm_event_states).event[item]);
  69. }
  70. static inline void count_vm_event(enum vm_event_item item)
  71. {
  72. this_cpu_inc(per_cpu_var(vm_event_states).event[item]);
  73. }
  74. static inline void __count_vm_events(enum vm_event_item item, long delta)
  75. {
  76. __this_cpu_add(per_cpu_var(vm_event_states).event[item], delta);
  77. }
  78. static inline void count_vm_events(enum vm_event_item item, long delta)
  79. {
  80. this_cpu_add(per_cpu_var(vm_event_states).event[item], delta);
  81. }
  82. extern void all_vm_events(unsigned long *);
  83. #ifdef CONFIG_HOTPLUG
  84. extern void vm_events_fold_cpu(int cpu);
  85. #else
  86. static inline void vm_events_fold_cpu(int cpu)
  87. {
  88. }
  89. #endif
  90. #else
  91. /* Disable counters */
  92. static inline void count_vm_event(enum vm_event_item item)
  93. {
  94. }
  95. static inline void count_vm_events(enum vm_event_item item, long delta)
  96. {
  97. }
  98. static inline void __count_vm_event(enum vm_event_item item)
  99. {
  100. }
  101. static inline void __count_vm_events(enum vm_event_item item, long delta)
  102. {
  103. }
  104. static inline void all_vm_events(unsigned long *ret)
  105. {
  106. }
  107. static inline void vm_events_fold_cpu(int cpu)
  108. {
  109. }
  110. #endif /* CONFIG_VM_EVENT_COUNTERS */
  111. #define __count_zone_vm_events(item, zone, delta) \
  112. __count_vm_events(item##_NORMAL - ZONE_NORMAL + \
  113. zone_idx(zone), delta)
  114. /*
  115. * Zone based page accounting with per cpu differentials.
  116. */
  117. extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  118. static inline void zone_page_state_add(long x, struct zone *zone,
  119. enum zone_stat_item item)
  120. {
  121. atomic_long_add(x, &zone->vm_stat[item]);
  122. atomic_long_add(x, &vm_stat[item]);
  123. }
  124. static inline unsigned long global_page_state(enum zone_stat_item item)
  125. {
  126. long x = atomic_long_read(&vm_stat[item]);
  127. #ifdef CONFIG_SMP
  128. if (x < 0)
  129. x = 0;
  130. #endif
  131. return x;
  132. }
  133. static inline unsigned long zone_page_state(struct zone *zone,
  134. enum zone_stat_item item)
  135. {
  136. long x = atomic_long_read(&zone->vm_stat[item]);
  137. #ifdef CONFIG_SMP
  138. if (x < 0)
  139. x = 0;
  140. #endif
  141. return x;
  142. }
  143. extern unsigned long global_reclaimable_pages(void);
  144. extern unsigned long zone_reclaimable_pages(struct zone *zone);
  145. #ifdef CONFIG_NUMA
  146. /*
  147. * Determine the per node value of a stat item. This function
  148. * is called frequently in a NUMA machine, so try to be as
  149. * frugal as possible.
  150. */
  151. static inline unsigned long node_page_state(int node,
  152. enum zone_stat_item item)
  153. {
  154. struct zone *zones = NODE_DATA(node)->node_zones;
  155. return
  156. #ifdef CONFIG_ZONE_DMA
  157. zone_page_state(&zones[ZONE_DMA], item) +
  158. #endif
  159. #ifdef CONFIG_ZONE_DMA32
  160. zone_page_state(&zones[ZONE_DMA32], item) +
  161. #endif
  162. #ifdef CONFIG_HIGHMEM
  163. zone_page_state(&zones[ZONE_HIGHMEM], item) +
  164. #endif
  165. zone_page_state(&zones[ZONE_NORMAL], item) +
  166. zone_page_state(&zones[ZONE_MOVABLE], item);
  167. }
  168. extern void zone_statistics(struct zone *, struct zone *);
  169. #else
  170. #define node_page_state(node, item) global_page_state(item)
  171. #define zone_statistics(_zl,_z) do { } while (0)
  172. #endif /* CONFIG_NUMA */
  173. #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d)
  174. #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d))
  175. static inline void zap_zone_vm_stats(struct zone *zone)
  176. {
  177. memset(zone->vm_stat, 0, sizeof(zone->vm_stat));
  178. }
  179. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  180. #ifdef CONFIG_SMP
  181. void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
  182. void __inc_zone_page_state(struct page *, enum zone_stat_item);
  183. void __dec_zone_page_state(struct page *, enum zone_stat_item);
  184. void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
  185. void inc_zone_page_state(struct page *, enum zone_stat_item);
  186. void dec_zone_page_state(struct page *, enum zone_stat_item);
  187. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  188. extern void __inc_zone_state(struct zone *, enum zone_stat_item);
  189. extern void dec_zone_state(struct zone *, enum zone_stat_item);
  190. extern void __dec_zone_state(struct zone *, enum zone_stat_item);
  191. void refresh_cpu_vm_stats(int);
  192. #else /* CONFIG_SMP */
  193. /*
  194. * We do not maintain differentials in a single processor configuration.
  195. * The functions directly modify the zone and global counters.
  196. */
  197. static inline void __mod_zone_page_state(struct zone *zone,
  198. enum zone_stat_item item, int delta)
  199. {
  200. zone_page_state_add(delta, zone, item);
  201. }
  202. static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  203. {
  204. atomic_long_inc(&zone->vm_stat[item]);
  205. atomic_long_inc(&vm_stat[item]);
  206. }
  207. static inline void __inc_zone_page_state(struct page *page,
  208. enum zone_stat_item item)
  209. {
  210. __inc_zone_state(page_zone(page), item);
  211. }
  212. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  213. {
  214. atomic_long_dec(&zone->vm_stat[item]);
  215. atomic_long_dec(&vm_stat[item]);
  216. }
  217. static inline void __dec_zone_page_state(struct page *page,
  218. enum zone_stat_item item)
  219. {
  220. __dec_zone_state(page_zone(page), item);
  221. }
  222. /*
  223. * We only use atomic operations to update counters. So there is no need to
  224. * disable interrupts.
  225. */
  226. #define inc_zone_page_state __inc_zone_page_state
  227. #define dec_zone_page_state __dec_zone_page_state
  228. #define mod_zone_page_state __mod_zone_page_state
  229. static inline void refresh_cpu_vm_stats(int cpu) { }
  230. #endif
  231. #endif /* _LINUX_VMSTAT_H */