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 | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 15 | #include <linux/cpu.h> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 16 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 17 | void __get_zone_counts(unsigned long *active, unsigned long *inactive, |
| 18 | unsigned long *free, struct pglist_data *pgdat) |
| 19 | { |
| 20 | struct zone *zones = pgdat->node_zones; |
| 21 | int i; |
| 22 | |
| 23 | *active = 0; |
| 24 | *inactive = 0; |
| 25 | *free = 0; |
| 26 | for (i = 0; i < MAX_NR_ZONES; i++) { |
| 27 | *active += zones[i].nr_active; |
| 28 | *inactive += zones[i].nr_inactive; |
| 29 | *free += zones[i].free_pages; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void get_zone_counts(unsigned long *active, |
| 34 | unsigned long *inactive, unsigned long *free) |
| 35 | { |
| 36 | struct pglist_data *pgdat; |
| 37 | |
| 38 | *active = 0; |
| 39 | *inactive = 0; |
| 40 | *free = 0; |
| 41 | for_each_online_pgdat(pgdat) { |
| 42 | unsigned long l, m, n; |
| 43 | __get_zone_counts(&l, &m, &n, pgdat); |
| 44 | *active += l; |
| 45 | *inactive += m; |
| 46 | *free += n; |
| 47 | } |
| 48 | } |
| 49 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 50 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 51 | DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; |
| 52 | EXPORT_PER_CPU_SYMBOL(vm_event_states); |
| 53 | |
| 54 | static void sum_vm_events(unsigned long *ret, cpumask_t *cpumask) |
| 55 | { |
| 56 | int cpu = 0; |
| 57 | int i; |
| 58 | |
| 59 | memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); |
| 60 | |
| 61 | cpu = first_cpu(*cpumask); |
| 62 | while (cpu < NR_CPUS) { |
| 63 | struct vm_event_state *this = &per_cpu(vm_event_states, cpu); |
| 64 | |
| 65 | cpu = next_cpu(cpu, *cpumask); |
| 66 | |
| 67 | if (cpu < NR_CPUS) |
| 68 | prefetch(&per_cpu(vm_event_states, cpu)); |
| 69 | |
| 70 | |
| 71 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) |
| 72 | ret[i] += this->event[i]; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Accumulate the vm event counters across all CPUs. |
| 78 | * The result is unavoidably approximate - it can change |
| 79 | * during and after execution of this function. |
| 80 | */ |
| 81 | void all_vm_events(unsigned long *ret) |
| 82 | { |
| 83 | sum_vm_events(ret, &cpu_online_map); |
| 84 | } |
Heiko Carstens | 32dd66f | 2006-07-10 04:44:31 -0700 | [diff] [blame] | 85 | EXPORT_SYMBOL_GPL(all_vm_events); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 86 | |
| 87 | #ifdef CONFIG_HOTPLUG |
| 88 | /* |
| 89 | * Fold the foreign cpu events into our own. |
| 90 | * |
| 91 | * This is adding to the events on one processor |
| 92 | * but keeps the global counts constant. |
| 93 | */ |
| 94 | void vm_events_fold_cpu(int cpu) |
| 95 | { |
| 96 | struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); |
| 97 | int i; |
| 98 | |
| 99 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { |
| 100 | count_vm_events(i, fold_state->event[i]); |
| 101 | fold_state->event[i] = 0; |
| 102 | } |
| 103 | } |
| 104 | #endif /* CONFIG_HOTPLUG */ |
| 105 | |
| 106 | #endif /* CONFIG_VM_EVENT_COUNTERS */ |
| 107 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 108 | /* |
| 109 | * Manage combined zone based / global counters |
| 110 | * |
| 111 | * vm_stat contains the global counters |
| 112 | */ |
| 113 | atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; |
| 114 | EXPORT_SYMBOL(vm_stat); |
| 115 | |
| 116 | #ifdef CONFIG_SMP |
| 117 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 118 | static int calculate_threshold(struct zone *zone) |
| 119 | { |
| 120 | int threshold; |
| 121 | int mem; /* memory in 128 MB units */ |
| 122 | |
| 123 | /* |
| 124 | * The threshold scales with the number of processors and the amount |
| 125 | * of memory per zone. More memory means that we can defer updates for |
| 126 | * longer, more processors could lead to more contention. |
| 127 | * fls() is used to have a cheap way of logarithmic scaling. |
| 128 | * |
| 129 | * Some sample thresholds: |
| 130 | * |
| 131 | * Threshold Processors (fls) Zonesize fls(mem+1) |
| 132 | * ------------------------------------------------------------------ |
| 133 | * 8 1 1 0.9-1 GB 4 |
| 134 | * 16 2 2 0.9-1 GB 4 |
| 135 | * 20 2 2 1-2 GB 5 |
| 136 | * 24 2 2 2-4 GB 6 |
| 137 | * 28 2 2 4-8 GB 7 |
| 138 | * 32 2 2 8-16 GB 8 |
| 139 | * 4 2 2 <128M 1 |
| 140 | * 30 4 3 2-4 GB 5 |
| 141 | * 48 4 3 8-16 GB 8 |
| 142 | * 32 8 4 1-2 GB 4 |
| 143 | * 32 8 4 0.9-1GB 4 |
| 144 | * 10 16 5 <128M 1 |
| 145 | * 40 16 5 900M 4 |
| 146 | * 70 64 7 2-4 GB 5 |
| 147 | * 84 64 7 4-8 GB 6 |
| 148 | * 108 512 9 4-8 GB 6 |
| 149 | * 125 1024 10 8-16 GB 8 |
| 150 | * 125 1024 10 16-32 GB 9 |
| 151 | */ |
| 152 | |
| 153 | mem = zone->present_pages >> (27 - PAGE_SHIFT); |
| 154 | |
| 155 | threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem)); |
| 156 | |
| 157 | /* |
| 158 | * Maximum threshold is 125 |
| 159 | */ |
| 160 | threshold = min(125, threshold); |
| 161 | |
| 162 | return threshold; |
| 163 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 164 | |
| 165 | /* |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 166 | * Refresh the thresholds for each zone. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 167 | */ |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 168 | static void refresh_zone_stat_thresholds(void) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 169 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 170 | struct zone *zone; |
| 171 | int cpu; |
| 172 | int threshold; |
| 173 | |
| 174 | for_each_zone(zone) { |
| 175 | |
| 176 | if (!zone->present_pages) |
| 177 | continue; |
| 178 | |
| 179 | threshold = calculate_threshold(zone); |
| 180 | |
| 181 | for_each_online_cpu(cpu) |
| 182 | zone_pcp(zone, cpu)->stat_threshold = threshold; |
| 183 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* |
| 187 | * For use when we know that interrupts are disabled. |
| 188 | */ |
| 189 | void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 190 | int delta) |
| 191 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 192 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 193 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 194 | long x; |
| 195 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 196 | x = delta + *p; |
| 197 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 198 | if (unlikely(x > pcp->stat_threshold || x < -pcp->stat_threshold)) { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 199 | zone_page_state_add(x, zone, item); |
| 200 | x = 0; |
| 201 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 202 | *p = x; |
| 203 | } |
| 204 | EXPORT_SYMBOL(__mod_zone_page_state); |
| 205 | |
| 206 | /* |
| 207 | * For an unknown interrupt state |
| 208 | */ |
| 209 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 210 | int delta) |
| 211 | { |
| 212 | unsigned long flags; |
| 213 | |
| 214 | local_irq_save(flags); |
| 215 | __mod_zone_page_state(zone, item, delta); |
| 216 | local_irq_restore(flags); |
| 217 | } |
| 218 | EXPORT_SYMBOL(mod_zone_page_state); |
| 219 | |
| 220 | /* |
| 221 | * Optimized increment and decrement functions. |
| 222 | * |
| 223 | * These are only for a single page and therefore can take a struct page * |
| 224 | * argument instead of struct zone *. This allows the inclusion of the code |
| 225 | * generated for page_zone(page) into the optimized functions. |
| 226 | * |
| 227 | * No overflow check is necessary and therefore the differential can be |
| 228 | * incremented or decremented in place which may allow the compilers to |
| 229 | * generate better code. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 230 | * The increment or decrement is known and therefore one boundary check can |
| 231 | * be omitted. |
| 232 | * |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 233 | * NOTE: These functions are very performance sensitive. Change only |
| 234 | * with care. |
| 235 | * |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 236 | * Some processors have inc/dec instructions that are atomic vs an interrupt. |
| 237 | * However, the code must first determine the differential location in a zone |
| 238 | * based on the processor number and then inc/dec the counter. There is no |
| 239 | * guarantee without disabling preemption that the processor will not change |
| 240 | * in between and therefore the atomicity vs. interrupt cannot be exploited |
| 241 | * in a useful way here. |
| 242 | */ |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 243 | static void __inc_zone_state(struct zone *zone, enum zone_stat_item item) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 244 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 245 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 246 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 247 | |
| 248 | (*p)++; |
| 249 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 250 | if (unlikely(*p > pcp->stat_threshold)) { |
| 251 | int overstep = pcp->stat_threshold / 2; |
| 252 | |
| 253 | zone_page_state_add(*p + overstep, zone, item); |
| 254 | *p = -overstep; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 257 | |
| 258 | void __inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 259 | { |
| 260 | __inc_zone_state(page_zone(page), item); |
| 261 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 262 | EXPORT_SYMBOL(__inc_zone_page_state); |
| 263 | |
| 264 | void __dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 265 | { |
| 266 | struct zone *zone = page_zone(page); |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 267 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 268 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 269 | |
| 270 | (*p)--; |
| 271 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 272 | if (unlikely(*p < - pcp->stat_threshold)) { |
| 273 | int overstep = pcp->stat_threshold / 2; |
| 274 | |
| 275 | zone_page_state_add(*p - overstep, zone, item); |
| 276 | *p = overstep; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | EXPORT_SYMBOL(__dec_zone_page_state); |
| 280 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 281 | void inc_zone_state(struct zone *zone, enum zone_stat_item item) |
| 282 | { |
| 283 | unsigned long flags; |
| 284 | |
| 285 | local_irq_save(flags); |
| 286 | __inc_zone_state(zone, item); |
| 287 | local_irq_restore(flags); |
| 288 | } |
| 289 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 290 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 291 | { |
| 292 | unsigned long flags; |
| 293 | struct zone *zone; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 294 | |
| 295 | zone = page_zone(page); |
| 296 | local_irq_save(flags); |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 297 | __inc_zone_state(zone, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 298 | local_irq_restore(flags); |
| 299 | } |
| 300 | EXPORT_SYMBOL(inc_zone_page_state); |
| 301 | |
| 302 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 303 | { |
| 304 | unsigned long flags; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 305 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 306 | local_irq_save(flags); |
Christoph Lameter | a302eb4 | 2006-08-31 21:27:34 -0700 | [diff] [blame] | 307 | __dec_zone_page_state(page, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 308 | local_irq_restore(flags); |
| 309 | } |
| 310 | EXPORT_SYMBOL(dec_zone_page_state); |
| 311 | |
| 312 | /* |
| 313 | * Update the zone counters for one cpu. |
| 314 | */ |
| 315 | void refresh_cpu_vm_stats(int cpu) |
| 316 | { |
| 317 | struct zone *zone; |
| 318 | int i; |
| 319 | unsigned long flags; |
| 320 | |
| 321 | for_each_zone(zone) { |
| 322 | struct per_cpu_pageset *pcp; |
| 323 | |
Christoph Lameter | 39bbcb8 | 2006-09-25 23:31:49 -0700 | [diff] [blame] | 324 | if (!populated_zone(zone)) |
| 325 | continue; |
| 326 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 327 | pcp = zone_pcp(zone, cpu); |
| 328 | |
| 329 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 330 | if (pcp->vm_stat_diff[i]) { |
| 331 | local_irq_save(flags); |
| 332 | zone_page_state_add(pcp->vm_stat_diff[i], |
| 333 | zone, i); |
| 334 | pcp->vm_stat_diff[i] = 0; |
| 335 | local_irq_restore(flags); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static void __refresh_cpu_vm_stats(void *dummy) |
| 341 | { |
| 342 | refresh_cpu_vm_stats(smp_processor_id()); |
| 343 | } |
| 344 | |
| 345 | /* |
| 346 | * Consolidate all counters. |
| 347 | * |
| 348 | * Note that the result is less inaccurate but still inaccurate |
| 349 | * if concurrent processes are allowed to run. |
| 350 | */ |
| 351 | void refresh_vm_stats(void) |
| 352 | { |
| 353 | on_each_cpu(__refresh_cpu_vm_stats, NULL, 0, 1); |
| 354 | } |
| 355 | EXPORT_SYMBOL(refresh_vm_stats); |
| 356 | |
| 357 | #endif |
| 358 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 359 | #ifdef CONFIG_NUMA |
| 360 | /* |
| 361 | * zonelist = the list of zones passed to the allocator |
| 362 | * z = the zone from which the allocation occurred. |
| 363 | * |
| 364 | * Must be called with interrupts disabled. |
| 365 | */ |
| 366 | void zone_statistics(struct zonelist *zonelist, struct zone *z) |
| 367 | { |
| 368 | if (z->zone_pgdat == zonelist->zones[0]->zone_pgdat) { |
| 369 | __inc_zone_state(z, NUMA_HIT); |
| 370 | } else { |
| 371 | __inc_zone_state(z, NUMA_MISS); |
| 372 | __inc_zone_state(zonelist->zones[0], NUMA_FOREIGN); |
| 373 | } |
| 374 | if (z->zone_pgdat == NODE_DATA(numa_node_id())) |
| 375 | __inc_zone_state(z, NUMA_LOCAL); |
| 376 | else |
| 377 | __inc_zone_state(z, NUMA_OTHER); |
| 378 | } |
| 379 | #endif |
| 380 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 381 | #ifdef CONFIG_PROC_FS |
| 382 | |
| 383 | #include <linux/seq_file.h> |
| 384 | |
| 385 | static void *frag_start(struct seq_file *m, loff_t *pos) |
| 386 | { |
| 387 | pg_data_t *pgdat; |
| 388 | loff_t node = *pos; |
| 389 | for (pgdat = first_online_pgdat(); |
| 390 | pgdat && node; |
| 391 | pgdat = next_online_pgdat(pgdat)) |
| 392 | --node; |
| 393 | |
| 394 | return pgdat; |
| 395 | } |
| 396 | |
| 397 | static void *frag_next(struct seq_file *m, void *arg, loff_t *pos) |
| 398 | { |
| 399 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 400 | |
| 401 | (*pos)++; |
| 402 | return next_online_pgdat(pgdat); |
| 403 | } |
| 404 | |
| 405 | static void frag_stop(struct seq_file *m, void *arg) |
| 406 | { |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * This walks the free areas for each zone. |
| 411 | */ |
| 412 | static int frag_show(struct seq_file *m, void *arg) |
| 413 | { |
| 414 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 415 | struct zone *zone; |
| 416 | struct zone *node_zones = pgdat->node_zones; |
| 417 | unsigned long flags; |
| 418 | int order; |
| 419 | |
| 420 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { |
| 421 | if (!populated_zone(zone)) |
| 422 | continue; |
| 423 | |
| 424 | spin_lock_irqsave(&zone->lock, flags); |
| 425 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); |
| 426 | for (order = 0; order < MAX_ORDER; ++order) |
| 427 | seq_printf(m, "%6lu ", zone->free_area[order].nr_free); |
| 428 | spin_unlock_irqrestore(&zone->lock, flags); |
| 429 | seq_putc(m, '\n'); |
| 430 | } |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | struct seq_operations fragmentation_op = { |
| 435 | .start = frag_start, |
| 436 | .next = frag_next, |
| 437 | .stop = frag_stop, |
| 438 | .show = frag_show, |
| 439 | }; |
| 440 | |
Christoph Lameter | 27bf71c | 2006-09-25 23:31:15 -0700 | [diff] [blame] | 441 | #ifdef CONFIG_ZONE_DMA32 |
| 442 | #define TEXT_FOR_DMA32(xx) xx "_dma32", |
| 443 | #else |
| 444 | #define TEXT_FOR_DMA32(xx) |
| 445 | #endif |
| 446 | |
| 447 | #ifdef CONFIG_HIGHMEM |
| 448 | #define TEXT_FOR_HIGHMEM(xx) xx "_high", |
| 449 | #else |
| 450 | #define TEXT_FOR_HIGHMEM(xx) |
| 451 | #endif |
| 452 | |
| 453 | #define TEXTS_FOR_ZONES(xx) xx "_dma", TEXT_FOR_DMA32(xx) xx "_normal", \ |
| 454 | TEXT_FOR_HIGHMEM(xx) |
| 455 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 456 | static char *vmstat_text[] = { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 457 | /* Zoned VM counters */ |
Christoph Lameter | f3dbd34 | 2006-06-30 01:55:36 -0700 | [diff] [blame] | 458 | "nr_anon_pages", |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 459 | "nr_mapped", |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 460 | "nr_file_pages", |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 461 | "nr_slab_reclaimable", |
| 462 | "nr_slab_unreclaimable", |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 463 | "nr_page_table_pages", |
Christoph Lameter | b1e7a8f | 2006-06-30 01:55:39 -0700 | [diff] [blame] | 464 | "nr_dirty", |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 465 | "nr_writeback", |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 466 | "nr_unstable", |
Christoph Lameter | d2c5e30 | 2006-06-30 01:55:41 -0700 | [diff] [blame] | 467 | "nr_bounce", |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 468 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 469 | #ifdef CONFIG_NUMA |
| 470 | "numa_hit", |
| 471 | "numa_miss", |
| 472 | "numa_foreign", |
| 473 | "numa_interleave", |
| 474 | "numa_local", |
| 475 | "numa_other", |
| 476 | #endif |
| 477 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 478 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 479 | "pgpgin", |
| 480 | "pgpgout", |
| 481 | "pswpin", |
| 482 | "pswpout", |
| 483 | |
Christoph Lameter | 27bf71c | 2006-09-25 23:31:15 -0700 | [diff] [blame] | 484 | TEXTS_FOR_ZONES("pgalloc") |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 485 | |
| 486 | "pgfree", |
| 487 | "pgactivate", |
| 488 | "pgdeactivate", |
| 489 | |
| 490 | "pgfault", |
| 491 | "pgmajfault", |
| 492 | |
Christoph Lameter | 27bf71c | 2006-09-25 23:31:15 -0700 | [diff] [blame] | 493 | TEXTS_FOR_ZONES("pgrefill") |
| 494 | TEXTS_FOR_ZONES("pgsteal") |
| 495 | TEXTS_FOR_ZONES("pgscan_kswapd") |
| 496 | TEXTS_FOR_ZONES("pgscan_direct") |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 497 | |
| 498 | "pginodesteal", |
| 499 | "slabs_scanned", |
| 500 | "kswapd_steal", |
| 501 | "kswapd_inodesteal", |
| 502 | "pageoutrun", |
| 503 | "allocstall", |
| 504 | |
| 505 | "pgrotated", |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 506 | #endif |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | /* |
| 510 | * Output information about zones in @pgdat. |
| 511 | */ |
| 512 | static int zoneinfo_show(struct seq_file *m, void *arg) |
| 513 | { |
| 514 | pg_data_t *pgdat = arg; |
| 515 | struct zone *zone; |
| 516 | struct zone *node_zones = pgdat->node_zones; |
| 517 | unsigned long flags; |
| 518 | |
| 519 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; zone++) { |
| 520 | int i; |
| 521 | |
| 522 | if (!populated_zone(zone)) |
| 523 | continue; |
| 524 | |
| 525 | spin_lock_irqsave(&zone->lock, flags); |
| 526 | seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name); |
| 527 | seq_printf(m, |
| 528 | "\n pages free %lu" |
| 529 | "\n min %lu" |
| 530 | "\n low %lu" |
| 531 | "\n high %lu" |
| 532 | "\n active %lu" |
| 533 | "\n inactive %lu" |
| 534 | "\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, |
| 541 | zone->nr_active, |
| 542 | zone->nr_inactive, |
| 543 | zone->pages_scanned, |
| 544 | zone->nr_scan_active, zone->nr_scan_inactive, |
| 545 | zone->spanned_pages, |
| 546 | zone->present_pages); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 547 | |
| 548 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 549 | seq_printf(m, "\n %-12s %lu", vmstat_text[i], |
| 550 | zone_page_state(zone, i)); |
| 551 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 552 | seq_printf(m, |
| 553 | "\n protection: (%lu", |
| 554 | zone->lowmem_reserve[0]); |
| 555 | for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++) |
| 556 | seq_printf(m, ", %lu", zone->lowmem_reserve[i]); |
| 557 | seq_printf(m, |
| 558 | ")" |
| 559 | "\n pagesets"); |
| 560 | for_each_online_cpu(i) { |
| 561 | struct per_cpu_pageset *pageset; |
| 562 | int j; |
| 563 | |
| 564 | pageset = zone_pcp(zone, i); |
| 565 | for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) { |
| 566 | if (pageset->pcp[j].count) |
| 567 | break; |
| 568 | } |
| 569 | if (j == ARRAY_SIZE(pageset->pcp)) |
| 570 | continue; |
| 571 | for (j = 0; j < ARRAY_SIZE(pageset->pcp); j++) { |
| 572 | seq_printf(m, |
| 573 | "\n cpu: %i pcp: %i" |
| 574 | "\n count: %i" |
| 575 | "\n high: %i" |
| 576 | "\n batch: %i", |
| 577 | i, j, |
| 578 | pageset->pcp[j].count, |
| 579 | pageset->pcp[j].high, |
| 580 | pageset->pcp[j].batch); |
| 581 | } |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 582 | #ifdef CONFIG_SMP |
| 583 | seq_printf(m, "\n vm stats threshold: %d", |
| 584 | pageset->stat_threshold); |
| 585 | #endif |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 586 | } |
| 587 | seq_printf(m, |
| 588 | "\n all_unreclaimable: %u" |
| 589 | "\n prev_priority: %i" |
| 590 | "\n temp_priority: %i" |
| 591 | "\n start_pfn: %lu", |
| 592 | zone->all_unreclaimable, |
| 593 | zone->prev_priority, |
| 594 | zone->temp_priority, |
| 595 | zone->zone_start_pfn); |
| 596 | spin_unlock_irqrestore(&zone->lock, flags); |
| 597 | seq_putc(m, '\n'); |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | struct seq_operations zoneinfo_op = { |
| 603 | .start = frag_start, /* iterate over all zones. The same as in |
| 604 | * fragmentation. */ |
| 605 | .next = frag_next, |
| 606 | .stop = frag_stop, |
| 607 | .show = zoneinfo_show, |
| 608 | }; |
| 609 | |
| 610 | static void *vmstat_start(struct seq_file *m, loff_t *pos) |
| 611 | { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 612 | unsigned long *v; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 613 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 614 | unsigned long *e; |
| 615 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 616 | int i; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 617 | |
| 618 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 619 | return NULL; |
| 620 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 621 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 622 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 623 | + sizeof(struct vm_event_state), GFP_KERNEL); |
| 624 | #else |
| 625 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long), |
| 626 | GFP_KERNEL); |
| 627 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 628 | m->private = v; |
| 629 | if (!v) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 630 | return ERR_PTR(-ENOMEM); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 631 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 632 | v[i] = global_page_state(i); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 633 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 634 | e = v + NR_VM_ZONE_STAT_ITEMS; |
| 635 | all_vm_events(e); |
| 636 | e[PGPGIN] /= 2; /* sectors -> kbytes */ |
| 637 | e[PGPGOUT] /= 2; |
| 638 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 639 | return v + *pos; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) |
| 643 | { |
| 644 | (*pos)++; |
| 645 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 646 | return NULL; |
| 647 | return (unsigned long *)m->private + *pos; |
| 648 | } |
| 649 | |
| 650 | static int vmstat_show(struct seq_file *m, void *arg) |
| 651 | { |
| 652 | unsigned long *l = arg; |
| 653 | unsigned long off = l - (unsigned long *)m->private; |
| 654 | |
| 655 | seq_printf(m, "%s %lu\n", vmstat_text[off], *l); |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static void vmstat_stop(struct seq_file *m, void *arg) |
| 660 | { |
| 661 | kfree(m->private); |
| 662 | m->private = NULL; |
| 663 | } |
| 664 | |
| 665 | struct seq_operations vmstat_op = { |
| 666 | .start = vmstat_start, |
| 667 | .next = vmstat_next, |
| 668 | .stop = vmstat_stop, |
| 669 | .show = vmstat_show, |
| 670 | }; |
| 671 | |
| 672 | #endif /* CONFIG_PROC_FS */ |
| 673 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 674 | #ifdef CONFIG_SMP |
| 675 | /* |
| 676 | * Use the cpu notifier to insure that the thresholds are recalculated |
| 677 | * when necessary. |
| 678 | */ |
| 679 | static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb, |
| 680 | unsigned long action, |
| 681 | void *hcpu) |
| 682 | { |
| 683 | switch (action) { |
| 684 | case CPU_UP_PREPARE: |
| 685 | case CPU_UP_CANCELED: |
| 686 | case CPU_DEAD: |
| 687 | refresh_zone_stat_thresholds(); |
| 688 | break; |
| 689 | default: |
| 690 | break; |
| 691 | } |
| 692 | return NOTIFY_OK; |
| 693 | } |
| 694 | |
| 695 | static struct notifier_block __cpuinitdata vmstat_notifier = |
| 696 | { &vmstat_cpuup_callback, NULL, 0 }; |
| 697 | |
| 698 | int __init setup_vmstat(void) |
| 699 | { |
| 700 | refresh_zone_stat_thresholds(); |
| 701 | register_cpu_notifier(&vmstat_notifier); |
| 702 | return 0; |
| 703 | } |
| 704 | module_init(setup_vmstat) |
| 705 | #endif |