repo init
[linux-rt-nao.git] / include / linux / vmstat.h
blob047e1ee69514a9b54df8e65978dd9f7a30a18078
1 #ifndef _LINUX_VMSTAT_H
2 #define _LINUX_VMSTAT_H
4 #include <linux/types.h>
5 #include <linux/percpu.h>
6 #include <linux/mm.h>
7 #include <linux/mmzone.h>
8 #include <asm/atomic.h>
10 #ifdef CONFIG_ZONE_DMA
11 #define DMA_ZONE(xx) xx##_DMA,
12 #else
13 #define DMA_ZONE(xx)
14 #endif
16 #ifdef CONFIG_ZONE_DMA32
17 #define DMA32_ZONE(xx) xx##_DMA32,
18 #else
19 #define DMA32_ZONE(xx)
20 #endif
22 #ifdef CONFIG_HIGHMEM
23 #define HIGHMEM_ZONE(xx) , xx##_HIGH
24 #else
25 #define HIGHMEM_ZONE(xx)
26 #endif
29 #define FOR_ALL_ZONES(xx) DMA_ZONE(xx) DMA32_ZONE(xx) xx##_NORMAL HIGHMEM_ZONE(xx) , xx##_MOVABLE
31 enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
32 FOR_ALL_ZONES(PGALLOC),
33 PGFREE, PGACTIVATE, PGDEACTIVATE,
34 PGFAULT, PGMAJFAULT,
35 FOR_ALL_ZONES(PGREFILL),
36 FOR_ALL_ZONES(PGSTEAL),
37 FOR_ALL_ZONES(PGSCAN_KSWAPD),
38 FOR_ALL_ZONES(PGSCAN_DIRECT),
39 PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL,
40 PAGEOUTRUN, ALLOCSTALL, PGROTATED,
41 #ifdef CONFIG_HUGETLB_PAGE
42 HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL,
43 #endif
44 #ifdef CONFIG_UNEVICTABLE_LRU
45 UNEVICTABLE_PGCULLED, /* culled to noreclaim list */
46 UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */
47 UNEVICTABLE_PGRESCUED, /* rescued from noreclaim list */
48 UNEVICTABLE_PGMLOCKED,
49 UNEVICTABLE_PGMUNLOCKED,
50 UNEVICTABLE_PGCLEARED, /* on COW, page truncate */
51 UNEVICTABLE_PGSTRANDED, /* unable to isolate on unlock */
52 UNEVICTABLE_MLOCKFREED,
53 #endif
54 NR_VM_EVENT_ITEMS
57 extern int sysctl_stat_interval;
59 #ifdef CONFIG_VM_EVENT_COUNTERS
61 * Light weight per cpu counter implementation.
63 * Counters should only be incremented and no critical kernel component
64 * should rely on the counter values.
66 * Counters are handled completely inline. On many platforms the code
67 * generated will simply be the increment of a global address.
70 struct vm_event_state {
71 unsigned long event[NR_VM_EVENT_ITEMS];
74 DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
76 static inline void __count_vm_event(enum vm_event_item item)
78 #ifdef CONFIG_PREEMPT_RT
79 get_cpu_var(vm_event_states).event[item]++;
80 put_cpu();
81 #else
82 __get_cpu_var(vm_event_states).event[item]++;
83 #endif
86 static inline void count_vm_event(enum vm_event_item item)
88 get_cpu_var(vm_event_states).event[item]++;
89 put_cpu();
92 static inline void __count_vm_events(enum vm_event_item item, long delta)
94 #ifdef CONFIG_PREEMPT_RT
95 get_cpu_var(vm_event_states).event[item] += delta;
96 put_cpu();
97 #else
98 __get_cpu_var(vm_event_states).event[item] += delta;
99 #endif
102 static inline void count_vm_events(enum vm_event_item item, long delta)
104 get_cpu_var(vm_event_states).event[item] += delta;
105 put_cpu();
108 extern void all_vm_events(unsigned long *);
109 #ifdef CONFIG_HOTPLUG
110 extern void vm_events_fold_cpu(int cpu);
111 #else
112 static inline void vm_events_fold_cpu(int cpu)
115 #endif
117 #else
119 /* Disable counters */
120 static inline void count_vm_event(enum vm_event_item item)
123 static inline void count_vm_events(enum vm_event_item item, long delta)
126 static inline void __count_vm_event(enum vm_event_item item)
129 static inline void __count_vm_events(enum vm_event_item item, long delta)
132 static inline void all_vm_events(unsigned long *ret)
135 static inline void vm_events_fold_cpu(int cpu)
139 #endif /* CONFIG_VM_EVENT_COUNTERS */
141 #define __count_zone_vm_events(item, zone, delta) \
142 __count_vm_events(item##_NORMAL - ZONE_NORMAL + \
143 zone_idx(zone), delta)
146 * Zone based page accounting with per cpu differentials.
148 extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
150 static inline void zone_page_state_add(long x, struct zone *zone,
151 enum zone_stat_item item)
153 atomic_long_add(x, &zone->vm_stat[item]);
154 atomic_long_add(x, &vm_stat[item]);
157 static inline unsigned long global_page_state(enum zone_stat_item item)
159 long x = atomic_long_read(&vm_stat[item]);
160 #ifdef CONFIG_SMP
161 if (x < 0)
162 x = 0;
163 #endif
164 return x;
167 static inline unsigned long zone_page_state(struct zone *zone,
168 enum zone_stat_item item)
170 long x = atomic_long_read(&zone->vm_stat[item]);
171 #ifdef CONFIG_SMP
172 if (x < 0)
173 x = 0;
174 #endif
175 return x;
178 extern unsigned long global_lru_pages(void);
180 static inline unsigned long zone_lru_pages(struct zone *zone)
182 return (zone_page_state(zone, NR_ACTIVE_ANON)
183 + zone_page_state(zone, NR_ACTIVE_FILE)
184 + zone_page_state(zone, NR_INACTIVE_ANON)
185 + zone_page_state(zone, NR_INACTIVE_FILE));
188 #ifdef CONFIG_NUMA
190 * Determine the per node value of a stat item. This function
191 * is called frequently in a NUMA machine, so try to be as
192 * frugal as possible.
194 static inline unsigned long node_page_state(int node,
195 enum zone_stat_item item)
197 struct zone *zones = NODE_DATA(node)->node_zones;
199 return
200 #ifdef CONFIG_ZONE_DMA
201 zone_page_state(&zones[ZONE_DMA], item) +
202 #endif
203 #ifdef CONFIG_ZONE_DMA32
204 zone_page_state(&zones[ZONE_DMA32], item) +
205 #endif
206 #ifdef CONFIG_HIGHMEM
207 zone_page_state(&zones[ZONE_HIGHMEM], item) +
208 #endif
209 zone_page_state(&zones[ZONE_NORMAL], item) +
210 zone_page_state(&zones[ZONE_MOVABLE], item);
213 extern void zone_statistics(struct zone *, struct zone *);
215 #else
217 #define node_page_state(node, item) global_page_state(item)
218 #define zone_statistics(_zl,_z) do { } while (0)
220 #endif /* CONFIG_NUMA */
222 #define __add_zone_page_state(__z, __i, __d) \
223 __mod_zone_page_state(__z, __i, __d)
224 #define __sub_zone_page_state(__z, __i, __d) \
225 __mod_zone_page_state(__z, __i,-(__d))
227 #define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d)
228 #define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d))
230 static inline void zap_zone_vm_stats(struct zone *zone)
232 memset(zone->vm_stat, 0, sizeof(zone->vm_stat));
235 extern void inc_zone_state(struct zone *, enum zone_stat_item);
237 #ifdef CONFIG_SMP
238 void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
239 void __inc_zone_page_state(struct page *, enum zone_stat_item);
240 void __dec_zone_page_state(struct page *, enum zone_stat_item);
242 void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
243 void inc_zone_page_state(struct page *, enum zone_stat_item);
244 void dec_zone_page_state(struct page *, enum zone_stat_item);
246 extern void inc_zone_state(struct zone *, enum zone_stat_item);
247 extern void __inc_zone_state(struct zone *, enum zone_stat_item);
248 extern void dec_zone_state(struct zone *, enum zone_stat_item);
249 extern void __dec_zone_state(struct zone *, enum zone_stat_item);
251 void refresh_cpu_vm_stats(int);
252 #else /* CONFIG_SMP */
255 * We do not maintain differentials in a single processor configuration.
256 * The functions directly modify the zone and global counters.
258 static inline void __mod_zone_page_state(struct zone *zone,
259 enum zone_stat_item item, int delta)
261 zone_page_state_add(delta, zone, item);
264 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
266 atomic_long_inc(&zone->vm_stat[item]);
267 atomic_long_inc(&vm_stat[item]);
270 static inline void __inc_zone_page_state(struct page *page,
271 enum zone_stat_item item)
273 __inc_zone_state(page_zone(page), item);
276 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
278 atomic_long_dec(&zone->vm_stat[item]);
279 atomic_long_dec(&vm_stat[item]);
282 static inline void __dec_zone_page_state(struct page *page,
283 enum zone_stat_item item)
285 __dec_zone_state(page_zone(page), item);
289 * We only use atomic operations to update counters. So there is no need to
290 * disable interrupts.
292 #define inc_zone_page_state __inc_zone_page_state
293 #define dec_zone_page_state __dec_zone_page_state
294 #define mod_zone_page_state __mod_zone_page_state
296 static inline void refresh_cpu_vm_stats(int cpu) { }
297 #endif
299 #endif /* _LINUX_VMSTAT_H */