blob: c8d55bcc09b91e9ccc049d8ea76ad7bbd26b3bb6 [file] [log] [blame]
Christoph Lameterf6ac2352006-06-30 01:55:32 -07001#ifndef _LINUX_VMSTAT_H
2#define _LINUX_VMSTAT_H
3
4#include <linux/types.h>
5#include <linux/percpu.h>
Christoph Lameter2244b952006-06-30 01:55:33 -07006#include <linux/mmzone.h>
7#include <asm/atomic.h>
Christoph Lameterf6ac2352006-06-30 01:55:32 -07008
Christoph Lameterf8891e52006-06-30 01:55:45 -07009#ifdef CONFIG_VM_EVENT_COUNTERS
Christoph Lameterf6ac2352006-06-30 01:55:32 -070010/*
Christoph Lameterf8891e52006-06-30 01:55:45 -070011 * Light weight per cpu counter implementation.
Christoph Lameterf6ac2352006-06-30 01:55:32 -070012 *
Paul Jackson2aea4fb2006-12-22 01:06:10 -080013 * Counters should only be incremented. You need to set EMBEDDED
14 * to disable VM_EVENT_COUNTERS. Things like procps (vmstat,
15 * top, etc) use /proc/vmstat and depend on these counters.
Christoph Lameterf8891e52006-06-30 01:55:45 -070016 *
17 * Counters are handled completely inline. On many platforms the code
18 * generated will simply be the increment of a global address.
Christoph Lameterf6ac2352006-06-30 01:55:32 -070019 */
Christoph Lameterf6ac2352006-06-30 01:55:32 -070020
Christoph Lameter27bf71c2006-09-25 23:31:15 -070021#ifdef CONFIG_ZONE_DMA32
22#define DMA32_ZONE(xx) xx##_DMA32,
23#else
24#define DMA32_ZONE(xx)
25#endif
26
27#ifdef CONFIG_HIGHMEM
28#define HIGHMEM_ZONE(xx) , xx##_HIGH
29#else
30#define HIGHMEM_ZONE(xx)
31#endif
32
33#define FOR_ALL_ZONES(xx) xx##_DMA, DMA32_ZONE(xx) xx##_NORMAL HIGHMEM_ZONE(xx)
Christoph Lameterf6ac2352006-06-30 01:55:32 -070034
Christoph Lameterf8891e52006-06-30 01:55:45 -070035enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
36 FOR_ALL_ZONES(PGALLOC),
37 PGFREE, PGACTIVATE, PGDEACTIVATE,
38 PGFAULT, PGMAJFAULT,
39 FOR_ALL_ZONES(PGREFILL),
40 FOR_ALL_ZONES(PGSTEAL),
41 FOR_ALL_ZONES(PGSCAN_KSWAPD),
42 FOR_ALL_ZONES(PGSCAN_DIRECT),
43 PGINODESTEAL, SLABS_SCANNED, KSWAPD_STEAL, KSWAPD_INODESTEAL,
44 PAGEOUTRUN, ALLOCSTALL, PGROTATED,
45 NR_VM_EVENT_ITEMS
Christoph Lameterf6ac2352006-06-30 01:55:32 -070046};
47
Christoph Lameterf8891e52006-06-30 01:55:45 -070048struct vm_event_state {
49 unsigned long event[NR_VM_EVENT_ITEMS];
50};
Christoph Lameterf6ac2352006-06-30 01:55:32 -070051
Christoph Lameterf8891e52006-06-30 01:55:45 -070052DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070053
Christoph Lameterf8891e52006-06-30 01:55:45 -070054static inline void __count_vm_event(enum vm_event_item item)
55{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070056 __get_cpu_var(vm_event_states).event[item]++;
Christoph Lameterf8891e52006-06-30 01:55:45 -070057}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070058
Christoph Lameterf8891e52006-06-30 01:55:45 -070059static inline void count_vm_event(enum vm_event_item item)
60{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070061 get_cpu_var(vm_event_states).event[item]++;
Christoph Lameterf8891e52006-06-30 01:55:45 -070062 put_cpu();
63}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070064
Christoph Lameterf8891e52006-06-30 01:55:45 -070065static inline void __count_vm_events(enum vm_event_item item, long delta)
66{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070067 __get_cpu_var(vm_event_states).event[item] += delta;
Christoph Lameterf8891e52006-06-30 01:55:45 -070068}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070069
Christoph Lameterf8891e52006-06-30 01:55:45 -070070static inline void count_vm_events(enum vm_event_item item, long delta)
71{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070072 get_cpu_var(vm_event_states).event[item] += delta;
Christoph Lameterf8891e52006-06-30 01:55:45 -070073 put_cpu();
74}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070075
Christoph Lameterf8891e52006-06-30 01:55:45 -070076extern void all_vm_events(unsigned long *);
Magnus Damme9033872006-12-22 01:08:01 -080077#ifdef CONFIG_HOTPLUG
Christoph Lameterf8891e52006-06-30 01:55:45 -070078extern void vm_events_fold_cpu(int cpu);
Magnus Damme9033872006-12-22 01:08:01 -080079#else
80static inline void vm_events_fold_cpu(int cpu)
81{
82}
83#endif
Christoph Lameterf6ac2352006-06-30 01:55:32 -070084
Christoph Lameterf8891e52006-06-30 01:55:45 -070085#else
Christoph Lameterf6ac2352006-06-30 01:55:32 -070086
Christoph Lameterf8891e52006-06-30 01:55:45 -070087/* Disable counters */
88#define get_cpu_vm_events(e) 0L
89#define count_vm_event(e) do { } while (0)
90#define count_vm_events(e,d) do { } while (0)
91#define __count_vm_event(e) do { } while (0)
92#define __count_vm_events(e,d) do { } while (0)
93#define vm_events_fold_cpu(x) do { } while (0)
Christoph Lameterf6ac2352006-06-30 01:55:32 -070094
Christoph Lameterf8891e52006-06-30 01:55:45 -070095#endif /* CONFIG_VM_EVENT_COUNTERS */
96
97#define __count_zone_vm_events(item, zone, delta) \
98 __count_vm_events(item##_DMA + zone_idx(zone), delta)
Christoph Lameterf6ac2352006-06-30 01:55:32 -070099
Christoph Lameter2244b952006-06-30 01:55:33 -0700100/*
101 * Zone based page accounting with per cpu differentials.
102 */
103extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700104
Christoph Lameter2244b952006-06-30 01:55:33 -0700105static inline void zone_page_state_add(long x, struct zone *zone,
106 enum zone_stat_item item)
107{
108 atomic_long_add(x, &zone->vm_stat[item]);
109 atomic_long_add(x, &vm_stat[item]);
110}
111
112static inline unsigned long global_page_state(enum zone_stat_item item)
113{
114 long x = atomic_long_read(&vm_stat[item]);
115#ifdef CONFIG_SMP
116 if (x < 0)
117 x = 0;
118#endif
119 return x;
120}
121
122static inline unsigned long zone_page_state(struct zone *zone,
123 enum zone_stat_item item)
124{
125 long x = atomic_long_read(&zone->vm_stat[item]);
126#ifdef CONFIG_SMP
127 if (x < 0)
128 x = 0;
129#endif
130 return x;
131}
132
133#ifdef CONFIG_NUMA
134/*
135 * Determine the per node value of a stat item. This function
136 * is called frequently in a NUMA machine, so try to be as
137 * frugal as possible.
138 */
139static inline unsigned long node_page_state(int node,
140 enum zone_stat_item item)
141{
142 struct zone *zones = NODE_DATA(node)->node_zones;
143
144 return
Christoph Lameterfb0e7942006-09-25 23:31:13 -0700145#ifdef CONFIG_ZONE_DMA32
Christoph Lameter2244b952006-06-30 01:55:33 -0700146 zone_page_state(&zones[ZONE_DMA32], item) +
147#endif
148 zone_page_state(&zones[ZONE_NORMAL], item) +
Christoph Lameter2244b952006-06-30 01:55:33 -0700149#ifdef CONFIG_HIGHMEM
150 zone_page_state(&zones[ZONE_HIGHMEM], item) +
151#endif
152 zone_page_state(&zones[ZONE_DMA], item);
153}
Christoph Lameterca889e62006-06-30 01:55:44 -0700154
155extern void zone_statistics(struct zonelist *, struct zone *);
156
Christoph Lameter2244b952006-06-30 01:55:33 -0700157#else
Christoph Lameterca889e62006-06-30 01:55:44 -0700158
Christoph Lameter2244b952006-06-30 01:55:33 -0700159#define node_page_state(node, item) global_page_state(item)
Christoph Lameterca889e62006-06-30 01:55:44 -0700160#define zone_statistics(_zl,_z) do { } while (0)
161
162#endif /* CONFIG_NUMA */
Christoph Lameter2244b952006-06-30 01:55:33 -0700163
164#define __add_zone_page_state(__z, __i, __d) \
165 __mod_zone_page_state(__z, __i, __d)
166#define __sub_zone_page_state(__z, __i, __d) \
167 __mod_zone_page_state(__z, __i,-(__d))
168
169#define add_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, __d)
170#define sub_zone_page_state(__z, __i, __d) mod_zone_page_state(__z, __i, -(__d))
171
172static inline void zap_zone_vm_stats(struct zone *zone)
173{
174 memset(zone->vm_stat, 0, sizeof(zone->vm_stat));
175}
176
Christoph Lameterca889e62006-06-30 01:55:44 -0700177extern void inc_zone_state(struct zone *, enum zone_stat_item);
178
Christoph Lameter2244b952006-06-30 01:55:33 -0700179#ifdef CONFIG_SMP
180void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
181void __inc_zone_page_state(struct page *, enum zone_stat_item);
182void __dec_zone_page_state(struct page *, enum zone_stat_item);
183
184void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
185void inc_zone_page_state(struct page *, enum zone_stat_item);
186void dec_zone_page_state(struct page *, enum zone_stat_item);
187
188extern void inc_zone_state(struct zone *, enum zone_stat_item);
Christoph Lameterc8785382007-02-10 01:43:01 -0800189extern void __inc_zone_state(struct zone *, enum zone_stat_item);
190extern void dec_zone_state(struct zone *, enum zone_stat_item);
191extern void __dec_zone_state(struct zone *, enum zone_stat_item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700192
193void refresh_cpu_vm_stats(int);
194void refresh_vm_stats(void);
195
196#else /* CONFIG_SMP */
197
198/*
199 * We do not maintain differentials in a single processor configuration.
200 * The functions directly modify the zone and global counters.
201 */
202static inline void __mod_zone_page_state(struct zone *zone,
203 enum zone_stat_item item, int delta)
204{
205 zone_page_state_add(delta, zone, item);
206}
207
Christoph Lameter7f4599e2006-07-10 04:44:30 -0700208static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
209{
210 atomic_long_inc(&zone->vm_stat[item]);
211 atomic_long_inc(&vm_stat[item]);
212}
213
Christoph Lameter2244b952006-06-30 01:55:33 -0700214static inline void __inc_zone_page_state(struct page *page,
215 enum zone_stat_item item)
216{
Christoph Lameter7f4599e2006-07-10 04:44:30 -0700217 __inc_zone_state(page_zone(page), item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700218}
219
Christoph Lameterc8785382007-02-10 01:43:01 -0800220static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
221{
222 atomic_long_dec(&zone->vm_stat[item]);
223 atomic_long_dec(&vm_stat[item]);
224}
225
Christoph Lameter2244b952006-06-30 01:55:33 -0700226static inline void __dec_zone_page_state(struct page *page,
227 enum zone_stat_item item)
228{
229 atomic_long_dec(&page_zone(page)->vm_stat[item]);
230 atomic_long_dec(&vm_stat[item]);
231}
232
233/*
234 * We only use atomic operations to update counters. So there is no need to
235 * disable interrupts.
236 */
237#define inc_zone_page_state __inc_zone_page_state
238#define dec_zone_page_state __dec_zone_page_state
239#define mod_zone_page_state __mod_zone_page_state
240
241static inline void refresh_cpu_vm_stats(int cpu) { }
242static inline void refresh_vm_stats(void) { }
243#endif
244
245#endif /* _LINUX_VMSTAT_H */