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 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 12 | #include <linux/mm.h> |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 14 | #include <linux/cpu.h> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 15 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 16 | void __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 | |
| 22 | *active = 0; |
| 23 | *inactive = 0; |
| 24 | *free = 0; |
| 25 | for (i = 0; i < MAX_NR_ZONES; i++) { |
| 26 | *active += zones[i].nr_active; |
| 27 | *inactive += zones[i].nr_inactive; |
| 28 | *free += zones[i].free_pages; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void get_zone_counts(unsigned long *active, |
| 33 | unsigned long *inactive, unsigned long *free) |
| 34 | { |
| 35 | struct pglist_data *pgdat; |
| 36 | |
| 37 | *active = 0; |
| 38 | *inactive = 0; |
| 39 | *free = 0; |
| 40 | for_each_online_pgdat(pgdat) { |
| 41 | unsigned long l, m, n; |
| 42 | __get_zone_counts(&l, &m, &n, pgdat); |
| 43 | *active += l; |
| 44 | *inactive += m; |
| 45 | *free += n; |
| 46 | } |
| 47 | } |
| 48 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 49 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 50 | DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; |
| 51 | EXPORT_PER_CPU_SYMBOL(vm_event_states); |
| 52 | |
| 53 | static void sum_vm_events(unsigned long *ret, cpumask_t *cpumask) |
| 54 | { |
| 55 | int cpu = 0; |
| 56 | int i; |
| 57 | |
| 58 | memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); |
| 59 | |
| 60 | cpu = first_cpu(*cpumask); |
| 61 | while (cpu < NR_CPUS) { |
| 62 | struct vm_event_state *this = &per_cpu(vm_event_states, cpu); |
| 63 | |
| 64 | cpu = next_cpu(cpu, *cpumask); |
| 65 | |
| 66 | if (cpu < NR_CPUS) |
| 67 | prefetch(&per_cpu(vm_event_states, cpu)); |
| 68 | |
| 69 | |
| 70 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) |
| 71 | ret[i] += this->event[i]; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * Accumulate the vm event counters across all CPUs. |
| 77 | * The result is unavoidably approximate - it can change |
| 78 | * during and after execution of this function. |
| 79 | */ |
| 80 | void all_vm_events(unsigned long *ret) |
| 81 | { |
| 82 | sum_vm_events(ret, &cpu_online_map); |
| 83 | } |
Heiko Carstens | 32dd66f | 2006-07-10 04:44:31 -0700 | [diff] [blame] | 84 | EXPORT_SYMBOL_GPL(all_vm_events); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 85 | |
| 86 | #ifdef CONFIG_HOTPLUG |
| 87 | /* |
| 88 | * Fold the foreign cpu events into our own. |
| 89 | * |
| 90 | * This is adding to the events on one processor |
| 91 | * but keeps the global counts constant. |
| 92 | */ |
| 93 | void vm_events_fold_cpu(int cpu) |
| 94 | { |
| 95 | struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); |
| 96 | int i; |
| 97 | |
| 98 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { |
| 99 | count_vm_events(i, fold_state->event[i]); |
| 100 | fold_state->event[i] = 0; |
| 101 | } |
| 102 | } |
| 103 | #endif /* CONFIG_HOTPLUG */ |
| 104 | |
| 105 | #endif /* CONFIG_VM_EVENT_COUNTERS */ |
| 106 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 107 | /* |
| 108 | * Manage combined zone based / global counters |
| 109 | * |
| 110 | * vm_stat contains the global counters |
| 111 | */ |
| 112 | atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; |
| 113 | EXPORT_SYMBOL(vm_stat); |
| 114 | |
| 115 | #ifdef CONFIG_SMP |
| 116 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 117 | static int calculate_threshold(struct zone *zone) |
| 118 | { |
| 119 | int threshold; |
| 120 | int mem; /* memory in 128 MB units */ |
| 121 | |
| 122 | /* |
| 123 | * The threshold scales with the number of processors and the amount |
| 124 | * of memory per zone. More memory means that we can defer updates for |
| 125 | * longer, more processors could lead to more contention. |
| 126 | * fls() is used to have a cheap way of logarithmic scaling. |
| 127 | * |
| 128 | * Some sample thresholds: |
| 129 | * |
| 130 | * Threshold Processors (fls) Zonesize fls(mem+1) |
| 131 | * ------------------------------------------------------------------ |
| 132 | * 8 1 1 0.9-1 GB 4 |
| 133 | * 16 2 2 0.9-1 GB 4 |
| 134 | * 20 2 2 1-2 GB 5 |
| 135 | * 24 2 2 2-4 GB 6 |
| 136 | * 28 2 2 4-8 GB 7 |
| 137 | * 32 2 2 8-16 GB 8 |
| 138 | * 4 2 2 <128M 1 |
| 139 | * 30 4 3 2-4 GB 5 |
| 140 | * 48 4 3 8-16 GB 8 |
| 141 | * 32 8 4 1-2 GB 4 |
| 142 | * 32 8 4 0.9-1GB 4 |
| 143 | * 10 16 5 <128M 1 |
| 144 | * 40 16 5 900M 4 |
| 145 | * 70 64 7 2-4 GB 5 |
| 146 | * 84 64 7 4-8 GB 6 |
| 147 | * 108 512 9 4-8 GB 6 |
| 148 | * 125 1024 10 8-16 GB 8 |
| 149 | * 125 1024 10 16-32 GB 9 |
| 150 | */ |
| 151 | |
| 152 | mem = zone->present_pages >> (27 - PAGE_SHIFT); |
| 153 | |
| 154 | threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem)); |
| 155 | |
| 156 | /* |
| 157 | * Maximum threshold is 125 |
| 158 | */ |
| 159 | threshold = min(125, threshold); |
| 160 | |
| 161 | return threshold; |
| 162 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 163 | |
| 164 | /* |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 165 | * Refresh the thresholds for each zone. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 166 | */ |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 167 | static void refresh_zone_stat_thresholds(void) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 168 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 169 | struct zone *zone; |
| 170 | int cpu; |
| 171 | int threshold; |
| 172 | |
| 173 | for_each_zone(zone) { |
| 174 | |
| 175 | if (!zone->present_pages) |
| 176 | continue; |
| 177 | |
| 178 | threshold = calculate_threshold(zone); |
| 179 | |
| 180 | for_each_online_cpu(cpu) |
| 181 | zone_pcp(zone, cpu)->stat_threshold = threshold; |
| 182 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* |
| 186 | * For use when we know that interrupts are disabled. |
| 187 | */ |
| 188 | void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 189 | int delta) |
| 190 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 191 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 192 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 193 | long x; |
| 194 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 195 | x = delta + *p; |
| 196 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 197 | if (unlikely(x > pcp->stat_threshold || x < -pcp->stat_threshold)) { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 198 | zone_page_state_add(x, zone, item); |
| 199 | x = 0; |
| 200 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 201 | *p = x; |
| 202 | } |
| 203 | EXPORT_SYMBOL(__mod_zone_page_state); |
| 204 | |
| 205 | /* |
| 206 | * For an unknown interrupt state |
| 207 | */ |
| 208 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
| 209 | int delta) |
| 210 | { |
| 211 | unsigned long flags; |
| 212 | |
| 213 | local_irq_save(flags); |
| 214 | __mod_zone_page_state(zone, item, delta); |
| 215 | local_irq_restore(flags); |
| 216 | } |
| 217 | EXPORT_SYMBOL(mod_zone_page_state); |
| 218 | |
| 219 | /* |
| 220 | * Optimized increment and decrement functions. |
| 221 | * |
| 222 | * These are only for a single page and therefore can take a struct page * |
| 223 | * argument instead of struct zone *. This allows the inclusion of the code |
| 224 | * generated for page_zone(page) into the optimized functions. |
| 225 | * |
| 226 | * No overflow check is necessary and therefore the differential can be |
| 227 | * incremented or decremented in place which may allow the compilers to |
| 228 | * generate better code. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 229 | * The increment or decrement is known and therefore one boundary check can |
| 230 | * be omitted. |
| 231 | * |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 232 | * NOTE: These functions are very performance sensitive. Change only |
| 233 | * with care. |
| 234 | * |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 235 | * Some processors have inc/dec instructions that are atomic vs an interrupt. |
| 236 | * However, the code must first determine the differential location in a zone |
| 237 | * based on the processor number and then inc/dec the counter. There is no |
| 238 | * guarantee without disabling preemption that the processor will not change |
| 239 | * in between and therefore the atomicity vs. interrupt cannot be exploited |
| 240 | * in a useful way here. |
| 241 | */ |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 242 | 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] | 243 | { |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 244 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 245 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 246 | |
| 247 | (*p)++; |
| 248 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 249 | if (unlikely(*p > pcp->stat_threshold)) { |
| 250 | int overstep = pcp->stat_threshold / 2; |
| 251 | |
| 252 | zone_page_state_add(*p + overstep, zone, item); |
| 253 | *p = -overstep; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 256 | |
| 257 | void __inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 258 | { |
| 259 | __inc_zone_state(page_zone(page), item); |
| 260 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 261 | EXPORT_SYMBOL(__inc_zone_page_state); |
| 262 | |
| 263 | void __dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 264 | { |
| 265 | struct zone *zone = page_zone(page); |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 266 | struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id()); |
| 267 | s8 *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 268 | |
| 269 | (*p)--; |
| 270 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 271 | if (unlikely(*p < - pcp->stat_threshold)) { |
| 272 | int overstep = pcp->stat_threshold / 2; |
| 273 | |
| 274 | zone_page_state_add(*p - overstep, zone, item); |
| 275 | *p = overstep; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | EXPORT_SYMBOL(__dec_zone_page_state); |
| 279 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 280 | void 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 Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 289 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 290 | { |
| 291 | unsigned long flags; |
| 292 | struct zone *zone; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 293 | |
| 294 | zone = page_zone(page); |
| 295 | local_irq_save(flags); |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 296 | __inc_zone_state(zone, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 297 | local_irq_restore(flags); |
| 298 | } |
| 299 | EXPORT_SYMBOL(inc_zone_page_state); |
| 300 | |
| 301 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 302 | { |
| 303 | unsigned long flags; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 304 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 305 | local_irq_save(flags); |
Christoph Lameter | a302eb4 | 2006-08-31 21:27:34 -0700 | [diff] [blame] | 306 | __dec_zone_page_state(page, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 307 | local_irq_restore(flags); |
| 308 | } |
| 309 | EXPORT_SYMBOL(dec_zone_page_state); |
| 310 | |
| 311 | /* |
| 312 | * Update the zone counters for one cpu. |
| 313 | */ |
| 314 | void 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 Lameter | 39bbcb8 | 2006-09-25 23:31:49 -0700 | [diff] [blame] | 323 | if (!populated_zone(zone)) |
| 324 | continue; |
| 325 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 326 | 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 | |
| 339 | static 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 | */ |
| 350 | void refresh_vm_stats(void) |
| 351 | { |
| 352 | on_each_cpu(__refresh_cpu_vm_stats, NULL, 0, 1); |
| 353 | } |
| 354 | EXPORT_SYMBOL(refresh_vm_stats); |
| 355 | |
| 356 | #endif |
| 357 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 358 | #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 | */ |
| 365 | void 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 Lameter | 5d29234 | 2006-09-27 01:50:10 -0700 | [diff] [blame] | 373 | if (z->node == numa_node_id()) |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 374 | __inc_zone_state(z, NUMA_LOCAL); |
| 375 | else |
| 376 | __inc_zone_state(z, NUMA_OTHER); |
| 377 | } |
| 378 | #endif |
| 379 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 380 | #ifdef CONFIG_PROC_FS |
| 381 | |
| 382 | #include <linux/seq_file.h> |
| 383 | |
| 384 | static 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 | |
| 396 | static 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 | |
| 404 | static void frag_stop(struct seq_file *m, void *arg) |
| 405 | { |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * This walks the free areas for each zone. |
| 410 | */ |
| 411 | static 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 Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 433 | const struct seq_operations fragmentation_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 434 | .start = frag_start, |
| 435 | .next = frag_next, |
| 436 | .stop = frag_stop, |
| 437 | .show = frag_show, |
| 438 | }; |
| 439 | |
Christoph Lameter | 27bf71c | 2006-09-25 23:31:15 -0700 | [diff] [blame] | 440 | #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 Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 455 | static const char * const vmstat_text[] = { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 456 | /* Zoned VM counters */ |
Christoph Lameter | f3dbd34 | 2006-06-30 01:55:36 -0700 | [diff] [blame] | 457 | "nr_anon_pages", |
Christoph Lameter | 65ba55f | 2006-06-30 01:55:34 -0700 | [diff] [blame] | 458 | "nr_mapped", |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 459 | "nr_file_pages", |
Christoph Lameter | 972d1a7 | 2006-09-25 23:31:51 -0700 | [diff] [blame] | 460 | "nr_slab_reclaimable", |
| 461 | "nr_slab_unreclaimable", |
Christoph Lameter | df849a1 | 2006-06-30 01:55:38 -0700 | [diff] [blame] | 462 | "nr_page_table_pages", |
Christoph Lameter | b1e7a8f | 2006-06-30 01:55:39 -0700 | [diff] [blame] | 463 | "nr_dirty", |
Christoph Lameter | ce866b3 | 2006-06-30 01:55:40 -0700 | [diff] [blame] | 464 | "nr_writeback", |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 465 | "nr_unstable", |
Christoph Lameter | d2c5e30 | 2006-06-30 01:55:41 -0700 | [diff] [blame] | 466 | "nr_bounce", |
Andrew Morton | e129b5c | 2006-09-27 01:50:00 -0700 | [diff] [blame] | 467 | "nr_vmscan_write", |
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" |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 590 | "\n start_pfn: %lu", |
| 591 | zone->all_unreclaimable, |
| 592 | zone->prev_priority, |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 593 | zone->zone_start_pfn); |
| 594 | spin_unlock_irqrestore(&zone->lock, flags); |
| 595 | seq_putc(m, '\n'); |
| 596 | } |
| 597 | return 0; |
| 598 | } |
| 599 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 600 | const struct seq_operations zoneinfo_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 601 | .start = frag_start, /* iterate over all zones. The same as in |
| 602 | * fragmentation. */ |
| 603 | .next = frag_next, |
| 604 | .stop = frag_stop, |
| 605 | .show = zoneinfo_show, |
| 606 | }; |
| 607 | |
| 608 | static void *vmstat_start(struct seq_file *m, loff_t *pos) |
| 609 | { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 610 | unsigned long *v; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 611 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 612 | unsigned long *e; |
| 613 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 614 | int i; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 615 | |
| 616 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 617 | return NULL; |
| 618 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 619 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 620 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 621 | + sizeof(struct vm_event_state), GFP_KERNEL); |
| 622 | #else |
| 623 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long), |
| 624 | GFP_KERNEL); |
| 625 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 626 | m->private = v; |
| 627 | if (!v) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 628 | return ERR_PTR(-ENOMEM); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 629 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 630 | v[i] = global_page_state(i); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 631 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 632 | e = v + NR_VM_ZONE_STAT_ITEMS; |
| 633 | all_vm_events(e); |
| 634 | e[PGPGIN] /= 2; /* sectors -> kbytes */ |
| 635 | e[PGPGOUT] /= 2; |
| 636 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 637 | return v + *pos; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) |
| 641 | { |
| 642 | (*pos)++; |
| 643 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 644 | return NULL; |
| 645 | return (unsigned long *)m->private + *pos; |
| 646 | } |
| 647 | |
| 648 | static int vmstat_show(struct seq_file *m, void *arg) |
| 649 | { |
| 650 | unsigned long *l = arg; |
| 651 | unsigned long off = l - (unsigned long *)m->private; |
| 652 | |
| 653 | seq_printf(m, "%s %lu\n", vmstat_text[off], *l); |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static void vmstat_stop(struct seq_file *m, void *arg) |
| 658 | { |
| 659 | kfree(m->private); |
| 660 | m->private = NULL; |
| 661 | } |
| 662 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 663 | const struct seq_operations vmstat_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 664 | .start = vmstat_start, |
| 665 | .next = vmstat_next, |
| 666 | .stop = vmstat_stop, |
| 667 | .show = vmstat_show, |
| 668 | }; |
| 669 | |
| 670 | #endif /* CONFIG_PROC_FS */ |
| 671 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 672 | #ifdef CONFIG_SMP |
| 673 | /* |
| 674 | * Use the cpu notifier to insure that the thresholds are recalculated |
| 675 | * when necessary. |
| 676 | */ |
| 677 | static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb, |
| 678 | unsigned long action, |
| 679 | void *hcpu) |
| 680 | { |
| 681 | switch (action) { |
Andy Whitcroft | ce421c7 | 2006-12-06 20:33:08 -0800 | [diff] [blame] | 682 | case CPU_UP_PREPARE: |
| 683 | case CPU_UP_CANCELED: |
| 684 | case CPU_DEAD: |
| 685 | refresh_zone_stat_thresholds(); |
| 686 | break; |
| 687 | default: |
| 688 | break; |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 689 | } |
| 690 | return NOTIFY_OK; |
| 691 | } |
| 692 | |
| 693 | static struct notifier_block __cpuinitdata vmstat_notifier = |
| 694 | { &vmstat_cpuup_callback, NULL, 0 }; |
| 695 | |
| 696 | int __init setup_vmstat(void) |
| 697 | { |
| 698 | refresh_zone_stat_thresholds(); |
| 699 | register_cpu_notifier(&vmstat_notifier); |
| 700 | return 0; |
| 701 | } |
| 702 | module_init(setup_vmstat) |
| 703 | #endif |