blob: 5462106725d719de129ec92ec5d8bd977cad6a29 [file] [log] [blame]
Christoph Lameterf6ac2352006-06-30 01:55:32 -07001/*
2 * linux/mm/vmstat.c
3 *
4 * Manages VM statistics
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
Christoph Lameter2244b952006-06-30 01:55:33 -07006 *
7 * zoned VM statistics
8 * Copyright (C) 2006 Silicon Graphics, Inc.,
9 * Christoph Lameter <christoph@lameter.com>
Christoph Lameterf6ac2352006-06-30 01:55:32 -070010 */
11
Christoph Lameterf6ac2352006-06-30 01:55:32 -070012#include <linux/mm.h>
Christoph Lameter2244b952006-06-30 01:55:33 -070013#include <linux/module.h>
Christoph Lameterdf9ecab2006-08-31 21:27:35 -070014#include <linux/cpu.h>
Christoph Lameterf6ac2352006-06-30 01:55:32 -070015
Christoph Lameterf6ac2352006-06-30 01:55:32 -070016void __get_zone_counts(unsigned long *active, unsigned long *inactive,
17 unsigned long *free, struct pglist_data *pgdat)
18{
19 struct zone *zones = pgdat->node_zones;
20 int i;
21
Christoph Lameterc8785382007-02-10 01:43:01 -080022 *active = node_page_state(pgdat->node_id, NR_ACTIVE);
23 *inactive = node_page_state(pgdat->node_id, NR_INACTIVE);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070024 *free = 0;
25 for (i = 0; i < MAX_NR_ZONES; i++) {
Christoph Lameterf6ac2352006-06-30 01:55:32 -070026 *free += zones[i].free_pages;
27 }
28}
29
30void get_zone_counts(unsigned long *active,
31 unsigned long *inactive, unsigned long *free)
32{
33 struct pglist_data *pgdat;
34
Christoph Lameterc8785382007-02-10 01:43:01 -080035 *active = global_page_state(NR_ACTIVE);
36 *inactive = global_page_state(NR_INACTIVE);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070037 *free = 0;
38 for_each_online_pgdat(pgdat) {
39 unsigned long l, m, n;
40 __get_zone_counts(&l, &m, &n, pgdat);
Christoph Lameterf6ac2352006-06-30 01:55:32 -070041 *free += n;
42 }
43}
44
Christoph Lameterf8891e52006-06-30 01:55:45 -070045#ifdef CONFIG_VM_EVENT_COUNTERS
46DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
47EXPORT_PER_CPU_SYMBOL(vm_event_states);
48
49static void sum_vm_events(unsigned long *ret, cpumask_t *cpumask)
50{
51 int cpu = 0;
52 int i;
53
54 memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long));
55
56 cpu = first_cpu(*cpumask);
57 while (cpu < NR_CPUS) {
58 struct vm_event_state *this = &per_cpu(vm_event_states, cpu);
59
60 cpu = next_cpu(cpu, *cpumask);
61
62 if (cpu < NR_CPUS)
63 prefetch(&per_cpu(vm_event_states, cpu));
64
65
66 for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
67 ret[i] += this->event[i];
68 }
69}
70
71/*
72 * Accumulate the vm event counters across all CPUs.
73 * The result is unavoidably approximate - it can change
74 * during and after execution of this function.
75*/
76void all_vm_events(unsigned long *ret)
77{
78 sum_vm_events(ret, &cpu_online_map);
79}
Heiko Carstens32dd66f2006-07-10 04:44:31 -070080EXPORT_SYMBOL_GPL(all_vm_events);
Christoph Lameterf8891e52006-06-30 01:55:45 -070081
82#ifdef CONFIG_HOTPLUG
83/*
84 * Fold the foreign cpu events into our own.
85 *
86 * This is adding to the events on one processor
87 * but keeps the global counts constant.
88 */
89void vm_events_fold_cpu(int cpu)
90{
91 struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu);
92 int i;
93
94 for (i = 0; i < NR_VM_EVENT_ITEMS; i++) {
95 count_vm_events(i, fold_state->event[i]);
96 fold_state->event[i] = 0;
97 }
98}
99#endif /* CONFIG_HOTPLUG */
100
101#endif /* CONFIG_VM_EVENT_COUNTERS */
102
Christoph Lameter2244b952006-06-30 01:55:33 -0700103/*
104 * Manage combined zone based / global counters
105 *
106 * vm_stat contains the global counters
107 */
108atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
109EXPORT_SYMBOL(vm_stat);
110
111#ifdef CONFIG_SMP
112
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700113static int calculate_threshold(struct zone *zone)
114{
115 int threshold;
116 int mem; /* memory in 128 MB units */
117
118 /*
119 * The threshold scales with the number of processors and the amount
120 * of memory per zone. More memory means that we can defer updates for
121 * longer, more processors could lead to more contention.
122 * fls() is used to have a cheap way of logarithmic scaling.
123 *
124 * Some sample thresholds:
125 *
126 * Threshold Processors (fls) Zonesize fls(mem+1)
127 * ------------------------------------------------------------------
128 * 8 1 1 0.9-1 GB 4
129 * 16 2 2 0.9-1 GB 4
130 * 20 2 2 1-2 GB 5
131 * 24 2 2 2-4 GB 6
132 * 28 2 2 4-8 GB 7
133 * 32 2 2 8-16 GB 8
134 * 4 2 2 <128M 1
135 * 30 4 3 2-4 GB 5
136 * 48 4 3 8-16 GB 8
137 * 32 8 4 1-2 GB 4
138 * 32 8 4 0.9-1GB 4
139 * 10 16 5 <128M 1
140 * 40 16 5 900M 4
141 * 70 64 7 2-4 GB 5
142 * 84 64 7 4-8 GB 6
143 * 108 512 9 4-8 GB 6
144 * 125 1024 10 8-16 GB 8
145 * 125 1024 10 16-32 GB 9
146 */
147
148 mem = zone->present_pages >> (27 - PAGE_SHIFT);
149
150 threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem));
151
152 /*
153 * Maximum threshold is 125
154 */
155 threshold = min(125, threshold);
156
157 return threshold;
158}
Christoph Lameter2244b952006-06-30 01:55:33 -0700159
160/*
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700161 * Refresh the thresholds for each zone.
Christoph Lameter2244b952006-06-30 01:55:33 -0700162 */
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700163static void refresh_zone_stat_thresholds(void)
Christoph Lameter2244b952006-06-30 01:55:33 -0700164{
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700165 struct zone *zone;
166 int cpu;
167 int threshold;
168
169 for_each_zone(zone) {
170
171 if (!zone->present_pages)
172 continue;
173
174 threshold = calculate_threshold(zone);
175
176 for_each_online_cpu(cpu)
177 zone_pcp(zone, cpu)->stat_threshold = threshold;
178 }
Christoph Lameter2244b952006-06-30 01:55:33 -0700179}
180
181/*
182 * For use when we know that interrupts are disabled.
183 */
184void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
185 int delta)
186{
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700187 struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
188 s8 *p = pcp->vm_stat_diff + item;
Christoph Lameter2244b952006-06-30 01:55:33 -0700189 long x;
190
Christoph Lameter2244b952006-06-30 01:55:33 -0700191 x = delta + *p;
192
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700193 if (unlikely(x > pcp->stat_threshold || x < -pcp->stat_threshold)) {
Christoph Lameter2244b952006-06-30 01:55:33 -0700194 zone_page_state_add(x, zone, item);
195 x = 0;
196 }
Christoph Lameter2244b952006-06-30 01:55:33 -0700197 *p = x;
198}
199EXPORT_SYMBOL(__mod_zone_page_state);
200
201/*
202 * For an unknown interrupt state
203 */
204void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
205 int delta)
206{
207 unsigned long flags;
208
209 local_irq_save(flags);
210 __mod_zone_page_state(zone, item, delta);
211 local_irq_restore(flags);
212}
213EXPORT_SYMBOL(mod_zone_page_state);
214
215/*
216 * Optimized increment and decrement functions.
217 *
218 * These are only for a single page and therefore can take a struct page *
219 * argument instead of struct zone *. This allows the inclusion of the code
220 * generated for page_zone(page) into the optimized functions.
221 *
222 * No overflow check is necessary and therefore the differential can be
223 * incremented or decremented in place which may allow the compilers to
224 * generate better code.
Christoph Lameter2244b952006-06-30 01:55:33 -0700225 * The increment or decrement is known and therefore one boundary check can
226 * be omitted.
227 *
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700228 * NOTE: These functions are very performance sensitive. Change only
229 * with care.
230 *
Christoph Lameter2244b952006-06-30 01:55:33 -0700231 * Some processors have inc/dec instructions that are atomic vs an interrupt.
232 * However, the code must first determine the differential location in a zone
233 * based on the processor number and then inc/dec the counter. There is no
234 * guarantee without disabling preemption that the processor will not change
235 * in between and therefore the atomicity vs. interrupt cannot be exploited
236 * in a useful way here.
237 */
Christoph Lameterc8785382007-02-10 01:43:01 -0800238void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
Christoph Lameter2244b952006-06-30 01:55:33 -0700239{
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700240 struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
241 s8 *p = pcp->vm_stat_diff + item;
Christoph Lameter2244b952006-06-30 01:55:33 -0700242
243 (*p)++;
244
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700245 if (unlikely(*p > pcp->stat_threshold)) {
246 int overstep = pcp->stat_threshold / 2;
247
248 zone_page_state_add(*p + overstep, zone, item);
249 *p = -overstep;
Christoph Lameter2244b952006-06-30 01:55:33 -0700250 }
251}
Christoph Lameterca889e62006-06-30 01:55:44 -0700252
253void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
254{
255 __inc_zone_state(page_zone(page), item);
256}
Christoph Lameter2244b952006-06-30 01:55:33 -0700257EXPORT_SYMBOL(__inc_zone_page_state);
258
Christoph Lameterc8785382007-02-10 01:43:01 -0800259void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
Christoph Lameter2244b952006-06-30 01:55:33 -0700260{
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700261 struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
262 s8 *p = pcp->vm_stat_diff + item;
Christoph Lameter2244b952006-06-30 01:55:33 -0700263
264 (*p)--;
265
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700266 if (unlikely(*p < - pcp->stat_threshold)) {
267 int overstep = pcp->stat_threshold / 2;
268
269 zone_page_state_add(*p - overstep, zone, item);
270 *p = overstep;
Christoph Lameter2244b952006-06-30 01:55:33 -0700271 }
272}
Christoph Lameterc8785382007-02-10 01:43:01 -0800273
274void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
275{
276 __dec_zone_state(page_zone(page), item);
277}
Christoph Lameter2244b952006-06-30 01:55:33 -0700278EXPORT_SYMBOL(__dec_zone_page_state);
279
Christoph Lameterca889e62006-06-30 01:55:44 -0700280void inc_zone_state(struct zone *zone, enum zone_stat_item item)
281{
282 unsigned long flags;
283
284 local_irq_save(flags);
285 __inc_zone_state(zone, item);
286 local_irq_restore(flags);
287}
288
Christoph Lameter2244b952006-06-30 01:55:33 -0700289void inc_zone_page_state(struct page *page, enum zone_stat_item item)
290{
291 unsigned long flags;
292 struct zone *zone;
Christoph Lameter2244b952006-06-30 01:55:33 -0700293
294 zone = page_zone(page);
295 local_irq_save(flags);
Christoph Lameterca889e62006-06-30 01:55:44 -0700296 __inc_zone_state(zone, item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700297 local_irq_restore(flags);
298}
299EXPORT_SYMBOL(inc_zone_page_state);
300
301void dec_zone_page_state(struct page *page, enum zone_stat_item item)
302{
303 unsigned long flags;
Christoph Lameter2244b952006-06-30 01:55:33 -0700304
Christoph Lameter2244b952006-06-30 01:55:33 -0700305 local_irq_save(flags);
Christoph Lametera302eb42006-08-31 21:27:34 -0700306 __dec_zone_page_state(page, item);
Christoph Lameter2244b952006-06-30 01:55:33 -0700307 local_irq_restore(flags);
308}
309EXPORT_SYMBOL(dec_zone_page_state);
310
311/*
312 * Update the zone counters for one cpu.
313 */
314void refresh_cpu_vm_stats(int cpu)
315{
316 struct zone *zone;
317 int i;
318 unsigned long flags;
319
320 for_each_zone(zone) {
321 struct per_cpu_pageset *pcp;
322
Christoph Lameter39bbcb82006-09-25 23:31:49 -0700323 if (!populated_zone(zone))
324 continue;
325
Christoph Lameter2244b952006-06-30 01:55:33 -0700326 pcp = zone_pcp(zone, cpu);
327
328 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
329 if (pcp->vm_stat_diff[i]) {
330 local_irq_save(flags);
331 zone_page_state_add(pcp->vm_stat_diff[i],
332 zone, i);
333 pcp->vm_stat_diff[i] = 0;
334 local_irq_restore(flags);
335 }
336 }
337}
338
339static void __refresh_cpu_vm_stats(void *dummy)
340{
341 refresh_cpu_vm_stats(smp_processor_id());
342}
343
344/*
345 * Consolidate all counters.
346 *
347 * Note that the result is less inaccurate but still inaccurate
348 * if concurrent processes are allowed to run.
349 */
350void refresh_vm_stats(void)
351{
352 on_each_cpu(__refresh_cpu_vm_stats, NULL, 0, 1);
353}
354EXPORT_SYMBOL(refresh_vm_stats);
355
356#endif
357
Christoph Lameterca889e62006-06-30 01:55:44 -0700358#ifdef CONFIG_NUMA
359/*
360 * zonelist = the list of zones passed to the allocator
361 * z = the zone from which the allocation occurred.
362 *
363 * Must be called with interrupts disabled.
364 */
365void zone_statistics(struct zonelist *zonelist, struct zone *z)
366{
367 if (z->zone_pgdat == zonelist->zones[0]->zone_pgdat) {
368 __inc_zone_state(z, NUMA_HIT);
369 } else {
370 __inc_zone_state(z, NUMA_MISS);
371 __inc_zone_state(zonelist->zones[0], NUMA_FOREIGN);
372 }
Christoph Lameter5d292342006-09-27 01:50:10 -0700373 if (z->node == numa_node_id())
Christoph Lameterca889e62006-06-30 01:55:44 -0700374 __inc_zone_state(z, NUMA_LOCAL);
375 else
376 __inc_zone_state(z, NUMA_OTHER);
377}
378#endif
379
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700380#ifdef CONFIG_PROC_FS
381
382#include <linux/seq_file.h>
383
384static void *frag_start(struct seq_file *m, loff_t *pos)
385{
386 pg_data_t *pgdat;
387 loff_t node = *pos;
388 for (pgdat = first_online_pgdat();
389 pgdat && node;
390 pgdat = next_online_pgdat(pgdat))
391 --node;
392
393 return pgdat;
394}
395
396static void *frag_next(struct seq_file *m, void *arg, loff_t *pos)
397{
398 pg_data_t *pgdat = (pg_data_t *)arg;
399
400 (*pos)++;
401 return next_online_pgdat(pgdat);
402}
403
404static void frag_stop(struct seq_file *m, void *arg)
405{
406}
407
408/*
409 * This walks the free areas for each zone.
410 */
411static int frag_show(struct seq_file *m, void *arg)
412{
413 pg_data_t *pgdat = (pg_data_t *)arg;
414 struct zone *zone;
415 struct zone *node_zones = pgdat->node_zones;
416 unsigned long flags;
417 int order;
418
419 for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
420 if (!populated_zone(zone))
421 continue;
422
423 spin_lock_irqsave(&zone->lock, flags);
424 seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
425 for (order = 0; order < MAX_ORDER; ++order)
426 seq_printf(m, "%6lu ", zone->free_area[order].nr_free);
427 spin_unlock_irqrestore(&zone->lock, flags);
428 seq_putc(m, '\n');
429 }
430 return 0;
431}
432
Helge Deller15ad7cd2006-12-06 20:40:36 -0800433const struct seq_operations fragmentation_op = {
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700434 .start = frag_start,
435 .next = frag_next,
436 .stop = frag_stop,
437 .show = frag_show,
438};
439
Christoph Lameter27bf71c2006-09-25 23:31:15 -0700440#ifdef CONFIG_ZONE_DMA32
441#define TEXT_FOR_DMA32(xx) xx "_dma32",
442#else
443#define TEXT_FOR_DMA32(xx)
444#endif
445
446#ifdef CONFIG_HIGHMEM
447#define TEXT_FOR_HIGHMEM(xx) xx "_high",
448#else
449#define TEXT_FOR_HIGHMEM(xx)
450#endif
451
452#define TEXTS_FOR_ZONES(xx) xx "_dma", TEXT_FOR_DMA32(xx) xx "_normal", \
453 TEXT_FOR_HIGHMEM(xx)
454
Helge Deller15ad7cd2006-12-06 20:40:36 -0800455static const char * const vmstat_text[] = {
Christoph Lameter2244b952006-06-30 01:55:33 -0700456 /* Zoned VM counters */
Christoph Lameterc8785382007-02-10 01:43:01 -0800457 "nr_active",
458 "nr_inactive",
Christoph Lameterf3dbd342006-06-30 01:55:36 -0700459 "nr_anon_pages",
Christoph Lameter65ba55f2006-06-30 01:55:34 -0700460 "nr_mapped",
Christoph Lameter347ce432006-06-30 01:55:35 -0700461 "nr_file_pages",
Christoph Lameter972d1a72006-09-25 23:31:51 -0700462 "nr_slab_reclaimable",
463 "nr_slab_unreclaimable",
Christoph Lameterdf849a12006-06-30 01:55:38 -0700464 "nr_page_table_pages",
Christoph Lameterb1e7a8f2006-06-30 01:55:39 -0700465 "nr_dirty",
Christoph Lameterce866b32006-06-30 01:55:40 -0700466 "nr_writeback",
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700467 "nr_unstable",
Christoph Lameterd2c5e302006-06-30 01:55:41 -0700468 "nr_bounce",
Andrew Mortone129b5c2006-09-27 01:50:00 -0700469 "nr_vmscan_write",
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700470
Christoph Lameterca889e62006-06-30 01:55:44 -0700471#ifdef CONFIG_NUMA
472 "numa_hit",
473 "numa_miss",
474 "numa_foreign",
475 "numa_interleave",
476 "numa_local",
477 "numa_other",
478#endif
479
Christoph Lameterf8891e52006-06-30 01:55:45 -0700480#ifdef CONFIG_VM_EVENT_COUNTERS
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700481 "pgpgin",
482 "pgpgout",
483 "pswpin",
484 "pswpout",
485
Christoph Lameter27bf71c2006-09-25 23:31:15 -0700486 TEXTS_FOR_ZONES("pgalloc")
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700487
488 "pgfree",
489 "pgactivate",
490 "pgdeactivate",
491
492 "pgfault",
493 "pgmajfault",
494
Christoph Lameter27bf71c2006-09-25 23:31:15 -0700495 TEXTS_FOR_ZONES("pgrefill")
496 TEXTS_FOR_ZONES("pgsteal")
497 TEXTS_FOR_ZONES("pgscan_kswapd")
498 TEXTS_FOR_ZONES("pgscan_direct")
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700499
500 "pginodesteal",
501 "slabs_scanned",
502 "kswapd_steal",
503 "kswapd_inodesteal",
504 "pageoutrun",
505 "allocstall",
506
507 "pgrotated",
Christoph Lameterf8891e52006-06-30 01:55:45 -0700508#endif
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700509};
510
511/*
512 * Output information about zones in @pgdat.
513 */
514static int zoneinfo_show(struct seq_file *m, void *arg)
515{
516 pg_data_t *pgdat = arg;
517 struct zone *zone;
518 struct zone *node_zones = pgdat->node_zones;
519 unsigned long flags;
520
521 for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; zone++) {
522 int i;
523
524 if (!populated_zone(zone))
525 continue;
526
527 spin_lock_irqsave(&zone->lock, flags);
528 seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name);
529 seq_printf(m,
530 "\n pages free %lu"
531 "\n min %lu"
532 "\n low %lu"
533 "\n high %lu"
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700534 "\n scanned %lu (a: %lu i: %lu)"
535 "\n spanned %lu"
536 "\n present %lu",
537 zone->free_pages,
538 zone->pages_min,
539 zone->pages_low,
540 zone->pages_high,
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700541 zone->pages_scanned,
542 zone->nr_scan_active, zone->nr_scan_inactive,
543 zone->spanned_pages,
544 zone->present_pages);
Christoph Lameter2244b952006-06-30 01:55:33 -0700545
546 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
547 seq_printf(m, "\n %-12s %lu", vmstat_text[i],
548 zone_page_state(zone, i));
549
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700550 seq_printf(m,
551 "\n protection: (%lu",
552 zone->lowmem_reserve[0]);
553 for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++)
554 seq_printf(m, ", %lu", zone->lowmem_reserve[i]);
555 seq_printf(m,
556 ")"
557 "\n pagesets");
558 for_each_online_cpu(i) {
559 struct per_cpu_pageset *pageset;
560 int j;
561
562 pageset = zone_pcp(zone, i);
563 for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) {
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700564 seq_printf(m,
565 "\n cpu: %i pcp: %i"
566 "\n count: %i"
567 "\n high: %i"
568 "\n batch: %i",
569 i, j,
570 pageset->pcp[j].count,
571 pageset->pcp[j].high,
572 pageset->pcp[j].batch);
573 }
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700574#ifdef CONFIG_SMP
575 seq_printf(m, "\n vm stats threshold: %d",
576 pageset->stat_threshold);
577#endif
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700578 }
579 seq_printf(m,
580 "\n all_unreclaimable: %u"
581 "\n prev_priority: %i"
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700582 "\n start_pfn: %lu",
583 zone->all_unreclaimable,
584 zone->prev_priority,
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700585 zone->zone_start_pfn);
586 spin_unlock_irqrestore(&zone->lock, flags);
587 seq_putc(m, '\n');
588 }
589 return 0;
590}
591
Helge Deller15ad7cd2006-12-06 20:40:36 -0800592const struct seq_operations zoneinfo_op = {
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700593 .start = frag_start, /* iterate over all zones. The same as in
594 * fragmentation. */
595 .next = frag_next,
596 .stop = frag_stop,
597 .show = zoneinfo_show,
598};
599
600static void *vmstat_start(struct seq_file *m, loff_t *pos)
601{
Christoph Lameter2244b952006-06-30 01:55:33 -0700602 unsigned long *v;
Christoph Lameterf8891e52006-06-30 01:55:45 -0700603#ifdef CONFIG_VM_EVENT_COUNTERS
604 unsigned long *e;
605#endif
Christoph Lameter2244b952006-06-30 01:55:33 -0700606 int i;
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700607
608 if (*pos >= ARRAY_SIZE(vmstat_text))
609 return NULL;
610
Christoph Lameterf8891e52006-06-30 01:55:45 -0700611#ifdef CONFIG_VM_EVENT_COUNTERS
Christoph Lameter2244b952006-06-30 01:55:33 -0700612 v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long)
Christoph Lameterf8891e52006-06-30 01:55:45 -0700613 + sizeof(struct vm_event_state), GFP_KERNEL);
614#else
615 v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long),
616 GFP_KERNEL);
617#endif
Christoph Lameter2244b952006-06-30 01:55:33 -0700618 m->private = v;
619 if (!v)
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700620 return ERR_PTR(-ENOMEM);
Christoph Lameter2244b952006-06-30 01:55:33 -0700621 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
622 v[i] = global_page_state(i);
Christoph Lameterf8891e52006-06-30 01:55:45 -0700623#ifdef CONFIG_VM_EVENT_COUNTERS
624 e = v + NR_VM_ZONE_STAT_ITEMS;
625 all_vm_events(e);
626 e[PGPGIN] /= 2; /* sectors -> kbytes */
627 e[PGPGOUT] /= 2;
628#endif
Christoph Lameter2244b952006-06-30 01:55:33 -0700629 return v + *pos;
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700630}
631
632static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
633{
634 (*pos)++;
635 if (*pos >= ARRAY_SIZE(vmstat_text))
636 return NULL;
637 return (unsigned long *)m->private + *pos;
638}
639
640static int vmstat_show(struct seq_file *m, void *arg)
641{
642 unsigned long *l = arg;
643 unsigned long off = l - (unsigned long *)m->private;
644
645 seq_printf(m, "%s %lu\n", vmstat_text[off], *l);
646 return 0;
647}
648
649static void vmstat_stop(struct seq_file *m, void *arg)
650{
651 kfree(m->private);
652 m->private = NULL;
653}
654
Helge Deller15ad7cd2006-12-06 20:40:36 -0800655const struct seq_operations vmstat_op = {
Christoph Lameterf6ac2352006-06-30 01:55:32 -0700656 .start = vmstat_start,
657 .next = vmstat_next,
658 .stop = vmstat_stop,
659 .show = vmstat_show,
660};
661
662#endif /* CONFIG_PROC_FS */
663
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700664#ifdef CONFIG_SMP
665/*
666 * Use the cpu notifier to insure that the thresholds are recalculated
667 * when necessary.
668 */
669static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
670 unsigned long action,
671 void *hcpu)
672{
673 switch (action) {
Andy Whitcroftce421c72006-12-06 20:33:08 -0800674 case CPU_UP_PREPARE:
675 case CPU_UP_CANCELED:
676 case CPU_DEAD:
677 refresh_zone_stat_thresholds();
678 break;
679 default:
680 break;
Christoph Lameterdf9ecab2006-08-31 21:27:35 -0700681 }
682 return NOTIFY_OK;
683}
684
685static struct notifier_block __cpuinitdata vmstat_notifier =
686 { &vmstat_cpuup_callback, NULL, 0 };
687
688int __init setup_vmstat(void)
689{
690 refresh_zone_stat_thresholds();
691 register_cpu_notifier(&vmstat_notifier);
692 return 0;
693}
694module_init(setup_vmstat)
695#endif