vmstat.c 32 KB

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