vmstat.c 20 KB

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