]>
Commit | Line | Data |
---|---|---|
f6ac2354 CL |
1 | #ifndef _LINUX_VMSTAT_H |
2 | #define _LINUX_VMSTAT_H | |
3 | ||
4 | #include <linux/types.h> | |
5 | #include <linux/percpu.h> | |
96177299 | 6 | #include <linux/mm.h> |
2244b95a CL |
7 | #include <linux/mmzone.h> |
8 | #include <asm/atomic.h> | |
f6ac2354 | 9 | |
f8891e5e | 10 | #ifdef CONFIG_VM_EVENT_COUNTERS |
f6ac2354 | 11 | /* |
f8891e5e | 12 | * Light weight per cpu counter implementation. |
f6ac2354 | 13 | * |
2aea4fb6 PJ |
14 | * Counters should only be incremented. You need to set EMBEDDED |
15 | * to disable VM_EVENT_COUNTERS. Things like procps (vmstat, | |
16 | * top, etc) use /proc/vmstat and depend on these counters. | |
f8891e5e CL |
17 | * |
18 | * Counters are handled completely inline. On many platforms the code | |
19 | * generated will simply be the increment of a global address. | |
f6ac2354 | 20 | */ |
f8891e5e | 21 | |
4b51d669 CL |
22 | #ifdef CONFIG_ZONE_DMA |
23 | #define DMA_ZONE(xx) xx##_DMA, | |
24 | #else | |
25 | #define DMA_ZONE(xx) | |
26 | #endif | |
27 | ||
27bf71c2 CL |
28 | #ifdef CONFIG_ZONE_DMA32 |
29 | #define DMA32_ZONE(xx) xx##_DMA32, | |
30 | #else | |
31 | #define DMA32_ZONE(xx) | |
32 | #endif | |
33 | ||
34 | #ifdef CONFIG_HIGHMEM | |
35 | #define HIGHMEM_ZONE(xx) , xx##_HIGH | |
36 | #else | |
37 | #define HIGHMEM_ZONE(xx) | |
38 | #endif | |
39 | ||
4b51d669 | 40 | #define FOR_ALL_ZONES(xx) DMA_ZONE(xx) DMA32_ZONE(xx) xx##_NORMAL HIGHMEM_ZONE(xx) |
f8891e5e CL |
41 | |
42 | enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, | |
43 | FOR_ALL_ZONES(PGALLOC), | |
44 | PGFREE, PGACTIVATE, PGDEACTIVATE, | |
45 | PGFAULT, PGMAJFAULT, | |
46 | FOR_ALL_ZONES(PGREFILL), | |
47 | FOR_ALL_ZONES(PGSTEAL), | |
48 | FOR_ALL_ZONES(PGSCAN_KSWAPD), | |
49 | FOR_ALL_ZONES(PGSCAN_DIRECT), | |
50 | PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL, | |
51 | PAGEOUTRUN, ALLOCSTALL, PGROTATED, | |
52 | NR_VM_EVENT_ITEMS | |
53 | }; | |
54 | ||
55 | struct vm_event_state { | |
56 | unsigned long event[NR_VM_EVENT_ITEMS]; | |
f6ac2354 CL |
57 | }; |
58 | ||
f8891e5e CL |
59 | DECLARE_PER_CPU(struct vm_event_state, vm_event_states); |
60 | ||
61 | static inline void __count_vm_event(enum vm_event_item item) | |
62 | { | |
38cbcdc0 | 63 | __get_cpu_var(vm_event_states).event[item]++; |
f8891e5e CL |
64 | } |
65 | ||
66 | static inline void count_vm_event(enum vm_event_item item) | |
67 | { | |
38cbcdc0 | 68 | get_cpu_var(vm_event_states).event[item]++; |
f8891e5e CL |
69 | put_cpu(); |
70 | } | |
71 | ||
72 | static inline void __count_vm_events(enum vm_event_item item, long delta) | |
73 | { | |
38cbcdc0 | 74 | __get_cpu_var(vm_event_states).event[item] += delta; |
f8891e5e CL |
75 | } |
76 | ||
77 | static inline void count_vm_events(enum vm_event_item item, long delta) | |
78 | { | |
38cbcdc0 | 79 | get_cpu_var(vm_event_states).event[item] += delta; |
f8891e5e CL |
80 | put_cpu(); |
81 | } | |
82 | ||
83 | extern void all_vm_events(unsigned long *); | |
e903387f | 84 | #ifdef CONFIG_HOTPLUG |
f8891e5e | 85 | extern void vm_events_fold_cpu(int cpu); |
e903387f MD |
86 | #else |
87 | static inline void vm_events_fold_cpu(int cpu) | |
88 | { | |
89 | } | |
90 | #endif | |
f8891e5e CL |
91 | |
92 | #else | |
93 | ||
94 | /* Disable counters */ | |
95 | #define get_cpu_vm_events(e) 0L | |
96 | #define count_vm_event(e) do { } while (0) | |
97 | #define count_vm_events(e,d) do { } while (0) | |
98 | #define __count_vm_event(e) do { } while (0) | |
99 | #define __count_vm_events(e,d) do { } while (0) | |
100 | #define vm_events_fold_cpu(x) do { } while (0) | |
101 | ||
102 | #endif /* CONFIG_VM_EVENT_COUNTERS */ | |
103 | ||
104 | #define __count_zone_vm_events(item, zone, delta) \ | |
4b51d669 CL |
105 | __count_vm_events(item##_NORMAL - ZONE_NORMAL + \ |
106 | zone_idx(zone), delta) | |
f6ac2354 | 107 | |
2244b95a CL |
108 | /* |
109 | * Zone based page accounting with per cpu differentials. | |
110 | */ | |
111 | extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; | |
112 | ||
113 | static inline void zone_page_state_add(long x, struct zone *zone, | |
114 | enum zone_stat_item item) | |
115 | { | |
116 | atomic_long_add(x, &zone->vm_stat[item]); | |
117 | atomic_long_add(x, &vm_stat[item]); | |
118 | } | |
119 | ||
120 | static inline unsigned long global_page_state(enum zone_stat_item item) | |
121 | { | |
122 | long x = atomic_long_read(&vm_stat[item]); | |
123 | #ifdef CONFIG_SMP | |
124 | if (x < 0) | |
125 | x = 0; | |
126 | #endif | |
127 | return x; | |
128 | } | |
129 | ||
130 | static inline unsigned long zone_page_state(struct zone *zone, | |
131 | enum zone_stat_item item) | |
132 | { | |
133 | long x = atomic_long_read(&zone->vm_stat[item]); | |
134 | #ifdef CONFIG_SMP | |
135 | if (x < 0) | |
136 | x = 0; | |
137 | #endif | |
138 | return x; | |
139 | } | |
140 | ||
141 | #ifdef CONFIG_NUMA | |
142 | /* | |
143 | * Determine the per node value of a stat item. This function | |
144 | * is called frequently in a NUMA machine, so try to be as | |
145 | * frugal as possible. | |
146 | */ | |
147 | static inline unsigned long node_page_state(int node, | |
148 | enum zone_stat_item item) | |
149 | { | |
150 | struct zone *zones = NODE_DATA(node)->node_zones; | |
151 | ||
152 | return | |
4b51d669 CL |
153 | #ifdef CONFIG_ZONE_DMA |
154 | zone_page_state(&zones[ZONE_DMA], item) + | |
155 | #endif | |
fb0e7942 | 156 | #ifdef CONFIG_ZONE_DMA32 |
2244b95a CL |
157 | zone_page_state(&zones[ZONE_DMA32], item) + |
158 | #endif | |
2244b95a CL |
159 | #ifdef CONFIG_HIGHMEM |
160 | zone_page_state(&zones[ZONE_HIGHMEM], item) + | |
161 | #endif | |
4b51d669 | 162 | zone_page_state(&zones[ZONE_NORMAL], item); |
2244b95a | 163 | } |
ca889e6c CL |
164 | |
165 | extern void zone_statistics(struct zonelist *, struct zone *); | |
166 | ||
2244b95a | 167 | #else |
ca889e6c | 168 | |
2244b95a | 169 | #define node_page_state(node, item) global_page_state(item) |
ca889e6c CL |
170 | #define zone_statistics(_zl,_z) do { } while (0) |
171 | ||
172 | #endif /* CONFIG_NUMA */ | |
2244b95a CL |
173 | |
174 | #define __add_zone_page_state(__z, __i, __d) \ | |
175 | __mod_zone_page_state(__z, __i, __d) | |
176 | #define __sub_zone_page_state(__z, __i, __d) \ | |
177 | __mod_zone_page_state(__z, __i,-(__d)) | |
178 | ||
179 | #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d) | |
180 | #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d)) | |
181 | ||
182 | static inline void zap_zone_vm_stats(struct zone *zone) | |
183 | { | |
184 | memset(zone->vm_stat, 0, sizeof(zone->vm_stat)); | |
185 | } | |
186 | ||
ca889e6c CL |
187 | extern void inc_zone_state(struct zone *, enum zone_stat_item); |
188 | ||
2244b95a CL |
189 | #ifdef CONFIG_SMP |
190 | void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int); | |
191 | void __inc_zone_page_state(struct page *, enum zone_stat_item); | |
192 | void __dec_zone_page_state(struct page *, enum zone_stat_item); | |
f6ac2354 | 193 | |
2244b95a CL |
194 | void mod_zone_page_state(struct zone *, enum zone_stat_item, int); |
195 | void inc_zone_page_state(struct page *, enum zone_stat_item); | |
196 | void dec_zone_page_state(struct page *, enum zone_stat_item); | |
197 | ||
198 | extern void inc_zone_state(struct zone *, enum zone_stat_item); | |
c8785385 CL |
199 | extern void __inc_zone_state(struct zone *, enum zone_stat_item); |
200 | extern void dec_zone_state(struct zone *, enum zone_stat_item); | |
201 | extern void __dec_zone_state(struct zone *, enum zone_stat_item); | |
2244b95a CL |
202 | |
203 | void refresh_cpu_vm_stats(int); | |
204 | void refresh_vm_stats(void); | |
205 | ||
206 | #else /* CONFIG_SMP */ | |
207 | ||
208 | /* | |
209 | * We do not maintain differentials in a single processor configuration. | |
210 | * The functions directly modify the zone and global counters. | |
211 | */ | |
212 | static inline void __mod_zone_page_state(struct zone *zone, | |
213 | enum zone_stat_item item, int delta) | |
214 | { | |
215 | zone_page_state_add(delta, zone, item); | |
216 | } | |
217 | ||
7f4599e9 CL |
218 | static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item) |
219 | { | |
220 | atomic_long_inc(&zone->vm_stat[item]); | |
221 | atomic_long_inc(&vm_stat[item]); | |
222 | } | |
223 | ||
2244b95a CL |
224 | static inline void __inc_zone_page_state(struct page *page, |
225 | enum zone_stat_item item) | |
226 | { | |
7f4599e9 | 227 | __inc_zone_state(page_zone(page), item); |
2244b95a CL |
228 | } |
229 | ||
c8785385 CL |
230 | static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item) |
231 | { | |
232 | atomic_long_dec(&zone->vm_stat[item]); | |
233 | atomic_long_dec(&vm_stat[item]); | |
234 | } | |
235 | ||
2244b95a CL |
236 | static inline void __dec_zone_page_state(struct page *page, |
237 | enum zone_stat_item item) | |
238 | { | |
239 | atomic_long_dec(&page_zone(page)->vm_stat[item]); | |
240 | atomic_long_dec(&vm_stat[item]); | |
241 | } | |
242 | ||
243 | /* | |
244 | * We only use atomic operations to update counters. So there is no need to | |
245 | * disable interrupts. | |
246 | */ | |
247 | #define inc_zone_page_state __inc_zone_page_state | |
248 | #define dec_zone_page_state __dec_zone_page_state | |
249 | #define mod_zone_page_state __mod_zone_page_state | |
250 | ||
251 | static inline void refresh_cpu_vm_stats(int cpu) { } | |
252 | static inline void refresh_vm_stats(void) { } | |
253 | #endif | |
254 | ||
255 | #endif /* _LINUX_VMSTAT_H */ |