Commit | Line | Data |
---|---|---|
f6ac2354 CL |
1 | /* |
2 | * linux/mm/vmstat.c | |
3 | * | |
4 | * Manages VM statistics | |
5 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds | |
2244b95a CL |
6 | * |
7 | * zoned VM statistics | |
8 | * Copyright (C) 2006 Silicon Graphics, Inc., | |
9 | * Christoph Lameter <christoph@lameter.com> | |
f6ac2354 | 10 | */ |
8f32f7e5 | 11 | #include <linux/fs.h> |
f6ac2354 | 12 | #include <linux/mm.h> |
4e950f6f | 13 | #include <linux/err.h> |
2244b95a | 14 | #include <linux/module.h> |
5a0e3ad6 | 15 | #include <linux/slab.h> |
df9ecaba | 16 | #include <linux/cpu.h> |
c748e134 | 17 | #include <linux/vmstat.h> |
e8edc6e0 | 18 | #include <linux/sched.h> |
f6ac2354 | 19 | |
f8891e5e CL |
20 | #ifdef CONFIG_VM_EVENT_COUNTERS |
21 | DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; | |
22 | EXPORT_PER_CPU_SYMBOL(vm_event_states); | |
23 | ||
174596a0 | 24 | static void sum_vm_events(unsigned long *ret, const struct cpumask *cpumask) |
f8891e5e | 25 | { |
9eccf2a8 | 26 | int cpu; |
f8891e5e CL |
27 | int i; |
28 | ||
29 | memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); | |
30 | ||
aa85ea5b | 31 | for_each_cpu(cpu, cpumask) { |
f8891e5e CL |
32 | struct vm_event_state *this = &per_cpu(vm_event_states, cpu); |
33 | ||
f8891e5e CL |
34 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) |
35 | ret[i] += this->event[i]; | |
36 | } | |
37 | } | |
38 | ||
39 | /* | |
40 | * Accumulate the vm event counters across all CPUs. | |
41 | * The result is unavoidably approximate - it can change | |
42 | * during and after execution of this function. | |
43 | */ | |
44 | void all_vm_events(unsigned long *ret) | |
45 | { | |
b5be1132 | 46 | get_online_cpus(); |
174596a0 | 47 | sum_vm_events(ret, cpu_online_mask); |
b5be1132 | 48 | put_online_cpus(); |
f8891e5e | 49 | } |
32dd66fc | 50 | EXPORT_SYMBOL_GPL(all_vm_events); |
f8891e5e CL |
51 | |
52 | #ifdef CONFIG_HOTPLUG | |
53 | /* | |
54 | * Fold the foreign cpu events into our own. | |
55 | * | |
56 | * This is adding to the events on one processor | |
57 | * but keeps the global counts constant. | |
58 | */ | |
59 | void vm_events_fold_cpu(int cpu) | |
60 | { | |
61 | struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); | |
62 | int i; | |
63 | ||
64 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { | |
65 | count_vm_events(i, fold_state->event[i]); | |
66 | fold_state->event[i] = 0; | |
67 | } | |
68 | } | |
69 | #endif /* CONFIG_HOTPLUG */ | |
70 | ||
71 | #endif /* CONFIG_VM_EVENT_COUNTERS */ | |
72 | ||
2244b95a CL |
73 | /* |
74 | * Manage combined zone based / global counters | |
75 | * | |
76 | * vm_stat contains the global counters | |
77 | */ | |
78 | atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS]; | |
79 | EXPORT_SYMBOL(vm_stat); | |
80 | ||
81 | #ifdef CONFIG_SMP | |
82 | ||
df9ecaba CL |
83 | static int calculate_threshold(struct zone *zone) |
84 | { | |
85 | int threshold; | |
86 | int mem; /* memory in 128 MB units */ | |
87 | ||
88 | /* | |
89 | * The threshold scales with the number of processors and the amount | |
90 | * of memory per zone. More memory means that we can defer updates for | |
91 | * longer, more processors could lead to more contention. | |
92 | * fls() is used to have a cheap way of logarithmic scaling. | |
93 | * | |
94 | * Some sample thresholds: | |
95 | * | |
96 | * Threshold Processors (fls) Zonesize fls(mem+1) | |
97 | * ------------------------------------------------------------------ | |
98 | * 8 1 1 0.9-1 GB 4 | |
99 | * 16 2 2 0.9-1 GB 4 | |
100 | * 20 2 2 1-2 GB 5 | |
101 | * 24 2 2 2-4 GB 6 | |
102 | * 28 2 2 4-8 GB 7 | |
103 | * 32 2 2 8-16 GB 8 | |
104 | * 4 2 2 <128M 1 | |
105 | * 30 4 3 2-4 GB 5 | |
106 | * 48 4 3 8-16 GB 8 | |
107 | * 32 8 4 1-2 GB 4 | |
108 | * 32 8 4 0.9-1GB 4 | |
109 | * 10 16 5 <128M 1 | |
110 | * 40 16 5 900M 4 | |
111 | * 70 64 7 2-4 GB 5 | |
112 | * 84 64 7 4-8 GB 6 | |
113 | * 108 512 9 4-8 GB 6 | |
114 | * 125 1024 10 8-16 GB 8 | |
115 | * 125 1024 10 16-32 GB 9 | |
116 | */ | |
117 | ||
118 | mem = zone->present_pages >> (27 - PAGE_SHIFT); | |
119 | ||
120 | threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem)); | |
121 | ||
122 | /* | |
123 | * Maximum threshold is 125 | |
124 | */ | |
125 | threshold = min(125, threshold); | |
126 | ||
127 | return threshold; | |
128 | } | |
2244b95a CL |
129 | |
130 | /* | |
df9ecaba | 131 | * Refresh the thresholds for each zone. |
2244b95a | 132 | */ |
df9ecaba | 133 | static void refresh_zone_stat_thresholds(void) |
2244b95a | 134 | { |
df9ecaba CL |
135 | struct zone *zone; |
136 | int cpu; | |
137 | int threshold; | |
138 | ||
ee99c71c | 139 | for_each_populated_zone(zone) { |
df9ecaba CL |
140 | threshold = calculate_threshold(zone); |
141 | ||
142 | for_each_online_cpu(cpu) | |
99dcc3e5 CL |
143 | per_cpu_ptr(zone->pageset, cpu)->stat_threshold |
144 | = threshold; | |
df9ecaba | 145 | } |
2244b95a CL |
146 | } |
147 | ||
148 | /* | |
149 | * For use when we know that interrupts are disabled. | |
150 | */ | |
151 | void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, | |
152 | int delta) | |
153 | { | |
99dcc3e5 CL |
154 | struct per_cpu_pageset *pcp = this_cpu_ptr(zone->pageset); |
155 | ||
df9ecaba | 156 | s8 *p = pcp->vm_stat_diff + item; |
2244b95a CL |
157 | long x; |
158 | ||
2244b95a CL |
159 | x = delta + *p; |
160 | ||
df9ecaba | 161 | if (unlikely(x > pcp->stat_threshold || x < -pcp->stat_threshold)) { |
2244b95a CL |
162 | zone_page_state_add(x, zone, item); |
163 | x = 0; | |
164 | } | |
2244b95a CL |
165 | *p = x; |
166 | } | |
167 | EXPORT_SYMBOL(__mod_zone_page_state); | |
168 | ||
169 | /* | |
170 | * For an unknown interrupt state | |
171 | */ | |
172 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, | |
173 | int delta) | |
174 | { | |
175 | unsigned long flags; | |
176 | ||
177 | local_irq_save(flags); | |
178 | __mod_zone_page_state(zone, item, delta); | |
179 | local_irq_restore(flags); | |
180 | } | |
181 | EXPORT_SYMBOL(mod_zone_page_state); | |
182 | ||
183 | /* | |
184 | * Optimized increment and decrement functions. | |
185 | * | |
186 | * These are only for a single page and therefore can take a struct page * | |
187 | * argument instead of struct zone *. This allows the inclusion of the code | |
188 | * generated for page_zone(page) into the optimized functions. | |
189 | * | |
190 | * No overflow check is necessary and therefore the differential can be | |
191 | * incremented or decremented in place which may allow the compilers to | |
192 | * generate better code. | |
2244b95a CL |
193 | * The increment or decrement is known and therefore one boundary check can |
194 | * be omitted. | |
195 | * | |
df9ecaba CL |
196 | * NOTE: These functions are very performance sensitive. Change only |
197 | * with care. | |
198 | * | |
2244b95a CL |
199 | * Some processors have inc/dec instructions that are atomic vs an interrupt. |
200 | * However, the code must first determine the differential location in a zone | |
201 | * based on the processor number and then inc/dec the counter. There is no | |
202 | * guarantee without disabling preemption that the processor will not change | |
203 | * in between and therefore the atomicity vs. interrupt cannot be exploited | |
204 | * in a useful way here. | |
205 | */ | |
c8785385 | 206 | void __inc_zone_state(struct zone *zone, enum zone_stat_item item) |
2244b95a | 207 | { |
99dcc3e5 | 208 | struct per_cpu_pageset *pcp = this_cpu_ptr(zone->pageset); |
df9ecaba | 209 | s8 *p = pcp->vm_stat_diff + item; |
2244b95a CL |
210 | |
211 | (*p)++; | |
212 | ||
df9ecaba CL |
213 | if (unlikely(*p > pcp->stat_threshold)) { |
214 | int overstep = pcp->stat_threshold / 2; | |
215 | ||
216 | zone_page_state_add(*p + overstep, zone, item); | |
217 | *p = -overstep; | |
2244b95a CL |
218 | } |
219 | } | |
ca889e6c CL |
220 | |
221 | void __inc_zone_page_state(struct page *page, enum zone_stat_item item) | |
222 | { | |
223 | __inc_zone_state(page_zone(page), item); | |
224 | } | |
2244b95a CL |
225 | EXPORT_SYMBOL(__inc_zone_page_state); |
226 | ||
c8785385 | 227 | void __dec_zone_state(struct zone *zone, enum zone_stat_item item) |
2244b95a | 228 | { |
99dcc3e5 | 229 | struct per_cpu_pageset *pcp = this_cpu_ptr(zone->pageset); |
df9ecaba | 230 | s8 *p = pcp->vm_stat_diff + item; |
2244b95a CL |
231 | |
232 | (*p)--; | |
233 | ||
df9ecaba CL |
234 | if (unlikely(*p < - pcp->stat_threshold)) { |
235 | int overstep = pcp->stat_threshold / 2; | |
236 | ||
237 | zone_page_state_add(*p - overstep, zone, item); | |
238 | *p = overstep; | |
2244b95a CL |
239 | } |
240 | } | |
c8785385 CL |
241 | |
242 | void __dec_zone_page_state(struct page *page, enum zone_stat_item item) | |
243 | { | |
244 | __dec_zone_state(page_zone(page), item); | |
245 | } | |
2244b95a CL |
246 | EXPORT_SYMBOL(__dec_zone_page_state); |
247 | ||
ca889e6c CL |
248 | void inc_zone_state(struct zone *zone, enum zone_stat_item item) |
249 | { | |
250 | unsigned long flags; | |
251 | ||
252 | local_irq_save(flags); | |
253 | __inc_zone_state(zone, item); | |
254 | local_irq_restore(flags); | |
255 | } | |
256 | ||
2244b95a CL |
257 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
258 | { | |
259 | unsigned long flags; | |
260 | struct zone *zone; | |
2244b95a CL |
261 | |
262 | zone = page_zone(page); | |
263 | local_irq_save(flags); | |
ca889e6c | 264 | __inc_zone_state(zone, item); |
2244b95a CL |
265 | local_irq_restore(flags); |
266 | } | |
267 | EXPORT_SYMBOL(inc_zone_page_state); | |
268 | ||
269 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) | |
270 | { | |
271 | unsigned long flags; | |
2244b95a | 272 | |
2244b95a | 273 | local_irq_save(flags); |
a302eb4e | 274 | __dec_zone_page_state(page, item); |
2244b95a CL |
275 | local_irq_restore(flags); |
276 | } | |
277 | EXPORT_SYMBOL(dec_zone_page_state); | |
278 | ||
279 | /* | |
280 | * Update the zone counters for one cpu. | |
4037d452 | 281 | * |
a7f75e25 CL |
282 | * The cpu specified must be either the current cpu or a processor that |
283 | * is not online. If it is the current cpu then the execution thread must | |
284 | * be pinned to the current cpu. | |
285 | * | |
4037d452 CL |
286 | * Note that refresh_cpu_vm_stats strives to only access |
287 | * node local memory. The per cpu pagesets on remote zones are placed | |
288 | * in the memory local to the processor using that pageset. So the | |
289 | * loop over all zones will access a series of cachelines local to | |
290 | * the processor. | |
291 | * | |
292 | * The call to zone_page_state_add updates the cachelines with the | |
293 | * statistics in the remote zone struct as well as the global cachelines | |
294 | * with the global counters. These could cause remote node cache line | |
295 | * bouncing and will have to be only done when necessary. | |
2244b95a CL |
296 | */ |
297 | void refresh_cpu_vm_stats(int cpu) | |
298 | { | |
299 | struct zone *zone; | |
300 | int i; | |
a7f75e25 | 301 | int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; |
2244b95a | 302 | |
ee99c71c | 303 | for_each_populated_zone(zone) { |
4037d452 | 304 | struct per_cpu_pageset *p; |
2244b95a | 305 | |
99dcc3e5 | 306 | p = per_cpu_ptr(zone->pageset, cpu); |
2244b95a CL |
307 | |
308 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) | |
4037d452 | 309 | if (p->vm_stat_diff[i]) { |
a7f75e25 CL |
310 | unsigned long flags; |
311 | int v; | |
312 | ||
2244b95a | 313 | local_irq_save(flags); |
a7f75e25 | 314 | v = p->vm_stat_diff[i]; |
4037d452 | 315 | p->vm_stat_diff[i] = 0; |
a7f75e25 CL |
316 | local_irq_restore(flags); |
317 | atomic_long_add(v, &zone->vm_stat[i]); | |
318 | global_diff[i] += v; | |
4037d452 CL |
319 | #ifdef CONFIG_NUMA |
320 | /* 3 seconds idle till flush */ | |
321 | p->expire = 3; | |
322 | #endif | |
2244b95a | 323 | } |
468fd62e | 324 | cond_resched(); |
4037d452 CL |
325 | #ifdef CONFIG_NUMA |
326 | /* | |
327 | * Deal with draining the remote pageset of this | |
328 | * processor | |
329 | * | |
330 | * Check if there are pages remaining in this pageset | |
331 | * if not then there is nothing to expire. | |
332 | */ | |
3dfa5721 | 333 | if (!p->expire || !p->pcp.count) |
4037d452 CL |
334 | continue; |
335 | ||
336 | /* | |
337 | * We never drain zones local to this processor. | |
338 | */ | |
339 | if (zone_to_nid(zone) == numa_node_id()) { | |
340 | p->expire = 0; | |
341 | continue; | |
342 | } | |
343 | ||
344 | p->expire--; | |
345 | if (p->expire) | |
346 | continue; | |
347 | ||
3dfa5721 CL |
348 | if (p->pcp.count) |
349 | drain_zone_pages(zone, &p->pcp); | |
4037d452 | 350 | #endif |
2244b95a | 351 | } |
a7f75e25 CL |
352 | |
353 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) | |
354 | if (global_diff[i]) | |
355 | atomic_long_add(global_diff[i], &vm_stat[i]); | |
2244b95a CL |
356 | } |
357 | ||
2244b95a CL |
358 | #endif |
359 | ||
ca889e6c CL |
360 | #ifdef CONFIG_NUMA |
361 | /* | |
362 | * zonelist = the list of zones passed to the allocator | |
363 | * z = the zone from which the allocation occurred. | |
364 | * | |
365 | * Must be called with interrupts disabled. | |
366 | */ | |
18ea7e71 | 367 | void zone_statistics(struct zone *preferred_zone, struct zone *z) |
ca889e6c | 368 | { |
18ea7e71 | 369 | if (z->zone_pgdat == preferred_zone->zone_pgdat) { |
ca889e6c CL |
370 | __inc_zone_state(z, NUMA_HIT); |
371 | } else { | |
372 | __inc_zone_state(z, NUMA_MISS); | |
18ea7e71 | 373 | __inc_zone_state(preferred_zone, NUMA_FOREIGN); |
ca889e6c | 374 | } |
5d292343 | 375 | if (z->node == numa_node_id()) |
ca889e6c CL |
376 | __inc_zone_state(z, NUMA_LOCAL); |
377 | else | |
378 | __inc_zone_state(z, NUMA_OTHER); | |
379 | } | |
380 | #endif | |
381 | ||
d7a5752c MG |
382 | #ifdef CONFIG_COMPACTION |
383 | struct contig_page_info { | |
384 | unsigned long free_pages; | |
385 | unsigned long free_blocks_total; | |
386 | unsigned long free_blocks_suitable; | |
387 | }; | |
388 | ||
389 | /* | |
390 | * Calculate the number of free pages in a zone, how many contiguous | |
391 | * pages are free and how many are large enough to satisfy an allocation of | |
392 | * the target size. Note that this function makes no attempt to estimate | |
393 | * how many suitable free blocks there *might* be if MOVABLE pages were | |
394 | * migrated. Calculating that is possible, but expensive and can be | |
395 | * figured out from userspace | |
396 | */ | |
397 | static void fill_contig_page_info(struct zone *zone, | |
398 | unsigned int suitable_order, | |
399 | struct contig_page_info *info) | |
400 | { | |
401 | unsigned int order; | |
402 | ||
403 | info->free_pages = 0; | |
404 | info->free_blocks_total = 0; | |
405 | info->free_blocks_suitable = 0; | |
406 | ||
407 | for (order = 0; order < MAX_ORDER; order++) { | |
408 | unsigned long blocks; | |
409 | ||
410 | /* Count number of free blocks */ | |
411 | blocks = zone->free_area[order].nr_free; | |
412 | info->free_blocks_total += blocks; | |
413 | ||
414 | /* Count free base pages */ | |
415 | info->free_pages += blocks << order; | |
416 | ||
417 | /* Count the suitable free blocks */ | |
418 | if (order >= suitable_order) | |
419 | info->free_blocks_suitable += blocks << | |
420 | (order - suitable_order); | |
421 | } | |
422 | } | |
423 | #endif | |
424 | ||
425 | #if defined(CONFIG_PROC_FS) || defined(CONFIG_COMPACTION) | |
8f32f7e5 | 426 | #include <linux/proc_fs.h> |
f6ac2354 CL |
427 | #include <linux/seq_file.h> |
428 | ||
467c996c MG |
429 | static char * const migratetype_names[MIGRATE_TYPES] = { |
430 | "Unmovable", | |
431 | "Reclaimable", | |
432 | "Movable", | |
433 | "Reserve", | |
91446b06 | 434 | "Isolate", |
467c996c MG |
435 | }; |
436 | ||
f6ac2354 CL |
437 | static void *frag_start(struct seq_file *m, loff_t *pos) |
438 | { | |
439 | pg_data_t *pgdat; | |
440 | loff_t node = *pos; | |
441 | for (pgdat = first_online_pgdat(); | |
442 | pgdat && node; | |
443 | pgdat = next_online_pgdat(pgdat)) | |
444 | --node; | |
445 | ||
446 | return pgdat; | |
447 | } | |
448 | ||
449 | static void *frag_next(struct seq_file *m, void *arg, loff_t *pos) | |
450 | { | |
451 | pg_data_t *pgdat = (pg_data_t *)arg; | |
452 | ||
453 | (*pos)++; | |
454 | return next_online_pgdat(pgdat); | |
455 | } | |
456 | ||
457 | static void frag_stop(struct seq_file *m, void *arg) | |
458 | { | |
459 | } | |
460 | ||
467c996c MG |
461 | /* Walk all the zones in a node and print using a callback */ |
462 | static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat, | |
463 | void (*print)(struct seq_file *m, pg_data_t *, struct zone *)) | |
f6ac2354 | 464 | { |
f6ac2354 CL |
465 | struct zone *zone; |
466 | struct zone *node_zones = pgdat->node_zones; | |
467 | unsigned long flags; | |
f6ac2354 CL |
468 | |
469 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { | |
470 | if (!populated_zone(zone)) | |
471 | continue; | |
472 | ||
473 | spin_lock_irqsave(&zone->lock, flags); | |
467c996c | 474 | print(m, pgdat, zone); |
f6ac2354 | 475 | spin_unlock_irqrestore(&zone->lock, flags); |
467c996c MG |
476 | } |
477 | } | |
d7a5752c | 478 | #endif |
467c996c | 479 | |
d7a5752c | 480 | #ifdef CONFIG_PROC_FS |
467c996c MG |
481 | static void frag_show_print(struct seq_file *m, pg_data_t *pgdat, |
482 | struct zone *zone) | |
483 | { | |
484 | int order; | |
485 | ||
486 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); | |
487 | for (order = 0; order < MAX_ORDER; ++order) | |
488 | seq_printf(m, "%6lu ", zone->free_area[order].nr_free); | |
489 | seq_putc(m, '\n'); | |
490 | } | |
491 | ||
492 | /* | |
493 | * This walks the free areas for each zone. | |
494 | */ | |
495 | static int frag_show(struct seq_file *m, void *arg) | |
496 | { | |
497 | pg_data_t *pgdat = (pg_data_t *)arg; | |
498 | walk_zones_in_node(m, pgdat, frag_show_print); | |
499 | return 0; | |
500 | } | |
501 | ||
502 | static void pagetypeinfo_showfree_print(struct seq_file *m, | |
503 | pg_data_t *pgdat, struct zone *zone) | |
504 | { | |
505 | int order, mtype; | |
506 | ||
507 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) { | |
508 | seq_printf(m, "Node %4d, zone %8s, type %12s ", | |
509 | pgdat->node_id, | |
510 | zone->name, | |
511 | migratetype_names[mtype]); | |
512 | for (order = 0; order < MAX_ORDER; ++order) { | |
513 | unsigned long freecount = 0; | |
514 | struct free_area *area; | |
515 | struct list_head *curr; | |
516 | ||
517 | area = &(zone->free_area[order]); | |
518 | ||
519 | list_for_each(curr, &area->free_list[mtype]) | |
520 | freecount++; | |
521 | seq_printf(m, "%6lu ", freecount); | |
522 | } | |
f6ac2354 CL |
523 | seq_putc(m, '\n'); |
524 | } | |
467c996c MG |
525 | } |
526 | ||
527 | /* Print out the free pages at each order for each migatetype */ | |
528 | static int pagetypeinfo_showfree(struct seq_file *m, void *arg) | |
529 | { | |
530 | int order; | |
531 | pg_data_t *pgdat = (pg_data_t *)arg; | |
532 | ||
533 | /* Print header */ | |
534 | seq_printf(m, "%-43s ", "Free pages count per migrate type at order"); | |
535 | for (order = 0; order < MAX_ORDER; ++order) | |
536 | seq_printf(m, "%6d ", order); | |
537 | seq_putc(m, '\n'); | |
538 | ||
539 | walk_zones_in_node(m, pgdat, pagetypeinfo_showfree_print); | |
540 | ||
541 | return 0; | |
542 | } | |
543 | ||
544 | static void pagetypeinfo_showblockcount_print(struct seq_file *m, | |
545 | pg_data_t *pgdat, struct zone *zone) | |
546 | { | |
547 | int mtype; | |
548 | unsigned long pfn; | |
549 | unsigned long start_pfn = zone->zone_start_pfn; | |
550 | unsigned long end_pfn = start_pfn + zone->spanned_pages; | |
551 | unsigned long count[MIGRATE_TYPES] = { 0, }; | |
552 | ||
553 | for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { | |
554 | struct page *page; | |
555 | ||
556 | if (!pfn_valid(pfn)) | |
557 | continue; | |
558 | ||
559 | page = pfn_to_page(pfn); | |
eb33575c MG |
560 | |
561 | /* Watch for unexpected holes punched in the memmap */ | |
562 | if (!memmap_valid_within(pfn, page, zone)) | |
e80d6a24 | 563 | continue; |
eb33575c | 564 | |
467c996c MG |
565 | mtype = get_pageblock_migratetype(page); |
566 | ||
e80d6a24 MG |
567 | if (mtype < MIGRATE_TYPES) |
568 | count[mtype]++; | |
467c996c MG |
569 | } |
570 | ||
571 | /* Print counts */ | |
572 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); | |
573 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) | |
574 | seq_printf(m, "%12lu ", count[mtype]); | |
575 | seq_putc(m, '\n'); | |
576 | } | |
577 | ||
578 | /* Print out the free pages at each order for each migratetype */ | |
579 | static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg) | |
580 | { | |
581 | int mtype; | |
582 | pg_data_t *pgdat = (pg_data_t *)arg; | |
583 | ||
584 | seq_printf(m, "\n%-23s", "Number of blocks type "); | |
585 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) | |
586 | seq_printf(m, "%12s ", migratetype_names[mtype]); | |
587 | seq_putc(m, '\n'); | |
588 | walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print); | |
589 | ||
590 | return 0; | |
591 | } | |
592 | ||
593 | /* | |
594 | * This prints out statistics in relation to grouping pages by mobility. | |
595 | * It is expensive to collect so do not constantly read the file. | |
596 | */ | |
597 | static int pagetypeinfo_show(struct seq_file *m, void *arg) | |
598 | { | |
599 | pg_data_t *pgdat = (pg_data_t *)arg; | |
600 | ||
41b25a37 KM |
601 | /* check memoryless node */ |
602 | if (!node_state(pgdat->node_id, N_HIGH_MEMORY)) | |
603 | return 0; | |
604 | ||
467c996c MG |
605 | seq_printf(m, "Page block order: %d\n", pageblock_order); |
606 | seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages); | |
607 | seq_putc(m, '\n'); | |
608 | pagetypeinfo_showfree(m, pgdat); | |
609 | pagetypeinfo_showblockcount(m, pgdat); | |
610 | ||
f6ac2354 CL |
611 | return 0; |
612 | } | |
613 | ||
8f32f7e5 | 614 | static const struct seq_operations fragmentation_op = { |
f6ac2354 CL |
615 | .start = frag_start, |
616 | .next = frag_next, | |
617 | .stop = frag_stop, | |
618 | .show = frag_show, | |
619 | }; | |
620 | ||
8f32f7e5 AD |
621 | static int fragmentation_open(struct inode *inode, struct file *file) |
622 | { | |
623 | return seq_open(file, &fragmentation_op); | |
624 | } | |
625 | ||
626 | static const struct file_operations fragmentation_file_operations = { | |
627 | .open = fragmentation_open, | |
628 | .read = seq_read, | |
629 | .llseek = seq_lseek, | |
630 | .release = seq_release, | |
631 | }; | |
632 | ||
74e2e8e8 | 633 | static const struct seq_operations pagetypeinfo_op = { |
467c996c MG |
634 | .start = frag_start, |
635 | .next = frag_next, | |
636 | .stop = frag_stop, | |
637 | .show = pagetypeinfo_show, | |
638 | }; | |
639 | ||
74e2e8e8 AD |
640 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
641 | { | |
642 | return seq_open(file, &pagetypeinfo_op); | |
643 | } | |
644 | ||
645 | static const struct file_operations pagetypeinfo_file_ops = { | |
646 | .open = pagetypeinfo_open, | |
647 | .read = seq_read, | |
648 | .llseek = seq_lseek, | |
649 | .release = seq_release, | |
650 | }; | |
651 | ||
4b51d669 CL |
652 | #ifdef CONFIG_ZONE_DMA |
653 | #define TEXT_FOR_DMA(xx) xx "_dma", | |
654 | #else | |
655 | #define TEXT_FOR_DMA(xx) | |
656 | #endif | |
657 | ||
27bf71c2 CL |
658 | #ifdef CONFIG_ZONE_DMA32 |
659 | #define TEXT_FOR_DMA32(xx) xx "_dma32", | |
660 | #else | |
661 | #define TEXT_FOR_DMA32(xx) | |
662 | #endif | |
663 | ||
664 | #ifdef CONFIG_HIGHMEM | |
665 | #define TEXT_FOR_HIGHMEM(xx) xx "_high", | |
666 | #else | |
667 | #define TEXT_FOR_HIGHMEM(xx) | |
668 | #endif | |
669 | ||
4b51d669 | 670 | #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \ |
2a1e274a | 671 | TEXT_FOR_HIGHMEM(xx) xx "_movable", |
27bf71c2 | 672 | |
15ad7cdc | 673 | static const char * const vmstat_text[] = { |
2244b95a | 674 | /* Zoned VM counters */ |
d23ad423 | 675 | "nr_free_pages", |
4f98a2fe RR |
676 | "nr_inactive_anon", |
677 | "nr_active_anon", | |
678 | "nr_inactive_file", | |
679 | "nr_active_file", | |
7b854121 | 680 | "nr_unevictable", |
5344b7e6 | 681 | "nr_mlock", |
f3dbd344 | 682 | "nr_anon_pages", |
65ba55f5 | 683 | "nr_mapped", |
347ce434 | 684 | "nr_file_pages", |
51ed4491 CL |
685 | "nr_dirty", |
686 | "nr_writeback", | |
972d1a7b CL |
687 | "nr_slab_reclaimable", |
688 | "nr_slab_unreclaimable", | |
df849a15 | 689 | "nr_page_table_pages", |
c6a7f572 | 690 | "nr_kernel_stack", |
f6ac2354 | 691 | "nr_unstable", |
d2c5e30c | 692 | "nr_bounce", |
e129b5c2 | 693 | "nr_vmscan_write", |
fc3ba692 | 694 | "nr_writeback_temp", |
a731286d KM |
695 | "nr_isolated_anon", |
696 | "nr_isolated_file", | |
4b02108a | 697 | "nr_shmem", |
ca889e6c CL |
698 | #ifdef CONFIG_NUMA |
699 | "numa_hit", | |
700 | "numa_miss", | |
701 | "numa_foreign", | |
702 | "numa_interleave", | |
703 | "numa_local", | |
704 | "numa_other", | |
705 | #endif | |
706 | ||
f8891e5e | 707 | #ifdef CONFIG_VM_EVENT_COUNTERS |
f6ac2354 CL |
708 | "pgpgin", |
709 | "pgpgout", | |
710 | "pswpin", | |
711 | "pswpout", | |
712 | ||
27bf71c2 | 713 | TEXTS_FOR_ZONES("pgalloc") |
f6ac2354 CL |
714 | |
715 | "pgfree", | |
716 | "pgactivate", | |
717 | "pgdeactivate", | |
718 | ||
719 | "pgfault", | |
720 | "pgmajfault", | |
721 | ||
27bf71c2 CL |
722 | TEXTS_FOR_ZONES("pgrefill") |
723 | TEXTS_FOR_ZONES("pgsteal") | |
724 | TEXTS_FOR_ZONES("pgscan_kswapd") | |
725 | TEXTS_FOR_ZONES("pgscan_direct") | |
f6ac2354 | 726 | |
24cf7251 MG |
727 | #ifdef CONFIG_NUMA |
728 | "zone_reclaim_failed", | |
729 | #endif | |
f6ac2354 CL |
730 | "pginodesteal", |
731 | "slabs_scanned", | |
732 | "kswapd_steal", | |
733 | "kswapd_inodesteal", | |
bb3ab596 KM |
734 | "kswapd_low_wmark_hit_quickly", |
735 | "kswapd_high_wmark_hit_quickly", | |
736 | "kswapd_skip_congestion_wait", | |
f6ac2354 CL |
737 | "pageoutrun", |
738 | "allocstall", | |
739 | ||
740 | "pgrotated", | |
3b116300 AL |
741 | #ifdef CONFIG_HUGETLB_PAGE |
742 | "htlb_buddy_alloc_success", | |
743 | "htlb_buddy_alloc_fail", | |
744 | #endif | |
bbfd28ee LS |
745 | "unevictable_pgs_culled", |
746 | "unevictable_pgs_scanned", | |
747 | "unevictable_pgs_rescued", | |
5344b7e6 NP |
748 | "unevictable_pgs_mlocked", |
749 | "unevictable_pgs_munlocked", | |
750 | "unevictable_pgs_cleared", | |
751 | "unevictable_pgs_stranded", | |
985737cf | 752 | "unevictable_pgs_mlockfreed", |
bbfd28ee | 753 | #endif |
f6ac2354 CL |
754 | }; |
755 | ||
467c996c MG |
756 | static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat, |
757 | struct zone *zone) | |
f6ac2354 | 758 | { |
467c996c MG |
759 | int i; |
760 | seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name); | |
761 | seq_printf(m, | |
762 | "\n pages free %lu" | |
763 | "\n min %lu" | |
764 | "\n low %lu" | |
765 | "\n high %lu" | |
08d9ae7c | 766 | "\n scanned %lu" |
467c996c MG |
767 | "\n spanned %lu" |
768 | "\n present %lu", | |
769 | zone_page_state(zone, NR_FREE_PAGES), | |
41858966 MG |
770 | min_wmark_pages(zone), |
771 | low_wmark_pages(zone), | |
772 | high_wmark_pages(zone), | |
467c996c | 773 | zone->pages_scanned, |
467c996c MG |
774 | zone->spanned_pages, |
775 | zone->present_pages); | |
776 | ||
777 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) | |
778 | seq_printf(m, "\n %-12s %lu", vmstat_text[i], | |
779 | zone_page_state(zone, i)); | |
780 | ||
781 | seq_printf(m, | |
782 | "\n protection: (%lu", | |
783 | zone->lowmem_reserve[0]); | |
784 | for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++) | |
785 | seq_printf(m, ", %lu", zone->lowmem_reserve[i]); | |
786 | seq_printf(m, | |
787 | ")" | |
788 | "\n pagesets"); | |
789 | for_each_online_cpu(i) { | |
790 | struct per_cpu_pageset *pageset; | |
467c996c | 791 | |
99dcc3e5 | 792 | pageset = per_cpu_ptr(zone->pageset, i); |
3dfa5721 CL |
793 | seq_printf(m, |
794 | "\n cpu: %i" | |
795 | "\n count: %i" | |
796 | "\n high: %i" | |
797 | "\n batch: %i", | |
798 | i, | |
799 | pageset->pcp.count, | |
800 | pageset->pcp.high, | |
801 | pageset->pcp.batch); | |
df9ecaba | 802 | #ifdef CONFIG_SMP |
467c996c MG |
803 | seq_printf(m, "\n vm stats threshold: %d", |
804 | pageset->stat_threshold); | |
df9ecaba | 805 | #endif |
f6ac2354 | 806 | } |
467c996c MG |
807 | seq_printf(m, |
808 | "\n all_unreclaimable: %u" | |
809 | "\n prev_priority: %i" | |
556adecb RR |
810 | "\n start_pfn: %lu" |
811 | "\n inactive_ratio: %u", | |
93e4a89a | 812 | zone->all_unreclaimable, |
467c996c | 813 | zone->prev_priority, |
556adecb RR |
814 | zone->zone_start_pfn, |
815 | zone->inactive_ratio); | |
467c996c MG |
816 | seq_putc(m, '\n'); |
817 | } | |
818 | ||
819 | /* | |
820 | * Output information about zones in @pgdat. | |
821 | */ | |
822 | static int zoneinfo_show(struct seq_file *m, void *arg) | |
823 | { | |
824 | pg_data_t *pgdat = (pg_data_t *)arg; | |
825 | walk_zones_in_node(m, pgdat, zoneinfo_show_print); | |
f6ac2354 CL |
826 | return 0; |
827 | } | |
828 | ||
5c9fe628 | 829 | static const struct seq_operations zoneinfo_op = { |
f6ac2354 CL |
830 | .start = frag_start, /* iterate over all zones. The same as in |
831 | * fragmentation. */ | |
832 | .next = frag_next, | |
833 | .stop = frag_stop, | |
834 | .show = zoneinfo_show, | |
835 | }; | |
836 | ||
5c9fe628 AD |
837 | static int zoneinfo_open(struct inode *inode, struct file *file) |
838 | { | |
839 | return seq_open(file, &zoneinfo_op); | |
840 | } | |
841 | ||
842 | static const struct file_operations proc_zoneinfo_file_operations = { | |
843 | .open = zoneinfo_open, | |
844 | .read = seq_read, | |
845 | .llseek = seq_lseek, | |
846 | .release = seq_release, | |
847 | }; | |
848 | ||
f6ac2354 CL |
849 | static void *vmstat_start(struct seq_file *m, loff_t *pos) |
850 | { | |
2244b95a | 851 | unsigned long *v; |
f8891e5e CL |
852 | #ifdef CONFIG_VM_EVENT_COUNTERS |
853 | unsigned long *e; | |
854 | #endif | |
2244b95a | 855 | int i; |
f6ac2354 CL |
856 | |
857 | if (*pos >= ARRAY_SIZE(vmstat_text)) | |
858 | return NULL; | |
859 | ||
f8891e5e | 860 | #ifdef CONFIG_VM_EVENT_COUNTERS |
2244b95a | 861 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) |
f8891e5e CL |
862 | + sizeof(struct vm_event_state), GFP_KERNEL); |
863 | #else | |
864 | v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long), | |
865 | GFP_KERNEL); | |
866 | #endif | |
2244b95a CL |
867 | m->private = v; |
868 | if (!v) | |
f6ac2354 | 869 | return ERR_PTR(-ENOMEM); |
2244b95a CL |
870 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
871 | v[i] = global_page_state(i); | |
f8891e5e CL |
872 | #ifdef CONFIG_VM_EVENT_COUNTERS |
873 | e = v + NR_VM_ZONE_STAT_ITEMS; | |
874 | all_vm_events(e); | |
875 | e[PGPGIN] /= 2; /* sectors -> kbytes */ | |
876 | e[PGPGOUT] /= 2; | |
877 | #endif | |
2244b95a | 878 | return v + *pos; |
f6ac2354 CL |
879 | } |
880 | ||
881 | static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) | |
882 | { | |
883 | (*pos)++; | |
884 | if (*pos >= ARRAY_SIZE(vmstat_text)) | |
885 | return NULL; | |
886 | return (unsigned long *)m->private + *pos; | |
887 | } | |
888 | ||
889 | static int vmstat_show(struct seq_file *m, void *arg) | |
890 | { | |
891 | unsigned long *l = arg; | |
892 | unsigned long off = l - (unsigned long *)m->private; | |
893 | ||
894 | seq_printf(m, "%s %lu\n", vmstat_text[off], *l); | |
895 | return 0; | |
896 | } | |
897 | ||
898 | static void vmstat_stop(struct seq_file *m, void *arg) | |
899 | { | |
900 | kfree(m->private); | |
901 | m->private = NULL; | |
902 | } | |
903 | ||
b6aa44ab | 904 | static const struct seq_operations vmstat_op = { |
f6ac2354 CL |
905 | .start = vmstat_start, |
906 | .next = vmstat_next, | |
907 | .stop = vmstat_stop, | |
908 | .show = vmstat_show, | |
909 | }; | |
910 | ||
b6aa44ab AD |
911 | static int vmstat_open(struct inode *inode, struct file *file) |
912 | { | |
913 | return seq_open(file, &vmstat_op); | |
914 | } | |
915 | ||
916 | static const struct file_operations proc_vmstat_file_operations = { | |
917 | .open = vmstat_open, | |
918 | .read = seq_read, | |
919 | .llseek = seq_lseek, | |
920 | .release = seq_release, | |
921 | }; | |
f6ac2354 CL |
922 | #endif /* CONFIG_PROC_FS */ |
923 | ||
df9ecaba | 924 | #ifdef CONFIG_SMP |
d1187ed2 | 925 | static DEFINE_PER_CPU(struct delayed_work, vmstat_work); |
77461ab3 | 926 | int sysctl_stat_interval __read_mostly = HZ; |
d1187ed2 CL |
927 | |
928 | static void vmstat_update(struct work_struct *w) | |
929 | { | |
930 | refresh_cpu_vm_stats(smp_processor_id()); | |
77461ab3 | 931 | schedule_delayed_work(&__get_cpu_var(vmstat_work), |
98f4ebb2 | 932 | round_jiffies_relative(sysctl_stat_interval)); |
d1187ed2 CL |
933 | } |
934 | ||
42614fcd | 935 | static void __cpuinit start_cpu_timer(int cpu) |
d1187ed2 | 936 | { |
1871e52c | 937 | struct delayed_work *work = &per_cpu(vmstat_work, cpu); |
d1187ed2 | 938 | |
1871e52c TH |
939 | INIT_DELAYED_WORK_DEFERRABLE(work, vmstat_update); |
940 | schedule_delayed_work_on(cpu, work, __round_jiffies_relative(HZ, cpu)); | |
d1187ed2 CL |
941 | } |
942 | ||
df9ecaba CL |
943 | /* |
944 | * Use the cpu notifier to insure that the thresholds are recalculated | |
945 | * when necessary. | |
946 | */ | |
947 | static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb, | |
948 | unsigned long action, | |
949 | void *hcpu) | |
950 | { | |
d1187ed2 CL |
951 | long cpu = (long)hcpu; |
952 | ||
df9ecaba | 953 | switch (action) { |
d1187ed2 CL |
954 | case CPU_ONLINE: |
955 | case CPU_ONLINE_FROZEN: | |
956 | start_cpu_timer(cpu); | |
ad596925 | 957 | node_set_state(cpu_to_node(cpu), N_CPU); |
d1187ed2 CL |
958 | break; |
959 | case CPU_DOWN_PREPARE: | |
960 | case CPU_DOWN_PREPARE_FROZEN: | |
961 | cancel_rearming_delayed_work(&per_cpu(vmstat_work, cpu)); | |
962 | per_cpu(vmstat_work, cpu).work.func = NULL; | |
963 | break; | |
964 | case CPU_DOWN_FAILED: | |
965 | case CPU_DOWN_FAILED_FROZEN: | |
966 | start_cpu_timer(cpu); | |
967 | break; | |
ce421c79 | 968 | case CPU_DEAD: |
8bb78442 | 969 | case CPU_DEAD_FROZEN: |
ce421c79 AW |
970 | refresh_zone_stat_thresholds(); |
971 | break; | |
972 | default: | |
973 | break; | |
df9ecaba CL |
974 | } |
975 | return NOTIFY_OK; | |
976 | } | |
977 | ||
978 | static struct notifier_block __cpuinitdata vmstat_notifier = | |
979 | { &vmstat_cpuup_callback, NULL, 0 }; | |
8f32f7e5 | 980 | #endif |
df9ecaba | 981 | |
e2fc88d0 | 982 | static int __init setup_vmstat(void) |
df9ecaba | 983 | { |
8f32f7e5 | 984 | #ifdef CONFIG_SMP |
d1187ed2 CL |
985 | int cpu; |
986 | ||
df9ecaba CL |
987 | refresh_zone_stat_thresholds(); |
988 | register_cpu_notifier(&vmstat_notifier); | |
d1187ed2 CL |
989 | |
990 | for_each_online_cpu(cpu) | |
991 | start_cpu_timer(cpu); | |
8f32f7e5 AD |
992 | #endif |
993 | #ifdef CONFIG_PROC_FS | |
994 | proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); | |
74e2e8e8 | 995 | proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); |
b6aa44ab | 996 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); |
5c9fe628 | 997 | proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); |
8f32f7e5 | 998 | #endif |
df9ecaba CL |
999 | return 0; |
1000 | } | |
1001 | module_init(setup_vmstat) | |
d7a5752c MG |
1002 | |
1003 | #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION) | |
1004 | #include <linux/debugfs.h> | |
1005 | ||
1006 | static struct dentry *extfrag_debug_root; | |
1007 | ||
1008 | /* | |
1009 | * Return an index indicating how much of the available free memory is | |
1010 | * unusable for an allocation of the requested size. | |
1011 | */ | |
1012 | static int unusable_free_index(unsigned int order, | |
1013 | struct contig_page_info *info) | |
1014 | { | |
1015 | /* No free memory is interpreted as all free memory is unusable */ | |
1016 | if (info->free_pages == 0) | |
1017 | return 1000; | |
1018 | ||
1019 | /* | |
1020 | * Index should be a value between 0 and 1. Return a value to 3 | |
1021 | * decimal places. | |
1022 | * | |
1023 | * 0 => no fragmentation | |
1024 | * 1 => high fragmentation | |
1025 | */ | |
1026 | return div_u64((info->free_pages - (info->free_blocks_suitable << order)) * 1000ULL, info->free_pages); | |
1027 | ||
1028 | } | |
1029 | ||
1030 | static void unusable_show_print(struct seq_file *m, | |
1031 | pg_data_t *pgdat, struct zone *zone) | |
1032 | { | |
1033 | unsigned int order; | |
1034 | int index; | |
1035 | struct contig_page_info info; | |
1036 | ||
1037 | seq_printf(m, "Node %d, zone %8s ", | |
1038 | pgdat->node_id, | |
1039 | zone->name); | |
1040 | for (order = 0; order < MAX_ORDER; ++order) { | |
1041 | fill_contig_page_info(zone, order, &info); | |
1042 | index = unusable_free_index(order, &info); | |
1043 | seq_printf(m, "%d.%03d ", index / 1000, index % 1000); | |
1044 | } | |
1045 | ||
1046 | seq_putc(m, '\n'); | |
1047 | } | |
1048 | ||
1049 | /* | |
1050 | * Display unusable free space index | |
1051 | * | |
1052 | * The unusable free space index measures how much of the available free | |
1053 | * memory cannot be used to satisfy an allocation of a given size and is a | |
1054 | * value between 0 and 1. The higher the value, the more of free memory is | |
1055 | * unusable and by implication, the worse the external fragmentation is. This | |
1056 | * can be expressed as a percentage by multiplying by 100. | |
1057 | */ | |
1058 | static int unusable_show(struct seq_file *m, void *arg) | |
1059 | { | |
1060 | pg_data_t *pgdat = (pg_data_t *)arg; | |
1061 | ||
1062 | /* check memoryless node */ | |
1063 | if (!node_state(pgdat->node_id, N_HIGH_MEMORY)) | |
1064 | return 0; | |
1065 | ||
1066 | walk_zones_in_node(m, pgdat, unusable_show_print); | |
1067 | ||
1068 | return 0; | |
1069 | } | |
1070 | ||
1071 | static const struct seq_operations unusable_op = { | |
1072 | .start = frag_start, | |
1073 | .next = frag_next, | |
1074 | .stop = frag_stop, | |
1075 | .show = unusable_show, | |
1076 | }; | |
1077 | ||
1078 | static int unusable_open(struct inode *inode, struct file *file) | |
1079 | { | |
1080 | return seq_open(file, &unusable_op); | |
1081 | } | |
1082 | ||
1083 | static const struct file_operations unusable_file_ops = { | |
1084 | .open = unusable_open, | |
1085 | .read = seq_read, | |
1086 | .llseek = seq_lseek, | |
1087 | .release = seq_release, | |
1088 | }; | |
1089 | ||
1090 | static int __init extfrag_debug_init(void) | |
1091 | { | |
1092 | extfrag_debug_root = debugfs_create_dir("extfrag", NULL); | |
1093 | if (!extfrag_debug_root) | |
1094 | return -ENOMEM; | |
1095 | ||
1096 | if (!debugfs_create_file("unusable_index", 0444, | |
1097 | extfrag_debug_root, NULL, &unusable_file_ops)) | |
1098 | return -ENOMEM; | |
1099 | ||
1100 | return 0; | |
1101 | } | |
1102 | ||
1103 | module_init(extfrag_debug_init); | |
1104 | #endif |