blob: 2d9b1b60798aca15f99c9fe46afe5587f1605b6e [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/config.h>
7#include <linux/mmzone.h>
8#include <asm/atomic.h>
Christoph Lameterf6ac2352006-06-30 01:55:32 -07009
Christoph Lameterf8891e52006-06-30 01:55:45 -070010#ifdef CONFIG_VM_EVENT_COUNTERS
Christoph Lameterf6ac2352006-06-30 01:55:32 -070011/*
Christoph Lameterf8891e52006-06-30 01:55:45 -070012 * Light weight per cpu counter implementation.
Christoph Lameterf6ac2352006-06-30 01:55:32 -070013 *
Christoph Lameterf8891e52006-06-30 01:55:45 -070014 * 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 Lameterf6ac2352006-06-30 01:55:32 -070019 */
Christoph Lameterf6ac2352006-06-30 01:55:32 -070020
Christoph Lameterf8891e52006-06-30 01:55:45 -070021#define FOR_ALL_ZONES(x) x##_DMA, x##_DMA32, x##_NORMAL, x##_HIGH
Christoph Lameterf6ac2352006-06-30 01:55:32 -070022
Christoph Lameterf8891e52006-06-30 01:55:45 -070023enum 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 Lameterf6ac2352006-06-30 01:55:32 -070034};
35
Christoph Lameterf8891e52006-06-30 01:55:45 -070036struct vm_event_state {
37 unsigned long event[NR_VM_EVENT_ITEMS];
38};
Christoph Lameterf6ac2352006-06-30 01:55:32 -070039
Christoph Lameterf8891e52006-06-30 01:55:45 -070040DECLARE_PER_CPU(struct vm_event_state, vm_event_states);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070041
Christoph Lameterf8891e52006-06-30 01:55:45 -070042static inline void __count_vm_event(enum vm_event_item item)
43{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070044 __get_cpu_var(vm_event_states).event[item]++;
Christoph Lameterf8891e52006-06-30 01:55:45 -070045}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070046
Christoph Lameterf8891e52006-06-30 01:55:45 -070047static inline void count_vm_event(enum vm_event_item item)
48{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070049 get_cpu_var(vm_event_states).event[item]++;
Christoph Lameterf8891e52006-06-30 01:55:45 -070050 put_cpu();
51}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070052
Christoph Lameterf8891e52006-06-30 01:55:45 -070053static inline void __count_vm_events(enum vm_event_item item, long delta)
54{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070055 __get_cpu_var(vm_event_states).event[item] += delta;
Christoph Lameterf8891e52006-06-30 01:55:45 -070056}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070057
Christoph Lameterf8891e52006-06-30 01:55:45 -070058static inline void count_vm_events(enum vm_event_item item, long delta)
59{
Jan Blunck38cbcdc2006-08-05 12:14:14 -070060 get_cpu_var(vm_event_states).event[item] += delta;
Christoph Lameterf8891e52006-06-30 01:55:45 -070061 put_cpu();
62}
Christoph Lameterf6ac2352006-06-30 01:55:32 -070063
Christoph Lameterf8891e52006-06-30 01:55:45 -070064extern void all_vm_events(unsigned long *);
65extern void vm_events_fold_cpu(int cpu);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070066
Christoph Lameterf8891e52006-06-30 01:55:45 -070067#else
Christoph Lameterf6ac2352006-06-30 01:55:32 -070068
Christoph Lameterf8891e52006-06-30 01:55:45 -070069/* 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 Lameterf6ac2352006-06-30 01:55:32 -070076
Christoph Lameterf8891e52006-06-30 01:55:45 -070077#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 Lameterf6ac2352006-06-30 01:55:32 -070081
Christoph Lameter2244b952006-06-30 01:55:33 -070082/*
83 * Zone based page accounting with per cpu differentials.
84 */
85extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
Christoph Lameterf6ac2352006-06-30 01:55:32 -070086
Christoph Lameter2244b952006-06-30 01:55:33 -070087static 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
94static 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
104static 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 */
121static 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 Lameterca889e62006-06-30 01:55:44 -0700138
139extern void zone_statistics(struct zonelist *, struct zone *);
140
Christoph Lameter2244b952006-06-30 01:55:33 -0700141#else
Christoph Lameterca889e62006-06-30 01:55:44 -0700142
Christoph Lameter2244b952006-06-30 01:55:33 -0700143#define node_page_state(node, item) global_page_state(item)
Christoph Lameterca889e62006-06-30 01:55:44 -0700144#define zone_statistics(_zl,_z) do { } while (0)
145
146#endif /* CONFIG_NUMA */
Christoph Lameter2244b952006-06-30 01:55:33 -0700147
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
156static inline void zap_zone_vm_stats(struct zone *zone)
157{
158 memset(zone->vm_stat, 0, sizeof(zone->vm_stat));
159}
160
Christoph Lameterca889e62006-06-30 01:55:44 -0700161extern void inc_zone_state(struct zone *, enum zone_stat_item);
162
Christoph Lameter2244b952006-06-30 01:55:33 -0700163#ifdef CONFIG_SMP
164void __mod_zone_page_state(struct zone *, enum zone_stat_item item, int);
165void __inc_zone_page_state(struct page *, enum zone_stat_item);
166void __dec_zone_page_state(struct page *, enum zone_stat_item);
167
168void mod_zone_page_state(struct zone *, enum zone_stat_item, int);
169void inc_zone_page_state(struct page *, enum zone_stat_item);
170void dec_zone_page_state(struct page *, enum zone_stat_item);
171
172extern void inc_zone_state(struct zone *, enum zone_stat_item);
173
174void refresh_cpu_vm_stats(int);
175void 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 */
183static 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 Lameter7f4599e2006-07-10 04:44:30 -0700189static 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 Lameter2244b952006-06-30 01:55:33 -0700195static inline void __inc_zone_page_state(struct page *page,
196 enum zone_stat_item item)
197{
Christoph Lameter7f4599e2006-07-10 04:44:30 -0700198 __inc_zone_state(page_zone(page), item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700199}
200
201static 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
216static inline void refresh_cpu_vm_stats(int cpu) { }
217static inline void refresh_vm_stats(void) { }
218#endif
219
220#endif /* _LINUX_VMSTAT_H */