vmstat.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 <linux/vm_event_item.h>
  8. #include <linux/atomic.h>
  9. extern int sysctl_stat_interval;
  10. #ifdef CONFIG_VM_EVENT_COUNTERS
  11. /*
  12. * Light weight per cpu counter implementation.
  13. *
  14. * Counters should only be incremented and no critical kernel component
  15. * should rely on the counter values.
  16. *
  17. * Counters are handled completely inline. On many platforms the code
  18. * generated will simply be the increment of a global address.
  19. */
  20. struct vm_event_state {
  21. unsigned long event[NR_VM_EVENT_ITEMS];
  22. };
  23. DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
  24. static inline void __count_vm_event(enum vm_event_item item)
  25. {
  26. __this_cpu_inc(vm_event_states.event[item]);
  27. }
  28. static inline void count_vm_event(enum vm_event_item item)
  29. {
  30. this_cpu_inc(vm_event_states.event[item]);
  31. }
  32. static inline void __count_vm_events(enum vm_event_item item, long delta)
  33. {
  34. __this_cpu_add(vm_event_states.event[item], delta);
  35. }
  36. static inline void count_vm_events(enum vm_event_item item, long delta)
  37. {
  38. this_cpu_add(vm_event_states.event[item], delta);
  39. }
  40. extern void all_vm_events(unsigned long *);
  41. extern void vm_events_fold_cpu(int cpu);
  42. #else
  43. /* Disable counters */
  44. static inline void count_vm_event(enum vm_event_item item)
  45. {
  46. }
  47. static inline void count_vm_events(enum vm_event_item item, long delta)
  48. {
  49. }
  50. static inline void __count_vm_event(enum vm_event_item item)
  51. {
  52. }
  53. static inline void __count_vm_events(enum vm_event_item item, long delta)
  54. {
  55. }
  56. static inline void all_vm_events(unsigned long *ret)
  57. {
  58. }
  59. static inline void vm_events_fold_cpu(int cpu)
  60. {
  61. }
  62. #endif /* CONFIG_VM_EVENT_COUNTERS */
  63. #ifdef CONFIG_NUMA_BALANCING
  64. #define count_vm_numa_event(x) count_vm_event(x)
  65. #define count_vm_numa_events(x, y) count_vm_events(x, y)
  66. #else
  67. #define count_vm_numa_event(x) do {} while (0)
  68. #define count_vm_numa_events(x, y) do { (void)(y); } while (0)
  69. #endif /* CONFIG_NUMA_BALANCING */
  70. #define __count_zone_vm_events(item, zone, delta) \
  71. __count_vm_events(item##_NORMAL - ZONE_NORMAL + \
  72. zone_idx(zone), delta)
  73. /*
  74. * Zone based page accounting with per cpu differentials.
  75. */
  76. extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
  77. static inline void zone_page_state_add(long x, struct zone *zone,
  78. enum zone_stat_item item)
  79. {
  80. atomic_long_add(x, &zone->vm_stat[item]);
  81. atomic_long_add(x, &vm_stat[item]);
  82. }
  83. static inline unsigned long global_page_state(enum zone_stat_item item)
  84. {
  85. long x = atomic_long_read(&vm_stat[item]);
  86. #ifdef CONFIG_SMP
  87. if (x < 0)
  88. x = 0;
  89. #endif
  90. return x;
  91. }
  92. static inline unsigned long zone_page_state(struct zone *zone,
  93. enum zone_stat_item item)
  94. {
  95. long x = atomic_long_read(&zone->vm_stat[item]);
  96. #ifdef CONFIG_SMP
  97. if (x < 0)
  98. x = 0;
  99. #endif
  100. return x;
  101. }
  102. /*
  103. * More accurate version that also considers the currently pending
  104. * deltas. For that we need to loop over all cpus to find the current
  105. * deltas. There is no synchronization so the result cannot be
  106. * exactly accurate either.
  107. */
  108. static inline unsigned long zone_page_state_snapshot(struct zone *zone,
  109. enum zone_stat_item item)
  110. {
  111. long x = atomic_long_read(&zone->vm_stat[item]);
  112. #ifdef CONFIG_SMP
  113. int cpu;
  114. for_each_online_cpu(cpu)
  115. x += per_cpu_ptr(zone->pageset, cpu)->vm_stat_diff[item];
  116. if (x < 0)
  117. x = 0;
  118. #endif
  119. return x;
  120. }
  121. extern unsigned long global_reclaimable_pages(void);
  122. #ifdef CONFIG_NUMA
  123. /*
  124. * Determine the per node value of a stat item. This function
  125. * is called frequently in a NUMA machine, so try to be as
  126. * frugal as possible.
  127. */
  128. static inline unsigned long node_page_state(int node,
  129. enum zone_stat_item item)
  130. {
  131. struct zone *zones = NODE_DATA(node)->node_zones;
  132. return
  133. #ifdef CONFIG_ZONE_DMA
  134. zone_page_state(&zones[ZONE_DMA], item) +
  135. #endif
  136. #ifdef CONFIG_ZONE_DMA32
  137. zone_page_state(&zones[ZONE_DMA32], item) +
  138. #endif
  139. #ifdef CONFIG_HIGHMEM
  140. zone_page_state(&zones[ZONE_HIGHMEM], item) +
  141. #endif
  142. zone_page_state(&zones[ZONE_NORMAL], item) +
  143. zone_page_state(&zones[ZONE_MOVABLE], item);
  144. }
  145. extern void zone_statistics(struct zone *, struct zone *, gfp_t gfp);
  146. #else
  147. #define node_page_state(node, item) global_page_state(item)
  148. #define zone_statistics(_zl, _z, gfp) do { } while (0)
  149. #endif /* CONFIG_NUMA */
  150. #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d)
  151. #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d))
  152. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  153. #ifdef CONFIG_SMP
  154. void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
  155. void __inc_zone_page_state(struct page *, enum zone_stat_item);
  156. void __dec_zone_page_state(struct page *, enum zone_stat_item);
  157. void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
  158. void inc_zone_page_state(struct page *, enum zone_stat_item);
  159. void dec_zone_page_state(struct page *, enum zone_stat_item);
  160. extern void inc_zone_state(struct zone *, enum zone_stat_item);
  161. extern void __inc_zone_state(struct zone *, enum zone_stat_item);
  162. extern void dec_zone_state(struct zone *, enum zone_stat_item);
  163. extern void __dec_zone_state(struct zone *, enum zone_stat_item);
  164. void cpu_vm_stats_fold(int cpu);
  165. void refresh_zone_stat_thresholds(void);
  166. void drain_zonestat(struct zone *zone, struct per_cpu_pageset *);
  167. int calculate_pressure_threshold(struct zone *zone);
  168. int calculate_normal_threshold(struct zone *zone);
  169. void set_pgdat_percpu_threshold(pg_data_t *pgdat,
  170. int (*calculate_pressure)(struct zone *));
  171. #else /* CONFIG_SMP */
  172. /*
  173. * We do not maintain differentials in a single processor configuration.
  174. * The functions directly modify the zone and global counters.
  175. */
  176. static inline void __mod_zone_page_state(struct zone *zone,
  177. enum zone_stat_item item, int delta)
  178. {
  179. zone_page_state_add(delta, zone, item);
  180. }
  181. static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  182. {
  183. atomic_long_inc(&zone->vm_stat[item]);
  184. atomic_long_inc(&vm_stat[item]);
  185. }
  186. static inline void __inc_zone_page_state(struct page *page,
  187. enum zone_stat_item item)
  188. {
  189. __inc_zone_state(page_zone(page), item);
  190. }
  191. static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  192. {
  193. atomic_long_dec(&zone->vm_stat[item]);
  194. atomic_long_dec(&vm_stat[item]);
  195. }
  196. static inline void __dec_zone_page_state(struct page *page,
  197. enum zone_stat_item item)
  198. {
  199. __dec_zone_state(page_zone(page), item);
  200. }
  201. /*
  202. * We only use atomic operations to update counters. So there is no need to
  203. * disable interrupts.
  204. */
  205. #define inc_zone_page_state __inc_zone_page_state
  206. #define dec_zone_page_state __dec_zone_page_state
  207. #define mod_zone_page_state __mod_zone_page_state
  208. #define set_pgdat_percpu_threshold(pgdat, callback) { }
  209. static inline void refresh_cpu_vm_stats(int cpu) { }
  210. static inline void refresh_zone_stat_thresholds(void) { }
  211. static inline void cpu_vm_stats_fold(int cpu) { }
  212. static inline void drain_zonestat(struct zone *zone,
  213. struct per_cpu_pageset *pset) { }
  214. #endif /* CONFIG_SMP */
  215. static inline void __mod_zone_freepage_state(struct zone *zone, int nr_pages,
  216. int migratetype)
  217. {
  218. __mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
  219. if (is_migrate_cma(migratetype))
  220. __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
  221. }
  222. extern const char * const vmstat_text[];
  223. #endif /* _LINUX_VMSTAT_H */