vmstat.c 20 KB

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