vmstat.c 20 KB

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