vmstat.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  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 <[email protected]>
  10. * Copyright (C) 2008-2014 Christoph Lameter
  11. */
  12. #include <linux/fs.h>
  13. #include <linux/mm.h>
  14. #include <linux/err.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <linux/cpu.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/vmstat.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/sched.h>
  24. #include <linux/math64.h>
  25. #include <linux/writeback.h>
  26. #include <linux/compaction.h>
  27. #include <linux/mm_inline.h>
  28. #include <linux/page_ext.h>
  29. #include <linux/page_owner.h>
  30. #include "internal.h"
  31. #ifdef CONFIG_VM_EVENT_COUNTERS
  32. DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
  33. EXPORT_PER_CPU_SYMBOL(vm_event_states);
  34. static void sum_vm_events(unsigned long *ret)
  35. {
  36. int cpu;
  37. int i;
  38. memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long));
  39. for_each_online_cpu(cpu) {
  40. struct vm_event_state *this = &per_cpu(vm_event_states, cpu);
  41. for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
  42. ret[i] += this->event[i];
  43. }
  44. }
  45. /*
  46. * Accumulate the vm event counters across all CPUs.
  47. * The result is unavoidably approximate - it can change
  48. * during and after execution of this function.
  49. */
  50. void all_vm_events(unsigned long *ret)
  51. {
  52. get_online_cpus();
  53. sum_vm_events(ret);
  54. put_online_cpus();
  55. }
  56. EXPORT_SYMBOL_GPL(all_vm_events);
  57. /*
  58. * Fold the foreign cpu events into our own.
  59. *
  60. * This is adding to the events on one processor
  61. * but keeps the global counts constant.
  62. */
  63. void vm_events_fold_cpu(int cpu)
  64. {
  65. struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu);
  66. int i;
  67. for (i = 0; i < NR_VM_EVENT_ITEMS; i++) {
  68. count_vm_events(i, fold_state->event[i]);
  69. fold_state->event[i] = 0;
  70. }
  71. }
  72. #endif /* CONFIG_VM_EVENT_COUNTERS */
  73. /*
  74. * Manage combined zone based / global counters
  75. *
  76. * vm_stat contains the global counters
  77. */
  78. atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
  79. atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS] __cacheline_aligned_in_smp;
  80. EXPORT_SYMBOL(vm_zone_stat);
  81. EXPORT_SYMBOL(vm_node_stat);
  82. #ifdef CONFIG_SMP
  83. int calculate_pressure_threshold(struct zone *zone)
  84. {
  85. int threshold;
  86. int watermark_distance;
  87. /*
  88. * As vmstats are not up to date, there is drift between the estimated
  89. * and real values. For high thresholds and a high number of CPUs, it
  90. * is possible for the min watermark to be breached while the estimated
  91. * value looks fine. The pressure threshold is a reduced value such
  92. * that even the maximum amount of drift will not accidentally breach
  93. * the min watermark
  94. */
  95. watermark_distance = low_wmark_pages(zone) - min_wmark_pages(zone);
  96. threshold = max(1, (int)(watermark_distance / num_online_cpus()));
  97. /*
  98. * Maximum threshold is 125
  99. */
  100. threshold = min(125, threshold);
  101. return threshold;
  102. }
  103. int calculate_normal_threshold(struct zone *zone)
  104. {
  105. int threshold;
  106. int mem; /* memory in 128 MB units */
  107. /*
  108. * The threshold scales with the number of processors and the amount
  109. * of memory per zone. More memory means that we can defer updates for
  110. * longer, more processors could lead to more contention.
  111. * fls() is used to have a cheap way of logarithmic scaling.
  112. *
  113. * Some sample thresholds:
  114. *
  115. * Threshold Processors (fls) Zonesize fls(mem+1)
  116. * ------------------------------------------------------------------
  117. * 8 1 1 0.9-1 GB 4
  118. * 16 2 2 0.9-1 GB 4
  119. * 20 2 2 1-2 GB 5
  120. * 24 2 2 2-4 GB 6
  121. * 28 2 2 4-8 GB 7
  122. * 32 2 2 8-16 GB 8
  123. * 4 2 2 <128M 1
  124. * 30 4 3 2-4 GB 5
  125. * 48 4 3 8-16 GB 8
  126. * 32 8 4 1-2 GB 4
  127. * 32 8 4 0.9-1GB 4
  128. * 10 16 5 <128M 1
  129. * 40 16 5 900M 4
  130. * 70 64 7 2-4 GB 5
  131. * 84 64 7 4-8 GB 6
  132. * 108 512 9 4-8 GB 6
  133. * 125 1024 10 8-16 GB 8
  134. * 125 1024 10 16-32 GB 9
  135. */
  136. mem = zone->managed_pages >> (27 - PAGE_SHIFT);
  137. threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem));
  138. /*
  139. * Maximum threshold is 125
  140. */
  141. threshold = min(125, threshold);
  142. return threshold;
  143. }
  144. /*
  145. * Refresh the thresholds for each zone.
  146. */
  147. void refresh_zone_stat_thresholds(void)
  148. {
  149. struct pglist_data *pgdat;
  150. struct zone *zone;
  151. int cpu;
  152. int threshold;
  153. /* Zero current pgdat thresholds */
  154. for_each_online_pgdat(pgdat) {
  155. for_each_online_cpu(cpu) {
  156. per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold = 0;
  157. }
  158. }
  159. for_each_populated_zone(zone) {
  160. struct pglist_data *pgdat = zone->zone_pgdat;
  161. unsigned long max_drift, tolerate_drift;
  162. threshold = calculate_normal_threshold(zone);
  163. for_each_online_cpu(cpu) {
  164. int pgdat_threshold;
  165. per_cpu_ptr(zone->pageset, cpu)->stat_threshold
  166. = threshold;
  167. /* Base nodestat threshold on the largest populated zone. */
  168. pgdat_threshold = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold;
  169. per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold
  170. = max(threshold, pgdat_threshold);
  171. }
  172. /*
  173. * Only set percpu_drift_mark if there is a danger that
  174. * NR_FREE_PAGES reports the low watermark is ok when in fact
  175. * the min watermark could be breached by an allocation
  176. */
  177. tolerate_drift = low_wmark_pages(zone) - min_wmark_pages(zone);
  178. max_drift = num_online_cpus() * threshold;
  179. if (max_drift > tolerate_drift)
  180. zone->percpu_drift_mark = high_wmark_pages(zone) +
  181. max_drift;
  182. }
  183. }
  184. void set_pgdat_percpu_threshold(pg_data_t *pgdat,
  185. int (*calculate_pressure)(struct zone *))
  186. {
  187. struct zone *zone;
  188. int cpu;
  189. int threshold;
  190. int i;
  191. for (i = 0; i < pgdat->nr_zones; i++) {
  192. zone = &pgdat->node_zones[i];
  193. if (!zone->percpu_drift_mark)
  194. continue;
  195. threshold = (*calculate_pressure)(zone);
  196. for_each_online_cpu(cpu)
  197. per_cpu_ptr(zone->pageset, cpu)->stat_threshold
  198. = threshold;
  199. }
  200. }
  201. /*
  202. * For use when we know that interrupts are disabled,
  203. * or when we know that preemption is disabled and that
  204. * particular counter cannot be updated from interrupt context.
  205. */
  206. void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
  207. long delta)
  208. {
  209. struct per_cpu_pageset __percpu *pcp = zone->pageset;
  210. s8 __percpu *p = pcp->vm_stat_diff + item;
  211. long x;
  212. long t;
  213. x = delta + __this_cpu_read(*p);
  214. t = __this_cpu_read(pcp->stat_threshold);
  215. if (unlikely(x > t || x < -t)) {
  216. zone_page_state_add(x, zone, item);
  217. x = 0;
  218. }
  219. __this_cpu_write(*p, x);
  220. }
  221. EXPORT_SYMBOL(__mod_zone_page_state);
  222. void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
  223. long delta)
  224. {
  225. struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
  226. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  227. long x;
  228. long t;
  229. x = delta + __this_cpu_read(*p);
  230. t = __this_cpu_read(pcp->stat_threshold);
  231. if (unlikely(x > t || x < -t)) {
  232. node_page_state_add(x, pgdat, item);
  233. x = 0;
  234. }
  235. __this_cpu_write(*p, x);
  236. }
  237. EXPORT_SYMBOL(__mod_node_page_state);
  238. /*
  239. * Optimized increment and decrement functions.
  240. *
  241. * These are only for a single page and therefore can take a struct page *
  242. * argument instead of struct zone *. This allows the inclusion of the code
  243. * generated for page_zone(page) into the optimized functions.
  244. *
  245. * No overflow check is necessary and therefore the differential can be
  246. * incremented or decremented in place which may allow the compilers to
  247. * generate better code.
  248. * The increment or decrement is known and therefore one boundary check can
  249. * be omitted.
  250. *
  251. * NOTE: These functions are very performance sensitive. Change only
  252. * with care.
  253. *
  254. * Some processors have inc/dec instructions that are atomic vs an interrupt.
  255. * However, the code must first determine the differential location in a zone
  256. * based on the processor number and then inc/dec the counter. There is no
  257. * guarantee without disabling preemption that the processor will not change
  258. * in between and therefore the atomicity vs. interrupt cannot be exploited
  259. * in a useful way here.
  260. */
  261. void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  262. {
  263. struct per_cpu_pageset __percpu *pcp = zone->pageset;
  264. s8 __percpu *p = pcp->vm_stat_diff + item;
  265. s8 v, t;
  266. v = __this_cpu_inc_return(*p);
  267. t = __this_cpu_read(pcp->stat_threshold);
  268. if (unlikely(v > t)) {
  269. s8 overstep = t >> 1;
  270. zone_page_state_add(v + overstep, zone, item);
  271. __this_cpu_write(*p, -overstep);
  272. }
  273. }
  274. void __inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  275. {
  276. struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
  277. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  278. s8 v, t;
  279. v = __this_cpu_inc_return(*p);
  280. t = __this_cpu_read(pcp->stat_threshold);
  281. if (unlikely(v > t)) {
  282. s8 overstep = t >> 1;
  283. node_page_state_add(v + overstep, pgdat, item);
  284. __this_cpu_write(*p, -overstep);
  285. }
  286. }
  287. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  288. {
  289. __inc_zone_state(page_zone(page), item);
  290. }
  291. EXPORT_SYMBOL(__inc_zone_page_state);
  292. void __inc_node_page_state(struct page *page, enum node_stat_item item)
  293. {
  294. __inc_node_state(page_pgdat(page), item);
  295. }
  296. EXPORT_SYMBOL(__inc_node_page_state);
  297. void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  298. {
  299. struct per_cpu_pageset __percpu *pcp = zone->pageset;
  300. s8 __percpu *p = pcp->vm_stat_diff + item;
  301. s8 v, t;
  302. v = __this_cpu_dec_return(*p);
  303. t = __this_cpu_read(pcp->stat_threshold);
  304. if (unlikely(v < - t)) {
  305. s8 overstep = t >> 1;
  306. zone_page_state_add(v - overstep, zone, item);
  307. __this_cpu_write(*p, overstep);
  308. }
  309. }
  310. void __dec_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  311. {
  312. struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
  313. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  314. s8 v, t;
  315. v = __this_cpu_dec_return(*p);
  316. t = __this_cpu_read(pcp->stat_threshold);
  317. if (unlikely(v < - t)) {
  318. s8 overstep = t >> 1;
  319. node_page_state_add(v - overstep, pgdat, item);
  320. __this_cpu_write(*p, overstep);
  321. }
  322. }
  323. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  324. {
  325. __dec_zone_state(page_zone(page), item);
  326. }
  327. EXPORT_SYMBOL(__dec_zone_page_state);
  328. void __dec_node_page_state(struct page *page, enum node_stat_item item)
  329. {
  330. __dec_node_state(page_pgdat(page), item);
  331. }
  332. EXPORT_SYMBOL(__dec_node_page_state);
  333. #ifdef CONFIG_HAVE_CMPXCHG_LOCAL
  334. /*
  335. * If we have cmpxchg_local support then we do not need to incur the overhead
  336. * that comes with local_irq_save/restore if we use this_cpu_cmpxchg.
  337. *
  338. * mod_state() modifies the zone counter state through atomic per cpu
  339. * operations.
  340. *
  341. * Overstep mode specifies how overstep should handled:
  342. * 0 No overstepping
  343. * 1 Overstepping half of threshold
  344. * -1 Overstepping minus half of threshold
  345. */
  346. static inline void mod_zone_state(struct zone *zone,
  347. enum zone_stat_item item, long delta, int overstep_mode)
  348. {
  349. struct per_cpu_pageset __percpu *pcp = zone->pageset;
  350. s8 __percpu *p = pcp->vm_stat_diff + item;
  351. long o, n, t, z;
  352. do {
  353. z = 0; /* overflow to zone counters */
  354. /*
  355. * The fetching of the stat_threshold is racy. We may apply
  356. * a counter threshold to the wrong the cpu if we get
  357. * rescheduled while executing here. However, the next
  358. * counter update will apply the threshold again and
  359. * therefore bring the counter under the threshold again.
  360. *
  361. * Most of the time the thresholds are the same anyways
  362. * for all cpus in a zone.
  363. */
  364. t = this_cpu_read(pcp->stat_threshold);
  365. o = this_cpu_read(*p);
  366. n = delta + o;
  367. if (n > t || n < -t) {
  368. int os = overstep_mode * (t >> 1) ;
  369. /* Overflow must be added to zone counters */
  370. z = n + os;
  371. n = -os;
  372. }
  373. } while (this_cpu_cmpxchg(*p, o, n) != o);
  374. if (z)
  375. zone_page_state_add(z, zone, item);
  376. }
  377. void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
  378. long delta)
  379. {
  380. mod_zone_state(zone, item, delta, 0);
  381. }
  382. EXPORT_SYMBOL(mod_zone_page_state);
  383. void inc_zone_page_state(struct page *page, enum zone_stat_item item)
  384. {
  385. mod_zone_state(page_zone(page), item, 1, 1);
  386. }
  387. EXPORT_SYMBOL(inc_zone_page_state);
  388. void dec_zone_page_state(struct page *page, enum zone_stat_item item)
  389. {
  390. mod_zone_state(page_zone(page), item, -1, -1);
  391. }
  392. EXPORT_SYMBOL(dec_zone_page_state);
  393. static inline void mod_node_state(struct pglist_data *pgdat,
  394. enum node_stat_item item, int delta, int overstep_mode)
  395. {
  396. struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats;
  397. s8 __percpu *p = pcp->vm_node_stat_diff + item;
  398. long o, n, t, z;
  399. do {
  400. z = 0; /* overflow to node counters */
  401. /*
  402. * The fetching of the stat_threshold is racy. We may apply
  403. * a counter threshold to the wrong the cpu if we get
  404. * rescheduled while executing here. However, the next
  405. * counter update will apply the threshold again and
  406. * therefore bring the counter under the threshold again.
  407. *
  408. * Most of the time the thresholds are the same anyways
  409. * for all cpus in a node.
  410. */
  411. t = this_cpu_read(pcp->stat_threshold);
  412. o = this_cpu_read(*p);
  413. n = delta + o;
  414. if (n > t || n < -t) {
  415. int os = overstep_mode * (t >> 1) ;
  416. /* Overflow must be added to node counters */
  417. z = n + os;
  418. n = -os;
  419. }
  420. } while (this_cpu_cmpxchg(*p, o, n) != o);
  421. if (z)
  422. node_page_state_add(z, pgdat, item);
  423. }
  424. void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
  425. long delta)
  426. {
  427. mod_node_state(pgdat, item, delta, 0);
  428. }
  429. EXPORT_SYMBOL(mod_node_page_state);
  430. void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  431. {
  432. mod_node_state(pgdat, item, 1, 1);
  433. }
  434. void inc_node_page_state(struct page *page, enum node_stat_item item)
  435. {
  436. mod_node_state(page_pgdat(page), item, 1, 1);
  437. }
  438. EXPORT_SYMBOL(inc_node_page_state);
  439. void dec_node_page_state(struct page *page, enum node_stat_item item)
  440. {
  441. mod_node_state(page_pgdat(page), item, -1, -1);
  442. }
  443. EXPORT_SYMBOL(dec_node_page_state);
  444. #else
  445. /*
  446. * Use interrupt disable to serialize counter updates
  447. */
  448. void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
  449. long delta)
  450. {
  451. unsigned long flags;
  452. local_irq_save(flags);
  453. __mod_zone_page_state(zone, item, delta);
  454. local_irq_restore(flags);
  455. }
  456. EXPORT_SYMBOL(mod_zone_page_state);
  457. void inc_zone_page_state(struct page *page, enum zone_stat_item item)
  458. {
  459. unsigned long flags;
  460. struct zone *zone;
  461. zone = page_zone(page);
  462. local_irq_save(flags);
  463. __inc_zone_state(zone, item);
  464. local_irq_restore(flags);
  465. }
  466. EXPORT_SYMBOL(inc_zone_page_state);
  467. void dec_zone_page_state(struct page *page, enum zone_stat_item item)
  468. {
  469. unsigned long flags;
  470. local_irq_save(flags);
  471. __dec_zone_page_state(page, item);
  472. local_irq_restore(flags);
  473. }
  474. EXPORT_SYMBOL(dec_zone_page_state);
  475. void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item)
  476. {
  477. unsigned long flags;
  478. local_irq_save(flags);
  479. __inc_node_state(pgdat, item);
  480. local_irq_restore(flags);
  481. }
  482. EXPORT_SYMBOL(inc_node_state);
  483. void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item,
  484. long delta)
  485. {
  486. unsigned long flags;
  487. local_irq_save(flags);
  488. __mod_node_page_state(pgdat, item, delta);
  489. local_irq_restore(flags);
  490. }
  491. EXPORT_SYMBOL(mod_node_page_state);
  492. void inc_node_page_state(struct page *page, enum node_stat_item item)
  493. {
  494. unsigned long flags;
  495. struct pglist_data *pgdat;
  496. pgdat = page_pgdat(page);
  497. local_irq_save(flags);
  498. __inc_node_state(pgdat, item);
  499. local_irq_restore(flags);
  500. }
  501. EXPORT_SYMBOL(inc_node_page_state);
  502. void dec_node_page_state(struct page *page, enum node_stat_item item)
  503. {
  504. unsigned long flags;
  505. local_irq_save(flags);
  506. __dec_node_page_state(page, item);
  507. local_irq_restore(flags);
  508. }
  509. EXPORT_SYMBOL(dec_node_page_state);
  510. #endif
  511. /*
  512. * Fold a differential into the global counters.
  513. * Returns the number of counters updated.
  514. */
  515. static int fold_diff(int *zone_diff, int *node_diff)
  516. {
  517. int i;
  518. int changes = 0;
  519. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  520. if (zone_diff[i]) {
  521. atomic_long_add(zone_diff[i], &vm_zone_stat[i]);
  522. changes++;
  523. }
  524. for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
  525. if (node_diff[i]) {
  526. atomic_long_add(node_diff[i], &vm_node_stat[i]);
  527. changes++;
  528. }
  529. return changes;
  530. }
  531. /*
  532. * Update the zone counters for the current cpu.
  533. *
  534. * Note that refresh_cpu_vm_stats strives to only access
  535. * node local memory. The per cpu pagesets on remote zones are placed
  536. * in the memory local to the processor using that pageset. So the
  537. * loop over all zones will access a series of cachelines local to
  538. * the processor.
  539. *
  540. * The call to zone_page_state_add updates the cachelines with the
  541. * statistics in the remote zone struct as well as the global cachelines
  542. * with the global counters. These could cause remote node cache line
  543. * bouncing and will have to be only done when necessary.
  544. *
  545. * The function returns the number of global counters updated.
  546. */
  547. static int refresh_cpu_vm_stats(bool do_pagesets)
  548. {
  549. struct pglist_data *pgdat;
  550. struct zone *zone;
  551. int i;
  552. int global_zone_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
  553. int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, };
  554. int changes = 0;
  555. for_each_populated_zone(zone) {
  556. struct per_cpu_pageset __percpu *p = zone->pageset;
  557. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {
  558. int v;
  559. v = this_cpu_xchg(p->vm_stat_diff[i], 0);
  560. if (v) {
  561. atomic_long_add(v, &zone->vm_stat[i]);
  562. global_zone_diff[i] += v;
  563. #ifdef CONFIG_NUMA
  564. /* 3 seconds idle till flush */
  565. __this_cpu_write(p->expire, 3);
  566. #endif
  567. }
  568. }
  569. #ifdef CONFIG_NUMA
  570. if (do_pagesets) {
  571. cond_resched();
  572. /*
  573. * Deal with draining the remote pageset of this
  574. * processor
  575. *
  576. * Check if there are pages remaining in this pageset
  577. * if not then there is nothing to expire.
  578. */
  579. if (!__this_cpu_read(p->expire) ||
  580. !__this_cpu_read(p->pcp.count))
  581. continue;
  582. /*
  583. * We never drain zones local to this processor.
  584. */
  585. if (zone_to_nid(zone) == numa_node_id()) {
  586. __this_cpu_write(p->expire, 0);
  587. continue;
  588. }
  589. if (__this_cpu_dec_return(p->expire))
  590. continue;
  591. if (__this_cpu_read(p->pcp.count)) {
  592. drain_zone_pages(zone, this_cpu_ptr(&p->pcp));
  593. changes++;
  594. }
  595. }
  596. #endif
  597. }
  598. for_each_online_pgdat(pgdat) {
  599. struct per_cpu_nodestat __percpu *p = pgdat->per_cpu_nodestats;
  600. for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) {
  601. int v;
  602. v = this_cpu_xchg(p->vm_node_stat_diff[i], 0);
  603. if (v) {
  604. atomic_long_add(v, &pgdat->vm_stat[i]);
  605. global_node_diff[i] += v;
  606. }
  607. }
  608. }
  609. changes += fold_diff(global_zone_diff, global_node_diff);
  610. return changes;
  611. }
  612. /*
  613. * Fold the data for an offline cpu into the global array.
  614. * There cannot be any access by the offline cpu and therefore
  615. * synchronization is simplified.
  616. */
  617. void cpu_vm_stats_fold(int cpu)
  618. {
  619. struct pglist_data *pgdat;
  620. struct zone *zone;
  621. int i;
  622. int global_zone_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
  623. int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, };
  624. for_each_populated_zone(zone) {
  625. struct per_cpu_pageset *p;
  626. p = per_cpu_ptr(zone->pageset, cpu);
  627. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  628. if (p->vm_stat_diff[i]) {
  629. int v;
  630. v = p->vm_stat_diff[i];
  631. p->vm_stat_diff[i] = 0;
  632. atomic_long_add(v, &zone->vm_stat[i]);
  633. global_zone_diff[i] += v;
  634. }
  635. }
  636. for_each_online_pgdat(pgdat) {
  637. struct per_cpu_nodestat *p;
  638. p = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu);
  639. for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
  640. if (p->vm_node_stat_diff[i]) {
  641. int v;
  642. v = p->vm_node_stat_diff[i];
  643. p->vm_node_stat_diff[i] = 0;
  644. atomic_long_add(v, &pgdat->vm_stat[i]);
  645. global_node_diff[i] += v;
  646. }
  647. }
  648. fold_diff(global_zone_diff, global_node_diff);
  649. }
  650. /*
  651. * this is only called if !populated_zone(zone), which implies no other users of
  652. * pset->vm_stat_diff[] exsist.
  653. */
  654. void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
  655. {
  656. int i;
  657. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  658. if (pset->vm_stat_diff[i]) {
  659. int v = pset->vm_stat_diff[i];
  660. pset->vm_stat_diff[i] = 0;
  661. atomic_long_add(v, &zone->vm_stat[i]);
  662. atomic_long_add(v, &vm_zone_stat[i]);
  663. }
  664. }
  665. #endif
  666. #ifdef CONFIG_NUMA
  667. /*
  668. * Determine the per node value of a stat item. This function
  669. * is called frequently in a NUMA machine, so try to be as
  670. * frugal as possible.
  671. */
  672. unsigned long sum_zone_node_page_state(int node,
  673. enum zone_stat_item item)
  674. {
  675. struct zone *zones = NODE_DATA(node)->node_zones;
  676. int i;
  677. unsigned long count = 0;
  678. for (i = 0; i < MAX_NR_ZONES; i++)
  679. count += zone_page_state(zones + i, item);
  680. return count;
  681. }
  682. /*
  683. * Determine the per node value of a stat item.
  684. */
  685. unsigned long node_page_state(struct pglist_data *pgdat,
  686. enum node_stat_item item)
  687. {
  688. long x = atomic_long_read(&pgdat->vm_stat[item]);
  689. #ifdef CONFIG_SMP
  690. if (x < 0)
  691. x = 0;
  692. #endif
  693. return x;
  694. }
  695. #endif
  696. #ifdef CONFIG_COMPACTION
  697. struct contig_page_info {
  698. unsigned long free_pages;
  699. unsigned long free_blocks_total;
  700. unsigned long free_blocks_suitable;
  701. };
  702. /*
  703. * Calculate the number of free pages in a zone, how many contiguous
  704. * pages are free and how many are large enough to satisfy an allocation of
  705. * the target size. Note that this function makes no attempt to estimate
  706. * how many suitable free blocks there *might* be if MOVABLE pages were
  707. * migrated. Calculating that is possible, but expensive and can be
  708. * figured out from userspace
  709. */
  710. static void fill_contig_page_info(struct zone *zone,
  711. unsigned int suitable_order,
  712. struct contig_page_info *info)
  713. {
  714. unsigned int order;
  715. info->free_pages = 0;
  716. info->free_blocks_total = 0;
  717. info->free_blocks_suitable = 0;
  718. for (order = 0; order < MAX_ORDER; order++) {
  719. unsigned long blocks;
  720. /* Count number of free blocks */
  721. blocks = zone->free_area[order].nr_free;
  722. info->free_blocks_total += blocks;
  723. /* Count free base pages */
  724. info->free_pages += blocks << order;
  725. /* Count the suitable free blocks */
  726. if (order >= suitable_order)
  727. info->free_blocks_suitable += blocks <<
  728. (order - suitable_order);
  729. }
  730. }
  731. /*
  732. * A fragmentation index only makes sense if an allocation of a requested
  733. * size would fail. If that is true, the fragmentation index indicates
  734. * whether external fragmentation or a lack of memory was the problem.
  735. * The value can be used to determine if page reclaim or compaction
  736. * should be used
  737. */
  738. static int __fragmentation_index(unsigned int order, struct contig_page_info *info)
  739. {
  740. unsigned long requested = 1UL << order;
  741. if (!info->free_blocks_total)
  742. return 0;
  743. /* Fragmentation index only makes sense when a request would fail */
  744. if (info->free_blocks_suitable)
  745. return -1000;
  746. /*
  747. * Index is between 0 and 1 so return within 3 decimal places
  748. *
  749. * 0 => allocation would fail due to lack of memory
  750. * 1 => allocation would fail due to fragmentation
  751. */
  752. return 1000 - div_u64( (1000+(div_u64(info->free_pages * 1000ULL, requested))), info->free_blocks_total);
  753. }
  754. /* Same as __fragmentation index but allocs contig_page_info on stack */
  755. int fragmentation_index(struct zone *zone, unsigned int order)
  756. {
  757. struct contig_page_info info;
  758. fill_contig_page_info(zone, order, &info);
  759. return __fragmentation_index(order, &info);
  760. }
  761. #endif
  762. #if defined(CONFIG_PROC_FS) || defined(CONFIG_SYSFS) || defined(CONFIG_NUMA)
  763. #ifdef CONFIG_ZONE_DMA
  764. #define TEXT_FOR_DMA(xx) xx "_dma",
  765. #else
  766. #define TEXT_FOR_DMA(xx)
  767. #endif
  768. #ifdef CONFIG_ZONE_DMA32
  769. #define TEXT_FOR_DMA32(xx) xx "_dma32",
  770. #else
  771. #define TEXT_FOR_DMA32(xx)
  772. #endif
  773. #ifdef CONFIG_HIGHMEM
  774. #define TEXT_FOR_HIGHMEM(xx) xx "_high",
  775. #else
  776. #define TEXT_FOR_HIGHMEM(xx)
  777. #endif
  778. #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \
  779. TEXT_FOR_HIGHMEM(xx) xx "_movable",
  780. const char * const vmstat_text[] = {
  781. /* enum zone_stat_item countes */
  782. "nr_free_pages",
  783. "nr_zone_inactive_anon",
  784. "nr_zone_active_anon",
  785. "nr_zone_inactive_file",
  786. "nr_zone_active_file",
  787. "nr_zone_unevictable",
  788. "nr_zone_write_pending",
  789. "nr_mlock",
  790. "nr_slab_reclaimable",
  791. "nr_slab_unreclaimable",
  792. "nr_page_table_pages",
  793. "nr_kernel_stack",
  794. #if IS_ENABLED(CONFIG_SHADOW_CALL_STACK)
  795. "nr_shadow_call_stack_bytes",
  796. #endif
  797. "nr_overhead",
  798. "nr_bounce",
  799. #if IS_ENABLED(CONFIG_ZSMALLOC)
  800. "nr_zspages",
  801. #endif
  802. #ifdef CONFIG_NUMA
  803. "numa_hit",
  804. "numa_miss",
  805. "numa_foreign",
  806. "numa_interleave",
  807. "numa_local",
  808. "numa_other",
  809. #endif
  810. "nr_free_cma",
  811. /* Node-based counters */
  812. "nr_inactive_anon",
  813. "nr_active_anon",
  814. "nr_inactive_file",
  815. "nr_active_file",
  816. "nr_unevictable",
  817. "nr_isolated_anon",
  818. "nr_isolated_file",
  819. "workingset_refault",
  820. "workingset_activate",
  821. "workingset_restore",
  822. "workingset_nodereclaim",
  823. "nr_anon_pages",
  824. "nr_mapped",
  825. "nr_file_pages",
  826. "nr_dirty",
  827. "nr_writeback",
  828. "nr_writeback_temp",
  829. "nr_shmem",
  830. "nr_shmem_hugepages",
  831. "nr_shmem_pmdmapped",
  832. "nr_anon_transparent_hugepages",
  833. "nr_unstable",
  834. "nr_vmscan_write",
  835. "nr_vmscan_immediate_reclaim",
  836. "nr_dirtied",
  837. "nr_written",
  838. "nr_indirectly_reclaimable",
  839. "nr_ion_heap",
  840. "nr_gpu_heap",
  841. /* enum writeback_stat_item counters */
  842. "nr_dirty_threshold",
  843. "nr_dirty_background_threshold",
  844. #ifdef CONFIG_VM_EVENT_COUNTERS
  845. /* enum vm_event_item counters */
  846. "pgpgin",
  847. "pgpgout",
  848. "pgpgoutclean",
  849. "pswpin",
  850. "pswpout",
  851. TEXTS_FOR_ZONES("pgalloc")
  852. TEXTS_FOR_ZONES("allocstall")
  853. TEXTS_FOR_ZONES("pgskip")
  854. "pgfree",
  855. "pgactivate",
  856. "pgdeactivate",
  857. "pgfault",
  858. "pgmajfault",
  859. "pglazyfreed",
  860. "pgrefill",
  861. "pgsteal_kswapd",
  862. "pgsteal_direct",
  863. "pgscan_kswapd",
  864. "pgscan_direct",
  865. "pgscan_direct_throttle",
  866. #ifdef CONFIG_NUMA
  867. "zone_reclaim_failed",
  868. #endif
  869. "pginodesteal",
  870. "slabs_scanned",
  871. "kswapd_inodesteal",
  872. "kswapd_low_wmark_hit_quickly",
  873. "kswapd_high_wmark_hit_quickly",
  874. "pageoutrun",
  875. "pgrotated",
  876. "drop_pagecache",
  877. "drop_slab",
  878. #ifdef CONFIG_NUMA_BALANCING
  879. "numa_pte_updates",
  880. "numa_huge_pte_updates",
  881. "numa_hint_faults",
  882. "numa_hint_faults_local",
  883. "numa_pages_migrated",
  884. #endif
  885. #ifdef CONFIG_MIGRATION
  886. "pgmigrate_success",
  887. "pgmigrate_fail",
  888. #endif
  889. #ifdef CONFIG_COMPACTION
  890. "compact_migrate_scanned",
  891. "compact_free_scanned",
  892. "compact_isolated",
  893. "compact_stall",
  894. "compact_fail",
  895. "compact_success",
  896. "compact_daemon_wake",
  897. #endif
  898. #ifdef CONFIG_HUGETLB_PAGE
  899. "htlb_buddy_alloc_success",
  900. "htlb_buddy_alloc_fail",
  901. #endif
  902. "unevictable_pgs_culled",
  903. "unevictable_pgs_scanned",
  904. "unevictable_pgs_rescued",
  905. "unevictable_pgs_mlocked",
  906. "unevictable_pgs_munlocked",
  907. "unevictable_pgs_cleared",
  908. "unevictable_pgs_stranded",
  909. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  910. "thp_fault_alloc",
  911. "thp_fault_fallback",
  912. "thp_collapse_alloc",
  913. "thp_collapse_alloc_failed",
  914. "thp_file_alloc",
  915. "thp_file_mapped",
  916. "thp_split_page",
  917. "thp_split_page_failed",
  918. "thp_deferred_split_page",
  919. "thp_split_pmd",
  920. "thp_zero_page_alloc",
  921. "thp_zero_page_alloc_failed",
  922. #endif
  923. #ifdef CONFIG_MEMORY_BALLOON
  924. "balloon_inflate",
  925. "balloon_deflate",
  926. #ifdef CONFIG_BALLOON_COMPACTION
  927. "balloon_migrate",
  928. #endif
  929. #endif /* CONFIG_MEMORY_BALLOON */
  930. #ifdef CONFIG_DEBUG_TLBFLUSH
  931. "nr_tlb_remote_flush",
  932. "nr_tlb_remote_flush_received",
  933. "nr_tlb_local_flush_all",
  934. "nr_tlb_local_flush_one",
  935. #endif /* CONFIG_DEBUG_TLBFLUSH */
  936. #ifdef CONFIG_DEBUG_VM_VMACACHE
  937. "vmacache_find_calls",
  938. "vmacache_find_hits",
  939. #endif
  940. #endif /* CONFIG_VM_EVENTS_COUNTERS */
  941. };
  942. #endif /* CONFIG_PROC_FS || CONFIG_SYSFS || CONFIG_NUMA */
  943. #if (defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION)) || \
  944. defined(CONFIG_PROC_FS)
  945. static void *frag_start(struct seq_file *m, loff_t *pos)
  946. {
  947. pg_data_t *pgdat;
  948. loff_t node = *pos;
  949. for (pgdat = first_online_pgdat();
  950. pgdat && node;
  951. pgdat = next_online_pgdat(pgdat))
  952. --node;
  953. return pgdat;
  954. }
  955. static void *frag_next(struct seq_file *m, void *arg, loff_t *pos)
  956. {
  957. pg_data_t *pgdat = (pg_data_t *)arg;
  958. (*pos)++;
  959. return next_online_pgdat(pgdat);
  960. }
  961. static void frag_stop(struct seq_file *m, void *arg)
  962. {
  963. }
  964. /* Walk all the zones in a node and print using a callback */
  965. static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat,
  966. bool nolock,
  967. void (*print)(struct seq_file *m, pg_data_t *, struct zone *))
  968. {
  969. struct zone *zone;
  970. struct zone *node_zones = pgdat->node_zones;
  971. unsigned long flags;
  972. for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
  973. if (!populated_zone(zone))
  974. continue;
  975. if (!nolock)
  976. spin_lock_irqsave(&zone->lock, flags);
  977. print(m, pgdat, zone);
  978. if (!nolock)
  979. spin_unlock_irqrestore(&zone->lock, flags);
  980. }
  981. }
  982. #endif
  983. #ifdef CONFIG_PROC_FS
  984. static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  985. struct zone *zone)
  986. {
  987. int order;
  988. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  989. for (order = 0; order < MAX_ORDER; ++order)
  990. seq_printf(m, "%6lu ", zone->free_area[order].nr_free);
  991. seq_putc(m, '\n');
  992. }
  993. /*
  994. * This walks the free areas for each zone.
  995. */
  996. static int frag_show(struct seq_file *m, void *arg)
  997. {
  998. pg_data_t *pgdat = (pg_data_t *)arg;
  999. walk_zones_in_node(m, pgdat, false, frag_show_print);
  1000. return 0;
  1001. }
  1002. static void pagetypeinfo_showfree_print(struct seq_file *m,
  1003. pg_data_t *pgdat, struct zone *zone)
  1004. {
  1005. int order, mtype;
  1006. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) {
  1007. seq_printf(m, "Node %4d, zone %8s, type %12s ",
  1008. pgdat->node_id,
  1009. zone->name,
  1010. migratetype_names[mtype]);
  1011. for (order = 0; order < MAX_ORDER; ++order) {
  1012. unsigned long freecount = 0;
  1013. struct free_area *area;
  1014. struct list_head *curr;
  1015. area = &(zone->free_area[order]);
  1016. list_for_each(curr, &area->free_list[mtype])
  1017. freecount++;
  1018. seq_printf(m, "%6lu ", freecount);
  1019. }
  1020. seq_putc(m, '\n');
  1021. }
  1022. }
  1023. /* Print out the free pages at each order for each migatetype */
  1024. static int pagetypeinfo_showfree(struct seq_file *m, void *arg)
  1025. {
  1026. int order;
  1027. pg_data_t *pgdat = (pg_data_t *)arg;
  1028. /* Print header */
  1029. seq_printf(m, "%-43s ", "Free pages count per migrate type at order");
  1030. for (order = 0; order < MAX_ORDER; ++order)
  1031. seq_printf(m, "%6d ", order);
  1032. seq_putc(m, '\n');
  1033. walk_zones_in_node(m, pgdat, false, pagetypeinfo_showfree_print);
  1034. return 0;
  1035. }
  1036. static void pagetypeinfo_showblockcount_print(struct seq_file *m,
  1037. pg_data_t *pgdat, struct zone *zone)
  1038. {
  1039. int mtype;
  1040. unsigned long pfn;
  1041. unsigned long start_pfn = zone->zone_start_pfn;
  1042. unsigned long end_pfn = zone_end_pfn(zone);
  1043. unsigned long count[MIGRATE_TYPES] = { 0, };
  1044. for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
  1045. struct page *page;
  1046. if (!pfn_valid(pfn))
  1047. continue;
  1048. page = pfn_to_page(pfn);
  1049. /* Watch for unexpected holes punched in the memmap */
  1050. if (!memmap_valid_within(pfn, page, zone))
  1051. continue;
  1052. if (page_zone(page) != zone)
  1053. continue;
  1054. mtype = get_pageblock_migratetype(page);
  1055. if (mtype < MIGRATE_TYPES)
  1056. count[mtype]++;
  1057. }
  1058. /* Print counts */
  1059. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  1060. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  1061. seq_printf(m, "%12lu ", count[mtype]);
  1062. seq_putc(m, '\n');
  1063. }
  1064. /* Print out the free pages at each order for each migratetype */
  1065. static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg)
  1066. {
  1067. int mtype;
  1068. pg_data_t *pgdat = (pg_data_t *)arg;
  1069. seq_printf(m, "\n%-23s", "Number of blocks type ");
  1070. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  1071. seq_printf(m, "%12s ", migratetype_names[mtype]);
  1072. seq_putc(m, '\n');
  1073. walk_zones_in_node(m, pgdat, false,
  1074. pagetypeinfo_showblockcount_print);
  1075. return 0;
  1076. }
  1077. /*
  1078. * Print out the number of pageblocks for each migratetype that contain pages
  1079. * of other types. This gives an indication of how well fallbacks are being
  1080. * contained by rmqueue_fallback(). It requires information from PAGE_OWNER
  1081. * to determine what is going on
  1082. */
  1083. static void pagetypeinfo_showmixedcount(struct seq_file *m, pg_data_t *pgdat)
  1084. {
  1085. #ifdef CONFIG_PAGE_OWNER
  1086. int mtype;
  1087. if (!static_branch_unlikely(&page_owner_inited))
  1088. return;
  1089. drain_all_pages(NULL);
  1090. seq_printf(m, "\n%-23s", "Number of mixed blocks ");
  1091. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  1092. seq_printf(m, "%12s ", migratetype_names[mtype]);
  1093. seq_putc(m, '\n');
  1094. walk_zones_in_node(m, pgdat, true,
  1095. pagetypeinfo_showmixedcount_print);
  1096. #endif /* CONFIG_PAGE_OWNER */
  1097. }
  1098. /*
  1099. * This prints out statistics in relation to grouping pages by mobility.
  1100. * It is expensive to collect so do not constantly read the file.
  1101. */
  1102. static int pagetypeinfo_show(struct seq_file *m, void *arg)
  1103. {
  1104. pg_data_t *pgdat = (pg_data_t *)arg;
  1105. /* check memoryless node */
  1106. if (!node_state(pgdat->node_id, N_MEMORY))
  1107. return 0;
  1108. seq_printf(m, "Page block order: %d\n", pageblock_order);
  1109. seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages);
  1110. seq_putc(m, '\n');
  1111. pagetypeinfo_showfree(m, pgdat);
  1112. pagetypeinfo_showblockcount(m, pgdat);
  1113. pagetypeinfo_showmixedcount(m, pgdat);
  1114. return 0;
  1115. }
  1116. static const struct seq_operations fragmentation_op = {
  1117. .start = frag_start,
  1118. .next = frag_next,
  1119. .stop = frag_stop,
  1120. .show = frag_show,
  1121. };
  1122. static int fragmentation_open(struct inode *inode, struct file *file)
  1123. {
  1124. return seq_open(file, &fragmentation_op);
  1125. }
  1126. static const struct file_operations fragmentation_file_operations = {
  1127. .open = fragmentation_open,
  1128. .read = seq_read,
  1129. .llseek = seq_lseek,
  1130. .release = seq_release,
  1131. };
  1132. static const struct seq_operations pagetypeinfo_op = {
  1133. .start = frag_start,
  1134. .next = frag_next,
  1135. .stop = frag_stop,
  1136. .show = pagetypeinfo_show,
  1137. };
  1138. static int pagetypeinfo_open(struct inode *inode, struct file *file)
  1139. {
  1140. return seq_open(file, &pagetypeinfo_op);
  1141. }
  1142. static const struct file_operations pagetypeinfo_file_ops = {
  1143. .open = pagetypeinfo_open,
  1144. .read = seq_read,
  1145. .llseek = seq_lseek,
  1146. .release = seq_release,
  1147. };
  1148. static bool is_zone_first_populated(pg_data_t *pgdat, struct zone *zone)
  1149. {
  1150. int zid;
  1151. for (zid = 0; zid < MAX_NR_ZONES; zid++) {
  1152. struct zone *compare = &pgdat->node_zones[zid];
  1153. if (populated_zone(compare))
  1154. return zone == compare;
  1155. }
  1156. return false;
  1157. }
  1158. static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
  1159. struct zone *zone)
  1160. {
  1161. int i;
  1162. seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name);
  1163. if (is_zone_first_populated(pgdat, zone)) {
  1164. seq_printf(m, "\n per-node stats");
  1165. for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) {
  1166. seq_printf(m, "\n %-12s %lu",
  1167. vmstat_text[i + NR_VM_ZONE_STAT_ITEMS],
  1168. node_page_state(pgdat, i));
  1169. }
  1170. }
  1171. seq_printf(m,
  1172. "\n pages free %lu"
  1173. "\n min %lu"
  1174. "\n low %lu"
  1175. "\n high %lu"
  1176. "\n spanned %lu"
  1177. "\n present %lu"
  1178. "\n managed %lu",
  1179. zone_page_state(zone, NR_FREE_PAGES),
  1180. min_wmark_pages(zone),
  1181. low_wmark_pages(zone),
  1182. high_wmark_pages(zone),
  1183. zone->spanned_pages,
  1184. zone->present_pages,
  1185. zone->managed_pages);
  1186. seq_printf(m,
  1187. "\n protection: (%ld",
  1188. zone->lowmem_reserve[0]);
  1189. for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++)
  1190. seq_printf(m, ", %ld", zone->lowmem_reserve[i]);
  1191. seq_putc(m, ')');
  1192. /* If unpopulated, no other information is useful */
  1193. if (!populated_zone(zone)) {
  1194. seq_putc(m, '\n');
  1195. return;
  1196. }
  1197. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  1198. seq_printf(m, "\n %-12s %lu", vmstat_text[i],
  1199. zone_page_state(zone, i));
  1200. seq_printf(m, "\n pagesets");
  1201. for_each_online_cpu(i) {
  1202. struct per_cpu_pageset *pageset;
  1203. pageset = per_cpu_ptr(zone->pageset, i);
  1204. seq_printf(m,
  1205. "\n cpu: %i"
  1206. "\n count: %i"
  1207. "\n high: %i"
  1208. "\n batch: %i",
  1209. i,
  1210. pageset->pcp.count,
  1211. pageset->pcp.high,
  1212. pageset->pcp.batch);
  1213. #ifdef CONFIG_SMP
  1214. seq_printf(m, "\n vm stats threshold: %d",
  1215. pageset->stat_threshold);
  1216. #endif
  1217. }
  1218. seq_printf(m,
  1219. "\n node_unreclaimable: %u"
  1220. "\n start_pfn: %lu"
  1221. "\n node_inactive_ratio: %u",
  1222. pgdat->kswapd_failures >= MAX_RECLAIM_RETRIES,
  1223. zone->zone_start_pfn,
  1224. zone->zone_pgdat->inactive_ratio);
  1225. seq_putc(m, '\n');
  1226. }
  1227. /*
  1228. * Output information about zones in @pgdat.
  1229. */
  1230. static int zoneinfo_show(struct seq_file *m, void *arg)
  1231. {
  1232. pg_data_t *pgdat = (pg_data_t *)arg;
  1233. walk_zones_in_node(m, pgdat, false, zoneinfo_show_print);
  1234. return 0;
  1235. }
  1236. static const struct seq_operations zoneinfo_op = {
  1237. .start = frag_start, /* iterate over all zones. The same as in
  1238. * fragmentation. */
  1239. .next = frag_next,
  1240. .stop = frag_stop,
  1241. .show = zoneinfo_show,
  1242. };
  1243. static int zoneinfo_open(struct inode *inode, struct file *file)
  1244. {
  1245. return seq_open(file, &zoneinfo_op);
  1246. }
  1247. static const struct file_operations proc_zoneinfo_file_operations = {
  1248. .open = zoneinfo_open,
  1249. .read = seq_read,
  1250. .llseek = seq_lseek,
  1251. .release = seq_release,
  1252. };
  1253. enum writeback_stat_item {
  1254. NR_DIRTY_THRESHOLD,
  1255. NR_DIRTY_BG_THRESHOLD,
  1256. NR_VM_WRITEBACK_STAT_ITEMS,
  1257. };
  1258. static void *vmstat_start(struct seq_file *m, loff_t *pos)
  1259. {
  1260. unsigned long *v;
  1261. int i, stat_items_size;
  1262. if (*pos >= ARRAY_SIZE(vmstat_text))
  1263. return NULL;
  1264. stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) +
  1265. NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) +
  1266. NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long);
  1267. #ifdef CONFIG_VM_EVENT_COUNTERS
  1268. stat_items_size += sizeof(struct vm_event_state);
  1269. #endif
  1270. v = kmalloc(stat_items_size, GFP_KERNEL);
  1271. m->private = v;
  1272. if (!v)
  1273. return ERR_PTR(-ENOMEM);
  1274. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  1275. v[i] = global_page_state(i);
  1276. v += NR_VM_ZONE_STAT_ITEMS;
  1277. for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
  1278. v[i] = global_node_page_state(i);
  1279. v += NR_VM_NODE_STAT_ITEMS;
  1280. global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD,
  1281. v + NR_DIRTY_THRESHOLD);
  1282. v += NR_VM_WRITEBACK_STAT_ITEMS;
  1283. #ifdef CONFIG_VM_EVENT_COUNTERS
  1284. all_vm_events(v);
  1285. v[PGPGIN] /= 2; /* sectors -> kbytes */
  1286. v[PGPGOUT] /= 2;
  1287. #endif
  1288. return (unsigned long *)m->private + *pos;
  1289. }
  1290. static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
  1291. {
  1292. (*pos)++;
  1293. if (*pos >= ARRAY_SIZE(vmstat_text))
  1294. return NULL;
  1295. return (unsigned long *)m->private + *pos;
  1296. }
  1297. static int vmstat_show(struct seq_file *m, void *arg)
  1298. {
  1299. unsigned long *l = arg;
  1300. unsigned long off = l - (unsigned long *)m->private;
  1301. seq_puts(m, vmstat_text[off]);
  1302. seq_put_decimal_ull(m, " ", *l);
  1303. seq_putc(m, '\n');
  1304. return 0;
  1305. }
  1306. static void vmstat_stop(struct seq_file *m, void *arg)
  1307. {
  1308. kfree(m->private);
  1309. m->private = NULL;
  1310. }
  1311. static const struct seq_operations vmstat_op = {
  1312. .start = vmstat_start,
  1313. .next = vmstat_next,
  1314. .stop = vmstat_stop,
  1315. .show = vmstat_show,
  1316. };
  1317. static int vmstat_open(struct inode *inode, struct file *file)
  1318. {
  1319. return seq_open(file, &vmstat_op);
  1320. }
  1321. static const struct file_operations proc_vmstat_file_operations = {
  1322. .open = vmstat_open,
  1323. .read = seq_read,
  1324. .llseek = seq_lseek,
  1325. .release = seq_release,
  1326. };
  1327. #endif /* CONFIG_PROC_FS */
  1328. #ifdef CONFIG_SMP
  1329. static struct workqueue_struct *vmstat_wq;
  1330. static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
  1331. int sysctl_stat_interval __read_mostly = HZ;
  1332. #ifdef CONFIG_PROC_FS
  1333. static void refresh_vm_stats(struct work_struct *work)
  1334. {
  1335. refresh_cpu_vm_stats(true);
  1336. }
  1337. int vmstat_refresh(struct ctl_table *table, int write,
  1338. void __user *buffer, size_t *lenp, loff_t *ppos)
  1339. {
  1340. long val;
  1341. int err;
  1342. int i;
  1343. /*
  1344. * The regular update, every sysctl_stat_interval, may come later
  1345. * than expected: leaving a significant amount in per_cpu buckets.
  1346. * This is particularly misleading when checking a quantity of HUGE
  1347. * pages, immediately after running a test. /proc/sys/vm/stat_refresh,
  1348. * which can equally be echo'ed to or cat'ted from (by root),
  1349. * can be used to update the stats just before reading them.
  1350. *
  1351. * Oh, and since global_page_state() etc. are so careful to hide
  1352. * transiently negative values, report an error here if any of
  1353. * the stats is negative, so we know to go looking for imbalance.
  1354. */
  1355. err = schedule_on_each_cpu(refresh_vm_stats);
  1356. if (err)
  1357. return err;
  1358. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {
  1359. val = atomic_long_read(&vm_zone_stat[i]);
  1360. if (val < 0) {
  1361. pr_warn("%s: %s %ld\n",
  1362. __func__, vmstat_text[i], val);
  1363. err = -EINVAL;
  1364. }
  1365. }
  1366. if (err)
  1367. return err;
  1368. if (write)
  1369. *ppos += *lenp;
  1370. else
  1371. *lenp = 0;
  1372. return 0;
  1373. }
  1374. #endif /* CONFIG_PROC_FS */
  1375. static void vmstat_update(struct work_struct *w)
  1376. {
  1377. if (refresh_cpu_vm_stats(true) && !cpu_isolated(smp_processor_id())) {
  1378. /*
  1379. * Counters were updated so we expect more updates
  1380. * to occur in the future. Keep on running the
  1381. * update worker thread.
  1382. */
  1383. queue_delayed_work_on(smp_processor_id(), vmstat_wq,
  1384. this_cpu_ptr(&vmstat_work),
  1385. round_jiffies_relative(sysctl_stat_interval));
  1386. }
  1387. }
  1388. /*
  1389. * Switch off vmstat processing and then fold all the remaining differentials
  1390. * until the diffs stay at zero. The function is used by NOHZ and can only be
  1391. * invoked when tick processing is not active.
  1392. */
  1393. /*
  1394. * Check if the diffs for a certain cpu indicate that
  1395. * an update is needed.
  1396. */
  1397. static bool need_update(int cpu)
  1398. {
  1399. struct zone *zone;
  1400. for_each_populated_zone(zone) {
  1401. struct per_cpu_pageset *p = per_cpu_ptr(zone->pageset, cpu);
  1402. BUILD_BUG_ON(sizeof(p->vm_stat_diff[0]) != 1);
  1403. /*
  1404. * The fast way of checking if there are any vmstat diffs.
  1405. * This works because the diffs are byte sized items.
  1406. */
  1407. if (memchr_inv(p->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS))
  1408. return true;
  1409. }
  1410. return false;
  1411. }
  1412. /*
  1413. * Switch off vmstat processing and then fold all the remaining differentials
  1414. * until the diffs stay at zero. The function is used by NOHZ and can only be
  1415. * invoked when tick processing is not active.
  1416. */
  1417. void quiet_vmstat(void)
  1418. {
  1419. if (system_state != SYSTEM_RUNNING)
  1420. return;
  1421. if (!delayed_work_pending(this_cpu_ptr(&vmstat_work)))
  1422. return;
  1423. if (!need_update(smp_processor_id()))
  1424. return;
  1425. /*
  1426. * Just refresh counters and do not care about the pending delayed
  1427. * vmstat_update. It doesn't fire that often to matter and canceling
  1428. * it would be too expensive from this path.
  1429. * vmstat_shepherd will take care about that for us.
  1430. */
  1431. refresh_cpu_vm_stats(false);
  1432. }
  1433. /*
  1434. * Shepherd worker thread that checks the
  1435. * differentials of processors that have their worker
  1436. * threads for vm statistics updates disabled because of
  1437. * inactivity.
  1438. */
  1439. static void vmstat_shepherd(struct work_struct *w);
  1440. static DECLARE_DEFERRABLE_WORK(shepherd, vmstat_shepherd);
  1441. static void vmstat_shepherd(struct work_struct *w)
  1442. {
  1443. int cpu;
  1444. get_online_cpus();
  1445. /* Check processors whose vmstat worker threads have been disabled */
  1446. for_each_online_cpu(cpu) {
  1447. struct delayed_work *dw = &per_cpu(vmstat_work, cpu);
  1448. if (!delayed_work_pending(dw) && need_update(cpu) &&
  1449. !cpu_isolated(cpu))
  1450. queue_delayed_work_on(cpu, vmstat_wq, dw, 0);
  1451. }
  1452. put_online_cpus();
  1453. schedule_delayed_work(&shepherd,
  1454. round_jiffies_relative(sysctl_stat_interval));
  1455. }
  1456. static void __init start_shepherd_timer(void)
  1457. {
  1458. int cpu;
  1459. for_each_possible_cpu(cpu)
  1460. INIT_DEFERRABLE_WORK(per_cpu_ptr(&vmstat_work, cpu),
  1461. vmstat_update);
  1462. vmstat_wq = alloc_workqueue("vmstat", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
  1463. schedule_delayed_work(&shepherd,
  1464. round_jiffies_relative(sysctl_stat_interval));
  1465. }
  1466. static void __init init_cpu_node_state(void)
  1467. {
  1468. int cpu;
  1469. get_online_cpus();
  1470. for_each_online_cpu(cpu)
  1471. node_set_state(cpu_to_node(cpu), N_CPU);
  1472. put_online_cpus();
  1473. }
  1474. static void vmstat_cpu_dead(int node)
  1475. {
  1476. int cpu;
  1477. get_online_cpus();
  1478. for_each_online_cpu(cpu)
  1479. if (cpu_to_node(cpu) == node)
  1480. goto end;
  1481. node_clear_state(node, N_CPU);
  1482. end:
  1483. put_online_cpus();
  1484. }
  1485. /*
  1486. * Use the cpu notifier to insure that the thresholds are recalculated
  1487. * when necessary.
  1488. */
  1489. static int vmstat_cpuup_callback(struct notifier_block *nfb,
  1490. unsigned long action,
  1491. void *hcpu)
  1492. {
  1493. long cpu = (long)hcpu;
  1494. switch (action) {
  1495. case CPU_ONLINE:
  1496. case CPU_ONLINE_FROZEN:
  1497. refresh_zone_stat_thresholds();
  1498. node_set_state(cpu_to_node(cpu), N_CPU);
  1499. break;
  1500. case CPU_DOWN_PREPARE:
  1501. case CPU_DOWN_PREPARE_FROZEN:
  1502. cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu));
  1503. break;
  1504. case CPU_DOWN_FAILED:
  1505. case CPU_DOWN_FAILED_FROZEN:
  1506. break;
  1507. case CPU_DEAD:
  1508. case CPU_DEAD_FROZEN:
  1509. refresh_zone_stat_thresholds();
  1510. vmstat_cpu_dead(cpu_to_node(cpu));
  1511. break;
  1512. default:
  1513. break;
  1514. }
  1515. return NOTIFY_OK;
  1516. }
  1517. static struct notifier_block vmstat_notifier =
  1518. { &vmstat_cpuup_callback, NULL, 0 };
  1519. #endif
  1520. static int __init setup_vmstat(void)
  1521. {
  1522. #ifdef CONFIG_SMP
  1523. cpu_notifier_register_begin();
  1524. __register_cpu_notifier(&vmstat_notifier);
  1525. init_cpu_node_state();
  1526. start_shepherd_timer();
  1527. cpu_notifier_register_done();
  1528. #endif
  1529. #ifdef CONFIG_PROC_FS
  1530. proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  1531. proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  1532. proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  1533. proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  1534. #endif
  1535. return 0;
  1536. }
  1537. module_init(setup_vmstat)
  1538. #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION)
  1539. /*
  1540. * Return an index indicating how much of the available free memory is
  1541. * unusable for an allocation of the requested size.
  1542. */
  1543. static int unusable_free_index(unsigned int order,
  1544. struct contig_page_info *info)
  1545. {
  1546. /* No free memory is interpreted as all free memory is unusable */
  1547. if (info->free_pages == 0)
  1548. return 1000;
  1549. /*
  1550. * Index should be a value between 0 and 1. Return a value to 3
  1551. * decimal places.
  1552. *
  1553. * 0 => no fragmentation
  1554. * 1 => high fragmentation
  1555. */
  1556. return div_u64((info->free_pages - (info->free_blocks_suitable << order)) * 1000ULL, info->free_pages);
  1557. }
  1558. static void unusable_show_print(struct seq_file *m,
  1559. pg_data_t *pgdat, struct zone *zone)
  1560. {
  1561. unsigned int order;
  1562. int index;
  1563. struct contig_page_info info;
  1564. seq_printf(m, "Node %d, zone %8s ",
  1565. pgdat->node_id,
  1566. zone->name);
  1567. for (order = 0; order < MAX_ORDER; ++order) {
  1568. fill_contig_page_info(zone, order, &info);
  1569. index = unusable_free_index(order, &info);
  1570. seq_printf(m, "%d.%03d ", index / 1000, index % 1000);
  1571. }
  1572. seq_putc(m, '\n');
  1573. }
  1574. /*
  1575. * Display unusable free space index
  1576. *
  1577. * The unusable free space index measures how much of the available free
  1578. * memory cannot be used to satisfy an allocation of a given size and is a
  1579. * value between 0 and 1. The higher the value, the more of free memory is
  1580. * unusable and by implication, the worse the external fragmentation is. This
  1581. * can be expressed as a percentage by multiplying by 100.
  1582. */
  1583. static int unusable_show(struct seq_file *m, void *arg)
  1584. {
  1585. pg_data_t *pgdat = (pg_data_t *)arg;
  1586. /* check memoryless node */
  1587. if (!node_state(pgdat->node_id, N_MEMORY))
  1588. return 0;
  1589. walk_zones_in_node(m, pgdat, false, unusable_show_print);
  1590. return 0;
  1591. }
  1592. static const struct seq_operations unusable_op = {
  1593. .start = frag_start,
  1594. .next = frag_next,
  1595. .stop = frag_stop,
  1596. .show = unusable_show,
  1597. };
  1598. static int unusable_open(struct inode *inode, struct file *file)
  1599. {
  1600. return seq_open(file, &unusable_op);
  1601. }
  1602. static const struct file_operations unusable_file_ops = {
  1603. .open = unusable_open,
  1604. .read = seq_read,
  1605. .llseek = seq_lseek,
  1606. .release = seq_release,
  1607. };
  1608. static void extfrag_show_print(struct seq_file *m,
  1609. pg_data_t *pgdat, struct zone *zone)
  1610. {
  1611. unsigned int order;
  1612. int index;
  1613. /* Alloc on stack as interrupts are disabled for zone walk */
  1614. struct contig_page_info info;
  1615. seq_printf(m, "Node %d, zone %8s ",
  1616. pgdat->node_id,
  1617. zone->name);
  1618. for (order = 0; order < MAX_ORDER; ++order) {
  1619. fill_contig_page_info(zone, order, &info);
  1620. index = __fragmentation_index(order, &info);
  1621. seq_printf(m, "%d.%03d ", index / 1000, index % 1000);
  1622. }
  1623. seq_putc(m, '\n');
  1624. }
  1625. /*
  1626. * Display fragmentation index for orders that allocations would fail for
  1627. */
  1628. static int extfrag_show(struct seq_file *m, void *arg)
  1629. {
  1630. pg_data_t *pgdat = (pg_data_t *)arg;
  1631. walk_zones_in_node(m, pgdat, false, extfrag_show_print);
  1632. return 0;
  1633. }
  1634. static const struct seq_operations extfrag_op = {
  1635. .start = frag_start,
  1636. .next = frag_next,
  1637. .stop = frag_stop,
  1638. .show = extfrag_show,
  1639. };
  1640. static int extfrag_open(struct inode *inode, struct file *file)
  1641. {
  1642. return seq_open(file, &extfrag_op);
  1643. }
  1644. static const struct file_operations extfrag_file_ops = {
  1645. .open = extfrag_open,
  1646. .read = seq_read,
  1647. .llseek = seq_lseek,
  1648. .release = seq_release,
  1649. };
  1650. static int __init extfrag_debug_init(void)
  1651. {
  1652. struct dentry *extfrag_debug_root;
  1653. extfrag_debug_root = debugfs_create_dir("extfrag", NULL);
  1654. if (!extfrag_debug_root)
  1655. return -ENOMEM;
  1656. if (!debugfs_create_file("unusable_index", 0444,
  1657. extfrag_debug_root, NULL, &unusable_file_ops))
  1658. goto fail;
  1659. if (!debugfs_create_file("extfrag_index", 0444,
  1660. extfrag_debug_root, NULL, &extfrag_file_ops))
  1661. goto fail;
  1662. return 0;
  1663. fail:
  1664. debugfs_remove_recursive(extfrag_debug_root);
  1665. return -ENOMEM;
  1666. }
  1667. module_init(extfrag_debug_init);
  1668. #endif