Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/vmstat.c |
| 3 | * |
| 4 | * Manages VM statistics |
| 5 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 6 | * |
| 7 | * zoned VM statistics |
| 8 | * Copyright (C) 2006 Silicon Graphics, Inc., |
| 9 | * Christoph Lameter <christoph@lameter.com> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/mm.h> |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * Accumulate the page_state information across all CPUs. |
| 18 | * The result is unavoidably approximate - it can change |
| 19 | * during and after execution of this function. |
| 20 | */ |
| 21 | DEFINE_PER_CPU(struct page_state, page_states) = {0}; |
| 22 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 23 | static void __get_page_state(struct page_state *ret, int nr, cpumask_t *cpumask) |
| 24 | { |
| 25 | unsigned cpu; |
| 26 | |
| 27 | memset(ret, 0, nr * sizeof(unsigned long)); |
| 28 | cpus_and(*cpumask, *cpumask, cpu_online_map); |
| 29 | |
| 30 | for_each_cpu_mask(cpu, *cpumask) { |
| 31 | unsigned long *in; |
| 32 | unsigned long *out; |
| 33 | unsigned off; |
| 34 | unsigned next_cpu; |
| 35 | |
| 36 | in = (unsigned long *)&per_cpu(page_states, cpu); |
| 37 | |
| 38 | next_cpu = next_cpu(cpu, *cpumask); |
| 39 | if (likely(next_cpu < NR_CPUS)) |
| 40 | prefetch(&per_cpu(page_states, next_cpu)); |
| 41 | |
| 42 | out = (unsigned long *)ret; |
| 43 | for (off = 0; off < nr; off++) |
| 44 | *out++ += *in++; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void get_page_state_node(struct page_state *ret, int node) |
| 49 | { |
| 50 | int nr; |
| 51 | cpumask_t mask = node_to_cpumask(node); |
| 52 | |
| 53 | nr = offsetof(struct page_state, GET_PAGE_STATE_LAST); |
| 54 | nr /= sizeof(unsigned long); |
| 55 | |
| 56 | __get_page_state(ret, nr+1, &mask); |
| 57 | } |
| 58 | |
| 59 | void get_page_state(struct page_state *ret) |
| 60 | { |
| 61 | int nr; |
| 62 | cpumask_t mask = CPU_MASK_ALL; |
| 63 | |
| 64 | nr = offsetof(struct page_state, GET_PAGE_STATE_LAST); |
| 65 | nr /= sizeof(unsigned long); |
| 66 | |
| 67 | __get_page_state(ret, nr + 1, &mask); |
| 68 | } |
| 69 | |
| 70 | void get_full_page_state(struct page_state *ret) |
| 71 | { |
| 72 | cpumask_t mask = CPU_MASK_ALL; |
| 73 | |
| 74 | __get_page_state(ret, sizeof(*ret) / sizeof(unsigned long), &mask); |
| 75 | } |
| 76 | |
| 77 | unsigned long read_page_state_offset(unsigned long offset) |
| 78 | { |
| 79 | unsigned long ret = 0; |
| 80 | int cpu; |
| 81 | |
| 82 | for_each_online_cpu(cpu) { |
| 83 | unsigned long in; |
| 84 | |
| 85 | in = (unsigned long)&per_cpu(page_states, cpu) + offset; |
| 86 | ret += *((unsigned long *)in); |
| 87 | } |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | void __mod_page_state_offset(unsigned long offset, unsigned long delta) |
| 92 | { |
| 93 | void *ptr; |
| 94 | |
| 95 | ptr = &__get_cpu_var(page_states); |
| 96 | *(unsigned long *)(ptr + offset) += delta; |
| 97 | } |
| 98 | EXPORT_SYMBOL(__mod_page_state_offset); |
| 99 | |
| 100 | void mod_page_state_offset(unsigned long offset, unsigned long delta) |
| 101 | { |
| 102 | unsigned long flags; |
| 103 | void *ptr; |
| 104 | |
| 105 | local_irq_save(flags); |
| 106 | ptr = &__get_cpu_var(page_states); |
| 107 | *(unsigned long *)(ptr + offset) += delta; |
| 108 | local_irq_restore(flags); |
| 109 | } |
| 110 | EXPORT_SYMBOL(mod_page_state_offset); |
| 111 | |
| 112 | void __get_zone_counts(unsigned long *active, unsigned long *inactive, |
| 113 | unsigned long *free, struct pglist_data *pgdat) |
| 114 | { |
| 115 | struct zone *zones = pgdat->node_zones; |
| 116 | int i; |
| 117 | |
| 118 | *active = 0; |
| 119 | *inactive = 0; |
| 120 | *free = 0; |
| 121 | for (i = 0; i < MAX_NR_ZONES; i++) { |
| 122 | *active += zones[i].nr_active; |
| 123 | *inactive += zones[i].nr_inactive; |
| 124 | *free += zones[i].free_pages; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void get_zone_counts(unsigned long *active, |
| 129 | unsigned long *inactive, unsigned long *free) |
| 130 | { |
| 131 | struct pglist_data *pgdat; |
| 132 | |
| 133 | *active = 0; |
| 134 | *inactive = 0; |
| 135 | *free = 0; |
| 136 | for_each_online_pgdat(pgdat) { |
| 137 | unsigned long l, m, n; |
| 138 | __get_zone_counts(&l, &m, &n, pgdat); |
| 139 | *active += l; |
| 140 | *inactive += m; |
| 141 | *free += n; |
| 142 | } |
| 143 | } |
| 144 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 145 | /* |
| 146 | * Manage combined zone based / global counters |
| 147 | * |
| 148 | * vm_stat contains the global counters |
| 149 | */ |
| 150 | atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; |
| 151 | EXPORT_SYMBOL(vm_stat); |
| 152 | |
| 153 | #ifdef CONFIG_SMP |
| 154 | |
| 155 | #define STAT_THRESHOLD 32 |
| 156 | |
| 157 | /* |
| 158 | * Determine pointer to currently valid differential byte given a zone and |
| 159 | * the item number. |
| 160 | * |
| 161 | * Preemption must be off |
| 162 | */ |
| 163 | static inline s8 *diff_pointer(struct zone *zone, enum zone_stat_item item) |
| 164 | { |
| 165 | return &zone_pcp(zone, smp_processor_id())->vm_stat_diff[item]; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * For use when we know that interrupts are disabled. |
| 170 | */ |
| 171 | void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 172 | int delta) |
| 173 | { |
| 174 | s8 *p; |
| 175 | long x; |
| 176 | |
| 177 | p = diff_pointer(zone, item); |
| 178 | x = delta + *p; |
| 179 | |
| 180 | if (unlikely(x > STAT_THRESHOLD || x < -STAT_THRESHOLD)) { |
| 181 | zone_page_state_add(x, zone, item); |
| 182 | x = 0; |
| 183 | } |
| 184 | |
| 185 | *p = x; |
| 186 | } |
| 187 | EXPORT_SYMBOL(__mod_zone_page_state); |
| 188 | |
| 189 | /* |
| 190 | * For an unknown interrupt state |
| 191 | */ |
| 192 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 193 | int delta) |
| 194 | { |
| 195 | unsigned long flags; |
| 196 | |
| 197 | local_irq_save(flags); |
| 198 | __mod_zone_page_state(zone, item, delta); |
| 199 | local_irq_restore(flags); |
| 200 | } |
| 201 | EXPORT_SYMBOL(mod_zone_page_state); |
| 202 | |
| 203 | /* |
| 204 | * Optimized increment and decrement functions. |
| 205 | * |
| 206 | * These are only for a single page and therefore can take a struct page * |
| 207 | * argument instead of struct zone *. This allows the inclusion of the code |
| 208 | * generated for page_zone(page) into the optimized functions. |
| 209 | * |
| 210 | * No overflow check is necessary and therefore the differential can be |
| 211 | * incremented or decremented in place which may allow the compilers to |
| 212 | * generate better code. |
| 213 | * |
| 214 | * The increment or decrement is known and therefore one boundary check can |
| 215 | * be omitted. |
| 216 | * |
| 217 | * Some processors have inc/dec instructions that are atomic vs an interrupt. |
| 218 | * However, the code must first determine the differential location in a zone |
| 219 | * based on the processor number and then inc/dec the counter. There is no |
| 220 | * guarantee without disabling preemption that the processor will not change |
| 221 | * in between and therefore the atomicity vs. interrupt cannot be exploited |
| 222 | * in a useful way here. |
| 223 | */ |
| 224 | void __inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 225 | { |
| 226 | struct zone *zone = page_zone(page); |
| 227 | s8 *p = diff_pointer(zone, item); |
| 228 | |
| 229 | (*p)++; |
| 230 | |
| 231 | if (unlikely(*p > STAT_THRESHOLD)) { |
| 232 | zone_page_state_add(*p, zone, item); |
| 233 | *p = 0; |
| 234 | } |
| 235 | } |
| 236 | EXPORT_SYMBOL(__inc_zone_page_state); |
| 237 | |
| 238 | void __dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 239 | { |
| 240 | struct zone *zone = page_zone(page); |
| 241 | s8 *p = diff_pointer(zone, item); |
| 242 | |
| 243 | (*p)--; |
| 244 | |
| 245 | if (unlikely(*p < -STAT_THRESHOLD)) { |
| 246 | zone_page_state_add(*p, zone, item); |
| 247 | *p = 0; |
| 248 | } |
| 249 | } |
| 250 | EXPORT_SYMBOL(__dec_zone_page_state); |
| 251 | |
| 252 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 253 | { |
| 254 | unsigned long flags; |
| 255 | struct zone *zone; |
| 256 | s8 *p; |
| 257 | |
| 258 | zone = page_zone(page); |
| 259 | local_irq_save(flags); |
| 260 | p = diff_pointer(zone, item); |
| 261 | |
| 262 | (*p)++; |
| 263 | |
| 264 | if (unlikely(*p > STAT_THRESHOLD)) { |
| 265 | zone_page_state_add(*p, zone, item); |
| 266 | *p = 0; |
| 267 | } |
| 268 | local_irq_restore(flags); |
| 269 | } |
| 270 | EXPORT_SYMBOL(inc_zone_page_state); |
| 271 | |
| 272 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 273 | { |
| 274 | unsigned long flags; |
| 275 | struct zone *zone; |
| 276 | s8 *p; |
| 277 | |
| 278 | zone = page_zone(page); |
| 279 | local_irq_save(flags); |
| 280 | p = diff_pointer(zone, item); |
| 281 | |
| 282 | (*p)--; |
| 283 | |
| 284 | if (unlikely(*p < -STAT_THRESHOLD)) { |
| 285 | zone_page_state_add(*p, zone, item); |
| 286 | *p = 0; |
| 287 | } |
| 288 | local_irq_restore(flags); |
| 289 | } |
| 290 | EXPORT_SYMBOL(dec_zone_page_state); |
| 291 | |
| 292 | /* |
| 293 | * Update the zone counters for one cpu. |
| 294 | */ |
| 295 | void refresh_cpu_vm_stats(int cpu) |
| 296 | { |
| 297 | struct zone *zone; |
| 298 | int i; |
| 299 | unsigned long flags; |
| 300 | |
| 301 | for_each_zone(zone) { |
| 302 | struct per_cpu_pageset *pcp; |
| 303 | |
| 304 | pcp = zone_pcp(zone, cpu); |
| 305 | |
| 306 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 307 | if (pcp->vm_stat_diff[i]) { |
| 308 | local_irq_save(flags); |
| 309 | zone_page_state_add(pcp->vm_stat_diff[i], |
| 310 | zone, i); |
| 311 | pcp->vm_stat_diff[i] = 0; |
| 312 | local_irq_restore(flags); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | static void __refresh_cpu_vm_stats(void *dummy) |
| 318 | { |
| 319 | refresh_cpu_vm_stats(smp_processor_id()); |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Consolidate all counters. |
| 324 | * |
| 325 | * Note that the result is less inaccurate but still inaccurate |
| 326 | * if concurrent processes are allowed to run. |
| 327 | */ |
| 328 | void refresh_vm_stats(void) |
| 329 | { |
| 330 | on_each_cpu(__refresh_cpu_vm_stats, NULL, 0, 1); |
| 331 | } |
| 332 | EXPORT_SYMBOL(refresh_vm_stats); |
| 333 | |
| 334 | #endif |
| 335 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 336 | #ifdef CONFIG_PROC_FS |
| 337 | |
| 338 | #include <linux/seq_file.h> |
| 339 | |
| 340 | static void *frag_start(struct seq_file *m, loff_t *pos) |
| 341 | { |
| 342 | pg_data_t *pgdat; |
| 343 | loff_t node = *pos; |
| 344 | for (pgdat = first_online_pgdat(); |
| 345 | pgdat && node; |
| 346 | pgdat = next_online_pgdat(pgdat)) |
| 347 | --node; |
| 348 | |
| 349 | return pgdat; |
| 350 | } |
| 351 | |
| 352 | static void *frag_next(struct seq_file *m, void *arg, loff_t *pos) |
| 353 | { |
| 354 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 355 | |
| 356 | (*pos)++; |
| 357 | return next_online_pgdat(pgdat); |
| 358 | } |
| 359 | |
| 360 | static void frag_stop(struct seq_file *m, void *arg) |
| 361 | { |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * This walks the free areas for each zone. |
| 366 | */ |
| 367 | static int frag_show(struct seq_file *m, void *arg) |
| 368 | { |
| 369 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 370 | struct zone *zone; |
| 371 | struct zone *node_zones = pgdat->node_zones; |
| 372 | unsigned long flags; |
| 373 | int order; |
| 374 | |
| 375 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { |
| 376 | if (!populated_zone(zone)) |
| 377 | continue; |
| 378 | |
| 379 | spin_lock_irqsave(&zone->lock, flags); |
| 380 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); |
| 381 | for (order = 0; order < MAX_ORDER; ++order) |
| 382 | seq_printf(m, "%6lu ", zone->free_area[order].nr_free); |
| 383 | spin_unlock_irqrestore(&zone->lock, flags); |
| 384 | seq_putc(m, '\n'); |
| 385 | } |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | struct seq_operations fragmentation_op = { |
| 390 | .start = frag_start, |
| 391 | .next = frag_next, |
| 392 | .stop = frag_stop, |
| 393 | .show = frag_show, |
| 394 | }; |
| 395 | |
| 396 | static char *vmstat_text[] = { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 397 | /* Zoned VM counters */ |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 398 | "nr_mapped", |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame^] | 399 | "nr_file_pages", |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 400 | |
| 401 | /* Page state */ |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 402 | "nr_dirty", |
| 403 | "nr_writeback", |
| 404 | "nr_unstable", |
| 405 | "nr_page_table_pages", |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 406 | "nr_slab", |
| 407 | |
| 408 | "pgpgin", |
| 409 | "pgpgout", |
| 410 | "pswpin", |
| 411 | "pswpout", |
| 412 | |
| 413 | "pgalloc_high", |
| 414 | "pgalloc_normal", |
| 415 | "pgalloc_dma32", |
| 416 | "pgalloc_dma", |
| 417 | |
| 418 | "pgfree", |
| 419 | "pgactivate", |
| 420 | "pgdeactivate", |
| 421 | |
| 422 | "pgfault", |
| 423 | "pgmajfault", |
| 424 | |
| 425 | "pgrefill_high", |
| 426 | "pgrefill_normal", |
| 427 | "pgrefill_dma32", |
| 428 | "pgrefill_dma", |
| 429 | |
| 430 | "pgsteal_high", |
| 431 | "pgsteal_normal", |
| 432 | "pgsteal_dma32", |
| 433 | "pgsteal_dma", |
| 434 | |
| 435 | "pgscan_kswapd_high", |
| 436 | "pgscan_kswapd_normal", |
| 437 | "pgscan_kswapd_dma32", |
| 438 | "pgscan_kswapd_dma", |
| 439 | |
| 440 | "pgscan_direct_high", |
| 441 | "pgscan_direct_normal", |
| 442 | "pgscan_direct_dma32", |
| 443 | "pgscan_direct_dma", |
| 444 | |
| 445 | "pginodesteal", |
| 446 | "slabs_scanned", |
| 447 | "kswapd_steal", |
| 448 | "kswapd_inodesteal", |
| 449 | "pageoutrun", |
| 450 | "allocstall", |
| 451 | |
| 452 | "pgrotated", |
| 453 | "nr_bounce", |
| 454 | }; |
| 455 | |
| 456 | /* |
| 457 | * Output information about zones in @pgdat. |
| 458 | */ |
| 459 | static int zoneinfo_show(struct seq_file *m, void *arg) |
| 460 | { |
| 461 | pg_data_t *pgdat = arg; |
| 462 | struct zone *zone; |
| 463 | struct zone *node_zones = pgdat->node_zones; |
| 464 | unsigned long flags; |
| 465 | |
| 466 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; zone++) { |
| 467 | int i; |
| 468 | |
| 469 | if (!populated_zone(zone)) |
| 470 | continue; |
| 471 | |
| 472 | spin_lock_irqsave(&zone->lock, flags); |
| 473 | seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name); |
| 474 | seq_printf(m, |
| 475 | "\n pages free %lu" |
| 476 | "\n min %lu" |
| 477 | "\n low %lu" |
| 478 | "\n high %lu" |
| 479 | "\n active %lu" |
| 480 | "\n inactive %lu" |
| 481 | "\n scanned %lu (a: %lu i: %lu)" |
| 482 | "\n spanned %lu" |
| 483 | "\n present %lu", |
| 484 | zone->free_pages, |
| 485 | zone->pages_min, |
| 486 | zone->pages_low, |
| 487 | zone->pages_high, |
| 488 | zone->nr_active, |
| 489 | zone->nr_inactive, |
| 490 | zone->pages_scanned, |
| 491 | zone->nr_scan_active, zone->nr_scan_inactive, |
| 492 | zone->spanned_pages, |
| 493 | zone->present_pages); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 494 | |
| 495 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 496 | seq_printf(m, "\n %-12s %lu", vmstat_text[i], |
| 497 | zone_page_state(zone, i)); |
| 498 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 499 | seq_printf(m, |
| 500 | "\n protection: (%lu", |
| 501 | zone->lowmem_reserve[0]); |
| 502 | for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++) |
| 503 | seq_printf(m, ", %lu", zone->lowmem_reserve[i]); |
| 504 | seq_printf(m, |
| 505 | ")" |
| 506 | "\n pagesets"); |
| 507 | for_each_online_cpu(i) { |
| 508 | struct per_cpu_pageset *pageset; |
| 509 | int j; |
| 510 | |
| 511 | pageset = zone_pcp(zone, i); |
| 512 | for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) { |
| 513 | if (pageset->pcp[j].count) |
| 514 | break; |
| 515 | } |
| 516 | if (j == ARRAY_SIZE(pageset->pcp)) |
| 517 | continue; |
| 518 | for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) { |
| 519 | seq_printf(m, |
| 520 | "\n cpu: %i pcp: %i" |
| 521 | "\n count: %i" |
| 522 | "\n high: %i" |
| 523 | "\n batch: %i", |
| 524 | i, j, |
| 525 | pageset->pcp[j].count, |
| 526 | pageset->pcp[j].high, |
| 527 | pageset->pcp[j].batch); |
| 528 | } |
| 529 | #ifdef CONFIG_NUMA |
| 530 | seq_printf(m, |
| 531 | "\n numa_hit: %lu" |
| 532 | "\n numa_miss: %lu" |
| 533 | "\n numa_foreign: %lu" |
| 534 | "\n interleave_hit: %lu" |
| 535 | "\n local_node: %lu" |
| 536 | "\n other_node: %lu", |
| 537 | pageset->numa_hit, |
| 538 | pageset->numa_miss, |
| 539 | pageset->numa_foreign, |
| 540 | pageset->interleave_hit, |
| 541 | pageset->local_node, |
| 542 | pageset->other_node); |
| 543 | #endif |
| 544 | } |
| 545 | seq_printf(m, |
| 546 | "\n all_unreclaimable: %u" |
| 547 | "\n prev_priority: %i" |
| 548 | "\n temp_priority: %i" |
| 549 | "\n start_pfn: %lu", |
| 550 | zone->all_unreclaimable, |
| 551 | zone->prev_priority, |
| 552 | zone->temp_priority, |
| 553 | zone->zone_start_pfn); |
| 554 | spin_unlock_irqrestore(&zone->lock, flags); |
| 555 | seq_putc(m, '\n'); |
| 556 | } |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | struct seq_operations zoneinfo_op = { |
| 561 | .start = frag_start, /* iterate over all zones. The same as in |
| 562 | * fragmentation. */ |
| 563 | .next = frag_next, |
| 564 | .stop = frag_stop, |
| 565 | .show = zoneinfo_show, |
| 566 | }; |
| 567 | |
| 568 | static void *vmstat_start(struct seq_file *m, loff_t *pos) |
| 569 | { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 570 | unsigned long *v; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 571 | struct page_state *ps; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 572 | int i; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 573 | |
| 574 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 575 | return NULL; |
| 576 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 577 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) |
| 578 | + sizeof(*ps), GFP_KERNEL); |
| 579 | m->private = v; |
| 580 | if (!v) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 581 | return ERR_PTR(-ENOMEM); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 582 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 583 | v[i] = global_page_state(i); |
| 584 | ps = (struct page_state *)(v + NR_VM_ZONE_STAT_ITEMS); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 585 | get_full_page_state(ps); |
| 586 | ps->pgpgin /= 2; /* sectors -> kbytes */ |
| 587 | ps->pgpgout /= 2; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 588 | return v + *pos; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) |
| 592 | { |
| 593 | (*pos)++; |
| 594 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 595 | return NULL; |
| 596 | return (unsigned long *)m->private + *pos; |
| 597 | } |
| 598 | |
| 599 | static int vmstat_show(struct seq_file *m, void *arg) |
| 600 | { |
| 601 | unsigned long *l = arg; |
| 602 | unsigned long off = l - (unsigned long *)m->private; |
| 603 | |
| 604 | seq_printf(m, "%s %lu\n", vmstat_text[off], *l); |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static void vmstat_stop(struct seq_file *m, void *arg) |
| 609 | { |
| 610 | kfree(m->private); |
| 611 | m->private = NULL; |
| 612 | } |
| 613 | |
| 614 | struct seq_operations vmstat_op = { |
| 615 | .start = vmstat_start, |
| 616 | .next = vmstat_next, |
| 617 | .stop = vmstat_stop, |
| 618 | .show = vmstat_show, |
| 619 | }; |
| 620 | |
| 621 | #endif /* CONFIG_PROC_FS */ |
| 622 | |