vmstat.c 20 KB

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