vmstat.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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)
  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. PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL,
  33. PAGEOUTRUN, ALLOCSTALL, PGROTATED,
  34. NR_VM_EVENT_ITEMS
  35. };
  36. #ifdef CONFIG_VM_EVENT_COUNTERS
  37. /*
  38. * Light weight per cpu counter implementation.
  39. *
  40. * Counters should only be incremented and no critical kernel component
  41. * should rely on the counter values.
  42. *
  43. * Counters are handled completely inline. On many platforms the code
  44. * generated will simply be the increment of a global address.
  45. */
  46. struct vm_event_state {
  47. unsigned long event[NR_VM_EVENT_ITEMS];
  48. };
  49. DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
  50. static inline void __count_vm_event(enum vm_event_item item)
  51. {
  52. __get_cpu_var(vm_event_states).event[item]++;
  53. }
  54. static inline void count_vm_event(enum vm_event_item item)
  55. {
  56. get_cpu_var(vm_event_states).event[item]++;
  57. put_cpu();
  58. }
  59. static inline void __count_vm_events(enum vm_event_item item, long delta)
  60. {
  61. __get_cpu_var(vm_event_states).event[item] += delta;
  62. }
  63. static inline void count_vm_events(enum vm_event_item item, long delta)
  64. {
  65. get_cpu_var(vm_event_states).event[item] += delta;
  66. put_cpu();
  67. }
  68. extern void all_vm_events(unsigned long *);
  69. #ifdef CONFIG_HOTPLUG
  70. extern void vm_events_fold_cpu(int cpu);
  71. #else
  72. static inline void vm_events_fold_cpu(int cpu)
  73. {
  74. }
  75. #endif
  76. #else
  77. /* Disable counters */
  78. static inline void count_vm_event(enum vm_event_item item)
  79. {
  80. }
  81. static inline void count_vm_events(enum vm_event_item item, long delta)
  82. {
  83. }
  84. static inline void __count_vm_event(enum vm_event_item item)
  85. {
  86. }
  87. static inline void __count_vm_events(enum vm_event_item item, long delta)
  88. {
  89. }
  90. static inline void all_vm_events(unsigned long *ret)
  91. {
  92. }
  93. static inline void vm_events_fold_cpu(int cpu)
  94. {
  95. }
  96. #endif /* CONFIG_VM_EVENT_COUNTERS */
  97. #define __count_zone_vm_events(item, zone, delta) \
  98. __count_vm_events(item##_NORMAL - ZONE_NORMAL + \
  99. zone_idx(zone), delta)
  100. /*
  101. * Zone based page accounting with per cpu differentials.
  102. */
  103. extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  104. static inline void zone_page_state_add(long x, struct zone *zone,
  105. enum zone_stat_item item)
  106. {
  107. atomic_long_add(x, &zone->vm_stat[item]);
  108. atomic_long_add(x, &vm_stat[item]);
  109. }
  110. static inline unsigned long global_page_state(enum zone_stat_item item)
  111. {
  112. long x = atomic_long_read(&vm_stat[item]);
  113. #ifdef CONFIG_SMP
  114. if (x < 0)
  115. x = 0;
  116. #endif
  117. return x;
  118. }
  119. static inline unsigned long zone_page_state(struct zone *zone,
  120. enum zone_stat_item item)
  121. {
  122. long x = atomic_long_read(&zone->vm_stat[item]);
  123. #ifdef CONFIG_SMP
  124. if (x < 0)
  125. x = 0;
  126. #endif
  127. return x;
  128. }
  129. #ifdef CONFIG_NUMA
  130. /*
  131. * Determine the per node value of a stat item. This function
  132. * is called frequently in a NUMA machine, so try to be as
  133. * frugal as possible.
  134. */
  135. static inline unsigned long node_page_state(int node,
  136. enum zone_stat_item item)
  137. {
  138. struct zone *zones = NODE_DATA(node)->node_zones;
  139. return
  140. #ifdef CONFIG_ZONE_DMA
  141. zone_page_state(&zones[ZONE_DMA], item) +
  142. #endif
  143. #ifdef CONFIG_ZONE_DMA32
  144. zone_page_state(&zones[ZONE_DMA32], item) +
  145. #endif
  146. #ifdef CONFIG_HIGHMEM
  147. zone_page_state(&zones[ZONE_HIGHMEM], item) +
  148. #endif
  149. zone_page_state(&zones[ZONE_NORMAL], item);
  150. }
  151. extern void zone_statistics(struct zonelist *, struct zone *);
  152. #else
  153. #define node_page_state(node, item) global_page_state(item)
  154. #define zone_statistics(_zl,_z) do { } while (0)
  155. #endif /* CONFIG_NUMA */
  156. #define __add_zone_page_state(__z, __i, __d) \
  157. __mod_zone_page_state(__z, __i, __d)
  158. #define __sub_zone_page_state(__z, __i, __d) \
  159. __mod_zone_page_state(__z, __i,-(__d))
  160. #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d)
  161. #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d))
  162. static inline void zap_zone_vm_stats(struct zone *zone)
  163. {
  164. memset(zone->vm_stat, 0, sizeof(zone->vm_stat));
  165. }
  166. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  167. #ifdef CONFIG_SMP
  168. void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
  169. void __inc_zone_page_state(struct page *, enum zone_stat_item);
  170. void __dec_zone_page_state(struct page *, enum zone_stat_item);
  171. void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
  172. void inc_zone_page_state(struct page *, enum zone_stat_item);
  173. void dec_zone_page_state(struct page *, enum zone_stat_item);
  174. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  175. extern void __inc_zone_state(struct zone *, enum zone_stat_item);
  176. extern void dec_zone_state(struct zone *, enum zone_stat_item);
  177. extern void __dec_zone_state(struct zone *, enum zone_stat_item);
  178. void refresh_cpu_vm_stats(int);
  179. void refresh_vm_stats(void);
  180. #else /* CONFIG_SMP */
  181. /*
  182. * We do not maintain differentials in a single processor configuration.
  183. * The functions directly modify the zone and global counters.
  184. */
  185. static inline void __mod_zone_page_state(struct zone *zone,
  186. enum zone_stat_item item, int delta)
  187. {
  188. zone_page_state_add(delta, zone, item);
  189. }
  190. static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  191. {
  192. atomic_long_inc(&zone->vm_stat[item]);
  193. atomic_long_inc(&vm_stat[item]);
  194. }
  195. static inline void __inc_zone_page_state(struct page *page,
  196. enum zone_stat_item item)
  197. {
  198. __inc_zone_state(page_zone(page), item);
  199. }
  200. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  201. {
  202. atomic_long_dec(&zone->vm_stat[item]);
  203. atomic_long_dec(&vm_stat[item]);
  204. }
  205. static inline void __dec_zone_page_state(struct page *page,
  206. enum zone_stat_item item)
  207. {
  208. atomic_long_dec(&page_zone(page)->vm_stat[item]);
  209. atomic_long_dec(&vm_stat[item]);
  210. }
  211. /*
  212. * We only use atomic operations to update counters. So there is no need to
  213. * disable interrupts.
  214. */
  215. #define inc_zone_page_state __inc_zone_page_state
  216. #define dec_zone_page_state __dec_zone_page_state
  217. #define mod_zone_page_state __mod_zone_page_state
  218. static inline void refresh_cpu_vm_stats(int cpu) { }
  219. static inline void refresh_vm_stats(void) { }
  220. #endif
  221. #endif /* _LINUX_VMSTAT_H */