Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_VMSTAT_H |
| 2 | #define _LINUX_VMSTAT_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/percpu.h> |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 6 | #include <linux/config.h> |
| 7 | #include <linux/mmzone.h> |
| 8 | #include <asm/atomic.h> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 9 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 10 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 11 | /* |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 12 | * Light weight per cpu counter implementation. |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 13 | * |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 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. |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 19 | */ |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 20 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 21 | #define FOR_ALL_ZONES(x) x##_DMA, x##_DMA32, x##_NORMAL, x##_HIGH |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 22 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 23 | enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, |
| 24 | FOR_ALL_ZONES(PGALLOC), |
| 25 | PGFREE, PGACTIVATE, PGDEACTIVATE, |
| 26 | PGFAULT, PGMAJFAULT, |
| 27 | FOR_ALL_ZONES(PGREFILL), |
| 28 | FOR_ALL_ZONES(PGSTEAL), |
| 29 | FOR_ALL_ZONES(PGSCAN_KSWAPD), |
| 30 | FOR_ALL_ZONES(PGSCAN_DIRECT), |
| 31 | PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL, |
| 32 | PAGEOUTRUN, ALLOCSTALL, PGROTATED, |
| 33 | NR_VM_EVENT_ITEMS |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 36 | struct vm_event_state { |
| 37 | unsigned long event[NR_VM_EVENT_ITEMS]; |
| 38 | }; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 39 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 40 | DECLARE_PER_CPU(struct vm_event_state, vm_event_states); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 41 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 42 | static inline void __count_vm_event(enum vm_event_item item) |
| 43 | { |
Jan Blunck | 38cbcdc | 2006-08-05 12:14:14 -0700 | [diff] [blame] | 44 | __get_cpu_var(vm_event_states).event[item]++; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 45 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 46 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 47 | static inline void count_vm_event(enum vm_event_item item) |
| 48 | { |
Jan Blunck | 38cbcdc | 2006-08-05 12:14:14 -0700 | [diff] [blame] | 49 | get_cpu_var(vm_event_states).event[item]++; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 50 | put_cpu(); |
| 51 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 52 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 53 | static inline void __count_vm_events(enum vm_event_item item, long delta) |
| 54 | { |
Jan Blunck | 38cbcdc | 2006-08-05 12:14:14 -0700 | [diff] [blame] | 55 | __get_cpu_var(vm_event_states).event[item] += delta; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 56 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 57 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 58 | static inline void count_vm_events(enum vm_event_item item, long delta) |
| 59 | { |
Jan Blunck | 38cbcdc | 2006-08-05 12:14:14 -0700 | [diff] [blame] | 60 | get_cpu_var(vm_event_states).event[item] += delta; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 61 | put_cpu(); |
| 62 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 63 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 64 | extern void all_vm_events(unsigned long *); |
| 65 | extern void vm_events_fold_cpu(int cpu); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 66 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 67 | #else |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 68 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 69 | /* Disable counters */ |
| 70 | #define get_cpu_vm_events(e) 0L |
| 71 | #define count_vm_event(e) do { } while (0) |
| 72 | #define count_vm_events(e,d) do { } while (0) |
| 73 | #define __count_vm_event(e) do { } while (0) |
| 74 | #define __count_vm_events(e,d) do { } while (0) |
| 75 | #define vm_events_fold_cpu(x) do { } while (0) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 76 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 77 | #endif /* CONFIG_VM_EVENT_COUNTERS */ |
| 78 | |
| 79 | #define __count_zone_vm_events(item, zone, delta) \ |
| 80 | __count_vm_events(item##_DMA + zone_idx(zone), delta) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 81 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Zone based page accounting with per cpu differentials. |
| 84 | */ |
| 85 | extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 86 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 87 | static inline void zone_page_state_add(long x, struct zone *zone, |
| 88 | enum zone_stat_item item) |
| 89 | { |
| 90 | atomic_long_add(x, &zone->vm_stat[item]); |
| 91 | atomic_long_add(x, &vm_stat[item]); |
| 92 | } |
| 93 | |
| 94 | static inline unsigned long global_page_state(enum zone_stat_item item) |
| 95 | { |
| 96 | long x = atomic_long_read(&vm_stat[item]); |
| 97 | #ifdef CONFIG_SMP |
| 98 | if (x < 0) |
| 99 | x = 0; |
| 100 | #endif |
| 101 | return x; |
| 102 | } |
| 103 | |
| 104 | static inline unsigned long zone_page_state(struct zone *zone, |
| 105 | enum zone_stat_item item) |
| 106 | { |
| 107 | long x = atomic_long_read(&zone->vm_stat[item]); |
| 108 | #ifdef CONFIG_SMP |
| 109 | if (x < 0) |
| 110 | x = 0; |
| 111 | #endif |
| 112 | return x; |
| 113 | } |
| 114 | |
| 115 | #ifdef CONFIG_NUMA |
| 116 | /* |
| 117 | * Determine the per node value of a stat item. This function |
| 118 | * is called frequently in a NUMA machine, so try to be as |
| 119 | * frugal as possible. |
| 120 | */ |
| 121 | static inline unsigned long node_page_state(int node, |
| 122 | enum zone_stat_item item) |
| 123 | { |
| 124 | struct zone *zones = NODE_DATA(node)->node_zones; |
| 125 | |
| 126 | return |
| 127 | #ifndef CONFIG_DMA_IS_NORMAL |
| 128 | #if !defined(CONFIG_DMA_IS_DMA32) && BITS_PER_LONG >= 64 |
| 129 | zone_page_state(&zones[ZONE_DMA32], item) + |
| 130 | #endif |
| 131 | zone_page_state(&zones[ZONE_NORMAL], item) + |
| 132 | #endif |
| 133 | #ifdef CONFIG_HIGHMEM |
| 134 | zone_page_state(&zones[ZONE_HIGHMEM], item) + |
| 135 | #endif |
| 136 | zone_page_state(&zones[ZONE_DMA], item); |
| 137 | } |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 138 | |
| 139 | extern void zone_statistics(struct zonelist *, struct zone *); |
| 140 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 141 | #else |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 142 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 143 | #define node_page_state(node, item) global_page_state(item) |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 144 | #define zone_statistics(_zl,_z) do { } while (0) |
| 145 | |
| 146 | #endif /* CONFIG_NUMA */ |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 147 | |
| 148 | #define __add_zone_page_state(__z, __i, __d) \ |
| 149 | __mod_zone_page_state(__z, __i, __d) |
| 150 | #define __sub_zone_page_state(__z, __i, __d) \ |
| 151 | __mod_zone_page_state(__z, __i,-(__d)) |
| 152 | |
| 153 | #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d) |
| 154 | #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d)) |
| 155 | |
| 156 | static inline void zap_zone_vm_stats(struct zone *zone) |
| 157 | { |
| 158 | memset(zone->vm_stat, 0, sizeof(zone->vm_stat)); |
| 159 | } |
| 160 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 161 | extern void inc_zone_state(struct zone *, enum zone_stat_item); |
| 162 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 163 | #ifdef CONFIG_SMP |
| 164 | void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int); |
| 165 | void __inc_zone_page_state(struct page *, enum zone_stat_item); |
| 166 | void __dec_zone_page_state(struct page *, enum zone_stat_item); |
| 167 | |
| 168 | void mod_zone_page_state(struct zone *, enum zone_stat_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 | |
| 172 | extern void inc_zone_state(struct zone *, enum zone_stat_item); |
| 173 | |
| 174 | void refresh_cpu_vm_stats(int); |
| 175 | void refresh_vm_stats(void); |
| 176 | |
| 177 | #else /* CONFIG_SMP */ |
| 178 | |
| 179 | /* |
| 180 | * We do not maintain differentials in a single processor configuration. |
| 181 | * The functions directly modify the zone and global counters. |
| 182 | */ |
| 183 | static inline void __mod_zone_page_state(struct zone *zone, |
| 184 | enum zone_stat_item item, int delta) |
| 185 | { |
| 186 | zone_page_state_add(delta, zone, item); |
| 187 | } |
| 188 | |
Christoph Lameter | 7f4599e | 2006-07-10 04:44:30 -0700 | [diff] [blame] | 189 | static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item) |
| 190 | { |
| 191 | atomic_long_inc(&zone->vm_stat[item]); |
| 192 | atomic_long_inc(&vm_stat[item]); |
| 193 | } |
| 194 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 195 | static inline void __inc_zone_page_state(struct page *page, |
| 196 | enum zone_stat_item item) |
| 197 | { |
Christoph Lameter | 7f4599e | 2006-07-10 04:44:30 -0700 | [diff] [blame] | 198 | __inc_zone_state(page_zone(page), item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static inline void __dec_zone_page_state(struct page *page, |
| 202 | enum zone_stat_item item) |
| 203 | { |
| 204 | atomic_long_dec(&page_zone(page)->vm_stat[item]); |
| 205 | atomic_long_dec(&vm_stat[item]); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * We only use atomic operations to update counters. So there is no need to |
| 210 | * disable interrupts. |
| 211 | */ |
| 212 | #define inc_zone_page_state __inc_zone_page_state |
| 213 | #define dec_zone_page_state __dec_zone_page_state |
| 214 | #define mod_zone_page_state __mod_zone_page_state |
| 215 | |
| 216 | static inline void refresh_cpu_vm_stats(int cpu) { } |
| 217 | static inline void refresh_vm_stats(void) { } |
| 218 | #endif |
| 219 | |
| 220 | #endif /* _LINUX_VMSTAT_H */ |