vmstat.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. * The cpu specified must be either the current cpu or a processor that
  240. * is not online. If it is the current cpu then the execution thread must
  241. * be pinned to the current cpu.
  242. *
  243. * Note that refresh_cpu_vm_stats strives to only access
  244. * node local memory. The per cpu pagesets on remote zones are placed
  245. * in the memory local to the processor using that pageset. So the
  246. * loop over all zones will access a series of cachelines local to
  247. * the processor.
  248. *
  249. * The call to zone_page_state_add updates the cachelines with the
  250. * statistics in the remote zone struct as well as the global cachelines
  251. * with the global counters. These could cause remote node cache line
  252. * bouncing and will have to be only done when necessary.
  253. */
  254. void refresh_cpu_vm_stats(int cpu)
  255. {
  256. struct zone *zone;
  257. int i;
  258. int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
  259. for_each_zone(zone) {
  260. struct per_cpu_pageset *p;
  261. if (!populated_zone(zone))
  262. continue;
  263. p = zone_pcp(zone, cpu);
  264. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  265. if (p->vm_stat_diff[i]) {
  266. unsigned long flags;
  267. int v;
  268. local_irq_save(flags);
  269. v = p->vm_stat_diff[i];
  270. p->vm_stat_diff[i] = 0;
  271. local_irq_restore(flags);
  272. atomic_long_add(v, &zone->vm_stat[i]);
  273. global_diff[i] += v;
  274. #ifdef CONFIG_NUMA
  275. /* 3 seconds idle till flush */
  276. p->expire = 3;
  277. #endif
  278. }
  279. #ifdef CONFIG_NUMA
  280. /*
  281. * Deal with draining the remote pageset of this
  282. * processor
  283. *
  284. * Check if there are pages remaining in this pageset
  285. * if not then there is nothing to expire.
  286. */
  287. if (!p->expire || !p->pcp.count)
  288. continue;
  289. /*
  290. * We never drain zones local to this processor.
  291. */
  292. if (zone_to_nid(zone) == numa_node_id()) {
  293. p->expire = 0;
  294. continue;
  295. }
  296. p->expire--;
  297. if (p->expire)
  298. continue;
  299. if (p->pcp.count)
  300. drain_zone_pages(zone, &p->pcp);
  301. #endif
  302. }
  303. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  304. if (global_diff[i])
  305. atomic_long_add(global_diff[i], &vm_stat[i]);
  306. }
  307. #endif
  308. #ifdef CONFIG_NUMA
  309. /*
  310. * zonelist = the list of zones passed to the allocator
  311. * z = the zone from which the allocation occurred.
  312. *
  313. * Must be called with interrupts disabled.
  314. */
  315. void zone_statistics(struct zonelist *zonelist, struct zone *z)
  316. {
  317. if (z->zone_pgdat == zonelist->zones[0]->zone_pgdat) {
  318. __inc_zone_state(z, NUMA_HIT);
  319. } else {
  320. __inc_zone_state(z, NUMA_MISS);
  321. __inc_zone_state(zonelist->zones[0], NUMA_FOREIGN);
  322. }
  323. if (z->node == numa_node_id())
  324. __inc_zone_state(z, NUMA_LOCAL);
  325. else
  326. __inc_zone_state(z, NUMA_OTHER);
  327. }
  328. #endif
  329. #ifdef CONFIG_PROC_FS
  330. #include <linux/seq_file.h>
  331. static char * const migratetype_names[MIGRATE_TYPES] = {
  332. "Unmovable",
  333. "Reclaimable",
  334. "Movable",
  335. "Reserve",
  336. };
  337. static void *frag_start(struct seq_file *m, loff_t *pos)
  338. {
  339. pg_data_t *pgdat;
  340. loff_t node = *pos;
  341. for (pgdat = first_online_pgdat();
  342. pgdat && node;
  343. pgdat = next_online_pgdat(pgdat))
  344. --node;
  345. return pgdat;
  346. }
  347. static void *frag_next(struct seq_file *m, void *arg, loff_t *pos)
  348. {
  349. pg_data_t *pgdat = (pg_data_t *)arg;
  350. (*pos)++;
  351. return next_online_pgdat(pgdat);
  352. }
  353. static void frag_stop(struct seq_file *m, void *arg)
  354. {
  355. }
  356. /* Walk all the zones in a node and print using a callback */
  357. static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat,
  358. void (*print)(struct seq_file *m, pg_data_t *, struct zone *))
  359. {
  360. struct zone *zone;
  361. struct zone *node_zones = pgdat->node_zones;
  362. unsigned long flags;
  363. for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
  364. if (!populated_zone(zone))
  365. continue;
  366. spin_lock_irqsave(&zone->lock, flags);
  367. print(m, pgdat, zone);
  368. spin_unlock_irqrestore(&zone->lock, flags);
  369. }
  370. }
  371. static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  372. struct zone *zone)
  373. {
  374. int order;
  375. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  376. for (order = 0; order < MAX_ORDER; ++order)
  377. seq_printf(m, "%6lu ", zone->free_area[order].nr_free);
  378. seq_putc(m, '\n');
  379. }
  380. /*
  381. * This walks the free areas for each zone.
  382. */
  383. static int frag_show(struct seq_file *m, void *arg)
  384. {
  385. pg_data_t *pgdat = (pg_data_t *)arg;
  386. walk_zones_in_node(m, pgdat, frag_show_print);
  387. return 0;
  388. }
  389. static void pagetypeinfo_showfree_print(struct seq_file *m,
  390. pg_data_t *pgdat, struct zone *zone)
  391. {
  392. int order, mtype;
  393. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) {
  394. seq_printf(m, "Node %4d, zone %8s, type %12s ",
  395. pgdat->node_id,
  396. zone->name,
  397. migratetype_names[mtype]);
  398. for (order = 0; order < MAX_ORDER; ++order) {
  399. unsigned long freecount = 0;
  400. struct free_area *area;
  401. struct list_head *curr;
  402. area = &(zone->free_area[order]);
  403. list_for_each(curr, &area->free_list[mtype])
  404. freecount++;
  405. seq_printf(m, "%6lu ", freecount);
  406. }
  407. seq_putc(m, '\n');
  408. }
  409. }
  410. /* Print out the free pages at each order for each migatetype */
  411. static int pagetypeinfo_showfree(struct seq_file *m, void *arg)
  412. {
  413. int order;
  414. pg_data_t *pgdat = (pg_data_t *)arg;
  415. /* Print header */
  416. seq_printf(m, "%-43s ", "Free pages count per migrate type at order");
  417. for (order = 0; order < MAX_ORDER; ++order)
  418. seq_printf(m, "%6d ", order);
  419. seq_putc(m, '\n');
  420. walk_zones_in_node(m, pgdat, pagetypeinfo_showfree_print);
  421. return 0;
  422. }
  423. static void pagetypeinfo_showblockcount_print(struct seq_file *m,
  424. pg_data_t *pgdat, struct zone *zone)
  425. {
  426. int mtype;
  427. unsigned long pfn;
  428. unsigned long start_pfn = zone->zone_start_pfn;
  429. unsigned long end_pfn = start_pfn + zone->spanned_pages;
  430. unsigned long count[MIGRATE_TYPES] = { 0, };
  431. for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
  432. struct page *page;
  433. if (!pfn_valid(pfn))
  434. continue;
  435. page = pfn_to_page(pfn);
  436. mtype = get_pageblock_migratetype(page);
  437. count[mtype]++;
  438. }
  439. /* Print counts */
  440. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  441. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  442. seq_printf(m, "%12lu ", count[mtype]);
  443. seq_putc(m, '\n');
  444. }
  445. /* Print out the free pages at each order for each migratetype */
  446. static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg)
  447. {
  448. int mtype;
  449. pg_data_t *pgdat = (pg_data_t *)arg;
  450. seq_printf(m, "\n%-23s", "Number of blocks type ");
  451. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  452. seq_printf(m, "%12s ", migratetype_names[mtype]);
  453. seq_putc(m, '\n');
  454. walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print);
  455. return 0;
  456. }
  457. /*
  458. * This prints out statistics in relation to grouping pages by mobility.
  459. * It is expensive to collect so do not constantly read the file.
  460. */
  461. static int pagetypeinfo_show(struct seq_file *m, void *arg)
  462. {
  463. pg_data_t *pgdat = (pg_data_t *)arg;
  464. seq_printf(m, "Page block order: %d\n", pageblock_order);
  465. seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages);
  466. seq_putc(m, '\n');
  467. pagetypeinfo_showfree(m, pgdat);
  468. pagetypeinfo_showblockcount(m, pgdat);
  469. return 0;
  470. }
  471. const struct seq_operations fragmentation_op = {
  472. .start = frag_start,
  473. .next = frag_next,
  474. .stop = frag_stop,
  475. .show = frag_show,
  476. };
  477. const struct seq_operations pagetypeinfo_op = {
  478. .start = frag_start,
  479. .next = frag_next,
  480. .stop = frag_stop,
  481. .show = pagetypeinfo_show,
  482. };
  483. #ifdef CONFIG_ZONE_DMA
  484. #define TEXT_FOR_DMA(xx) xx "_dma",
  485. #else
  486. #define TEXT_FOR_DMA(xx)
  487. #endif
  488. #ifdef CONFIG_ZONE_DMA32
  489. #define TEXT_FOR_DMA32(xx) xx "_dma32",
  490. #else
  491. #define TEXT_FOR_DMA32(xx)
  492. #endif
  493. #ifdef CONFIG_HIGHMEM
  494. #define TEXT_FOR_HIGHMEM(xx) xx "_high",
  495. #else
  496. #define TEXT_FOR_HIGHMEM(xx)
  497. #endif
  498. #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \
  499. TEXT_FOR_HIGHMEM(xx) xx "_movable",
  500. static const char * const vmstat_text[] = {
  501. /* Zoned VM counters */
  502. "nr_free_pages",
  503. "nr_inactive",
  504. "nr_active",
  505. "nr_anon_pages",
  506. "nr_mapped",
  507. "nr_file_pages",
  508. "nr_dirty",
  509. "nr_writeback",
  510. "nr_slab_reclaimable",
  511. "nr_slab_unreclaimable",
  512. "nr_page_table_pages",
  513. "nr_unstable",
  514. "nr_bounce",
  515. "nr_vmscan_write",
  516. #ifdef CONFIG_NUMA
  517. "numa_hit",
  518. "numa_miss",
  519. "numa_foreign",
  520. "numa_interleave",
  521. "numa_local",
  522. "numa_other",
  523. #endif
  524. #ifdef CONFIG_VM_EVENT_COUNTERS
  525. "pgpgin",
  526. "pgpgout",
  527. "pswpin",
  528. "pswpout",
  529. TEXTS_FOR_ZONES("pgalloc")
  530. "pgfree",
  531. "pgactivate",
  532. "pgdeactivate",
  533. "pgfault",
  534. "pgmajfault",
  535. TEXTS_FOR_ZONES("pgrefill")
  536. TEXTS_FOR_ZONES("pgsteal")
  537. TEXTS_FOR_ZONES("pgscan_kswapd")
  538. TEXTS_FOR_ZONES("pgscan_direct")
  539. "pginodesteal",
  540. "slabs_scanned",
  541. "kswapd_steal",
  542. "kswapd_inodesteal",
  543. "pageoutrun",
  544. "allocstall",
  545. "pgrotated",
  546. #endif
  547. };
  548. static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
  549. struct zone *zone)
  550. {
  551. int i;
  552. seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name);
  553. seq_printf(m,
  554. "\n pages free %lu"
  555. "\n min %lu"
  556. "\n low %lu"
  557. "\n high %lu"
  558. "\n scanned %lu (a: %lu i: %lu)"
  559. "\n spanned %lu"
  560. "\n present %lu",
  561. zone_page_state(zone, NR_FREE_PAGES),
  562. zone->pages_min,
  563. zone->pages_low,
  564. zone->pages_high,
  565. zone->pages_scanned,
  566. zone->nr_scan_active, zone->nr_scan_inactive,
  567. zone->spanned_pages,
  568. zone->present_pages);
  569. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  570. seq_printf(m, "\n %-12s %lu", vmstat_text[i],
  571. zone_page_state(zone, i));
  572. seq_printf(m,
  573. "\n protection: (%lu",
  574. zone->lowmem_reserve[0]);
  575. for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++)
  576. seq_printf(m, ", %lu", zone->lowmem_reserve[i]);
  577. seq_printf(m,
  578. ")"
  579. "\n pagesets");
  580. for_each_online_cpu(i) {
  581. struct per_cpu_pageset *pageset;
  582. pageset = zone_pcp(zone, i);
  583. seq_printf(m,
  584. "\n cpu: %i"
  585. "\n count: %i"
  586. "\n high: %i"
  587. "\n batch: %i",
  588. i,
  589. pageset->pcp.count,
  590. pageset->pcp.high,
  591. pageset->pcp.batch);
  592. #ifdef CONFIG_SMP
  593. seq_printf(m, "\n vm stats threshold: %d",
  594. pageset->stat_threshold);
  595. #endif
  596. }
  597. seq_printf(m,
  598. "\n all_unreclaimable: %u"
  599. "\n prev_priority: %i"
  600. "\n start_pfn: %lu",
  601. zone_is_all_unreclaimable(zone),
  602. zone->prev_priority,
  603. zone->zone_start_pfn);
  604. seq_putc(m, '\n');
  605. }
  606. /*
  607. * Output information about zones in @pgdat.
  608. */
  609. static int zoneinfo_show(struct seq_file *m, void *arg)
  610. {
  611. pg_data_t *pgdat = (pg_data_t *)arg;
  612. walk_zones_in_node(m, pgdat, zoneinfo_show_print);
  613. return 0;
  614. }
  615. const struct seq_operations zoneinfo_op = {
  616. .start = frag_start, /* iterate over all zones. The same as in
  617. * fragmentation. */
  618. .next = frag_next,
  619. .stop = frag_stop,
  620. .show = zoneinfo_show,
  621. };
  622. static void *vmstat_start(struct seq_file *m, loff_t *pos)
  623. {
  624. unsigned long *v;
  625. #ifdef CONFIG_VM_EVENT_COUNTERS
  626. unsigned long *e;
  627. #endif
  628. int i;
  629. if (*pos >= ARRAY_SIZE(vmstat_text))
  630. return NULL;
  631. #ifdef CONFIG_VM_EVENT_COUNTERS
  632. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long)
  633. + sizeof(struct vm_event_state), GFP_KERNEL);
  634. #else
  635. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long),
  636. GFP_KERNEL);
  637. #endif
  638. m->private = v;
  639. if (!v)
  640. return ERR_PTR(-ENOMEM);
  641. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  642. v[i] = global_page_state(i);
  643. #ifdef CONFIG_VM_EVENT_COUNTERS
  644. e = v + NR_VM_ZONE_STAT_ITEMS;
  645. all_vm_events(e);
  646. e[PGPGIN] /= 2; /* sectors -> kbytes */
  647. e[PGPGOUT] /= 2;
  648. #endif
  649. return v + *pos;
  650. }
  651. static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
  652. {
  653. (*pos)++;
  654. if (*pos >= ARRAY_SIZE(vmstat_text))
  655. return NULL;
  656. return (unsigned long *)m->private + *pos;
  657. }
  658. static int vmstat_show(struct seq_file *m, void *arg)
  659. {
  660. unsigned long *l = arg;
  661. unsigned long off = l - (unsigned long *)m->private;
  662. seq_printf(m, "%s %lu\n", vmstat_text[off], *l);
  663. return 0;
  664. }
  665. static void vmstat_stop(struct seq_file *m, void *arg)
  666. {
  667. kfree(m->private);
  668. m->private = NULL;
  669. }
  670. const struct seq_operations vmstat_op = {
  671. .start = vmstat_start,
  672. .next = vmstat_next,
  673. .stop = vmstat_stop,
  674. .show = vmstat_show,
  675. };
  676. #endif /* CONFIG_PROC_FS */
  677. #ifdef CONFIG_SMP
  678. static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
  679. int sysctl_stat_interval __read_mostly = HZ;
  680. static void vmstat_update(struct work_struct *w)
  681. {
  682. refresh_cpu_vm_stats(smp_processor_id());
  683. schedule_delayed_work(&__get_cpu_var(vmstat_work),
  684. sysctl_stat_interval);
  685. }
  686. static void __cpuinit start_cpu_timer(int cpu)
  687. {
  688. struct delayed_work *vmstat_work = &per_cpu(vmstat_work, cpu);
  689. INIT_DELAYED_WORK_DEFERRABLE(vmstat_work, vmstat_update);
  690. schedule_delayed_work_on(cpu, vmstat_work, HZ + cpu);
  691. }
  692. /*
  693. * Use the cpu notifier to insure that the thresholds are recalculated
  694. * when necessary.
  695. */
  696. static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
  697. unsigned long action,
  698. void *hcpu)
  699. {
  700. long cpu = (long)hcpu;
  701. switch (action) {
  702. case CPU_ONLINE:
  703. case CPU_ONLINE_FROZEN:
  704. start_cpu_timer(cpu);
  705. break;
  706. case CPU_DOWN_PREPARE:
  707. case CPU_DOWN_PREPARE_FROZEN:
  708. cancel_rearming_delayed_work(&per_cpu(vmstat_work, cpu));
  709. per_cpu(vmstat_work, cpu).work.func = NULL;
  710. break;
  711. case CPU_DOWN_FAILED:
  712. case CPU_DOWN_FAILED_FROZEN:
  713. start_cpu_timer(cpu);
  714. break;
  715. case CPU_DEAD:
  716. case CPU_DEAD_FROZEN:
  717. refresh_zone_stat_thresholds();
  718. break;
  719. default:
  720. break;
  721. }
  722. return NOTIFY_OK;
  723. }
  724. static struct notifier_block __cpuinitdata vmstat_notifier =
  725. { &vmstat_cpuup_callback, NULL, 0 };
  726. static int __init setup_vmstat(void)
  727. {
  728. int cpu;
  729. refresh_zone_stat_thresholds();
  730. register_cpu_notifier(&vmstat_notifier);
  731. for_each_online_cpu(cpu)
  732. start_cpu_timer(cpu);
  733. return 0;
  734. }
  735. module_init(setup_vmstat)
  736. #endif