vmstat.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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. #ifdef CONFIG_ARCH_FLATMEM_HAS_HOLES
  438. /*
  439. * Ordinarily, memory holes in flatmem still have a valid
  440. * memmap for the PFN range. However, an architecture for
  441. * embedded systems (e.g. ARM) can free up the memmap backing
  442. * holes to save memory on the assumption the memmap is
  443. * never used. The page_zone linkages are then broken even
  444. * though pfn_valid() returns true. Skip the page if the
  445. * linkages are broken. Even if this test passed, the impact
  446. * is that the counters for the movable type are off but
  447. * fragmentation monitoring is likely meaningless on small
  448. * systems.
  449. */
  450. if (page_zone(page) != zone)
  451. continue;
  452. #endif
  453. mtype = get_pageblock_migratetype(page);
  454. if (mtype < MIGRATE_TYPES)
  455. count[mtype]++;
  456. }
  457. /* Print counts */
  458. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  459. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  460. seq_printf(m, "%12lu ", count[mtype]);
  461. seq_putc(m, '\n');
  462. }
  463. /* Print out the free pages at each order for each migratetype */
  464. static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg)
  465. {
  466. int mtype;
  467. pg_data_t *pgdat = (pg_data_t *)arg;
  468. seq_printf(m, "\n%-23s", "Number of blocks type ");
  469. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  470. seq_printf(m, "%12s ", migratetype_names[mtype]);
  471. seq_putc(m, '\n');
  472. walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print);
  473. return 0;
  474. }
  475. /*
  476. * This prints out statistics in relation to grouping pages by mobility.
  477. * It is expensive to collect so do not constantly read the file.
  478. */
  479. static int pagetypeinfo_show(struct seq_file *m, void *arg)
  480. {
  481. pg_data_t *pgdat = (pg_data_t *)arg;
  482. /* check memoryless node */
  483. if (!node_state(pgdat->node_id, N_HIGH_MEMORY))
  484. return 0;
  485. seq_printf(m, "Page block order: %d\n", pageblock_order);
  486. seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages);
  487. seq_putc(m, '\n');
  488. pagetypeinfo_showfree(m, pgdat);
  489. pagetypeinfo_showblockcount(m, pgdat);
  490. return 0;
  491. }
  492. const struct seq_operations fragmentation_op = {
  493. .start = frag_start,
  494. .next = frag_next,
  495. .stop = frag_stop,
  496. .show = frag_show,
  497. };
  498. const struct seq_operations pagetypeinfo_op = {
  499. .start = frag_start,
  500. .next = frag_next,
  501. .stop = frag_stop,
  502. .show = pagetypeinfo_show,
  503. };
  504. #ifdef CONFIG_ZONE_DMA
  505. #define TEXT_FOR_DMA(xx) xx "_dma",
  506. #else
  507. #define TEXT_FOR_DMA(xx)
  508. #endif
  509. #ifdef CONFIG_ZONE_DMA32
  510. #define TEXT_FOR_DMA32(xx) xx "_dma32",
  511. #else
  512. #define TEXT_FOR_DMA32(xx)
  513. #endif
  514. #ifdef CONFIG_HIGHMEM
  515. #define TEXT_FOR_HIGHMEM(xx) xx "_high",
  516. #else
  517. #define TEXT_FOR_HIGHMEM(xx)
  518. #endif
  519. #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \
  520. TEXT_FOR_HIGHMEM(xx) xx "_movable",
  521. static const char * const vmstat_text[] = {
  522. /* Zoned VM counters */
  523. "nr_free_pages",
  524. "nr_inactive",
  525. "nr_active",
  526. "nr_anon_pages",
  527. "nr_mapped",
  528. "nr_file_pages",
  529. "nr_dirty",
  530. "nr_writeback",
  531. "nr_slab_reclaimable",
  532. "nr_slab_unreclaimable",
  533. "nr_page_table_pages",
  534. "nr_unstable",
  535. "nr_bounce",
  536. "nr_vmscan_write",
  537. "nr_writeback_temp",
  538. #ifdef CONFIG_NUMA
  539. "numa_hit",
  540. "numa_miss",
  541. "numa_foreign",
  542. "numa_interleave",
  543. "numa_local",
  544. "numa_other",
  545. #endif
  546. #ifdef CONFIG_VM_EVENT_COUNTERS
  547. "pgpgin",
  548. "pgpgout",
  549. "pswpin",
  550. "pswpout",
  551. TEXTS_FOR_ZONES("pgalloc")
  552. "pgfree",
  553. "pgactivate",
  554. "pgdeactivate",
  555. "pgfault",
  556. "pgmajfault",
  557. TEXTS_FOR_ZONES("pgrefill")
  558. TEXTS_FOR_ZONES("pgsteal")
  559. TEXTS_FOR_ZONES("pgscan_kswapd")
  560. TEXTS_FOR_ZONES("pgscan_direct")
  561. "pginodesteal",
  562. "slabs_scanned",
  563. "kswapd_steal",
  564. "kswapd_inodesteal",
  565. "pageoutrun",
  566. "allocstall",
  567. "pgrotated",
  568. #ifdef CONFIG_HUGETLB_PAGE
  569. "htlb_buddy_alloc_success",
  570. "htlb_buddy_alloc_fail",
  571. #endif
  572. #endif
  573. };
  574. static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
  575. struct zone *zone)
  576. {
  577. int i;
  578. seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name);
  579. seq_printf(m,
  580. "\n pages free %lu"
  581. "\n min %lu"
  582. "\n low %lu"
  583. "\n high %lu"
  584. "\n scanned %lu (a: %lu i: %lu)"
  585. "\n spanned %lu"
  586. "\n present %lu",
  587. zone_page_state(zone, NR_FREE_PAGES),
  588. zone->pages_min,
  589. zone->pages_low,
  590. zone->pages_high,
  591. zone->pages_scanned,
  592. zone->nr_scan_active, zone->nr_scan_inactive,
  593. zone->spanned_pages,
  594. zone->present_pages);
  595. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  596. seq_printf(m, "\n %-12s %lu", vmstat_text[i],
  597. zone_page_state(zone, i));
  598. seq_printf(m,
  599. "\n protection: (%lu",
  600. zone->lowmem_reserve[0]);
  601. for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++)
  602. seq_printf(m, ", %lu", zone->lowmem_reserve[i]);
  603. seq_printf(m,
  604. ")"
  605. "\n pagesets");
  606. for_each_online_cpu(i) {
  607. struct per_cpu_pageset *pageset;
  608. pageset = zone_pcp(zone, i);
  609. seq_printf(m,
  610. "\n cpu: %i"
  611. "\n count: %i"
  612. "\n high: %i"
  613. "\n batch: %i",
  614. i,
  615. pageset->pcp.count,
  616. pageset->pcp.high,
  617. pageset->pcp.batch);
  618. #ifdef CONFIG_SMP
  619. seq_printf(m, "\n vm stats threshold: %d",
  620. pageset->stat_threshold);
  621. #endif
  622. }
  623. seq_printf(m,
  624. "\n all_unreclaimable: %u"
  625. "\n prev_priority: %i"
  626. "\n start_pfn: %lu",
  627. zone_is_all_unreclaimable(zone),
  628. zone->prev_priority,
  629. zone->zone_start_pfn);
  630. seq_putc(m, '\n');
  631. }
  632. /*
  633. * Output information about zones in @pgdat.
  634. */
  635. static int zoneinfo_show(struct seq_file *m, void *arg)
  636. {
  637. pg_data_t *pgdat = (pg_data_t *)arg;
  638. walk_zones_in_node(m, pgdat, zoneinfo_show_print);
  639. return 0;
  640. }
  641. const struct seq_operations zoneinfo_op = {
  642. .start = frag_start, /* iterate over all zones. The same as in
  643. * fragmentation. */
  644. .next = frag_next,
  645. .stop = frag_stop,
  646. .show = zoneinfo_show,
  647. };
  648. static void *vmstat_start(struct seq_file *m, loff_t *pos)
  649. {
  650. unsigned long *v;
  651. #ifdef CONFIG_VM_EVENT_COUNTERS
  652. unsigned long *e;
  653. #endif
  654. int i;
  655. if (*pos >= ARRAY_SIZE(vmstat_text))
  656. return NULL;
  657. #ifdef CONFIG_VM_EVENT_COUNTERS
  658. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long)
  659. + sizeof(struct vm_event_state), GFP_KERNEL);
  660. #else
  661. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long),
  662. GFP_KERNEL);
  663. #endif
  664. m->private = v;
  665. if (!v)
  666. return ERR_PTR(-ENOMEM);
  667. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  668. v[i] = global_page_state(i);
  669. #ifdef CONFIG_VM_EVENT_COUNTERS
  670. e = v + NR_VM_ZONE_STAT_ITEMS;
  671. all_vm_events(e);
  672. e[PGPGIN] /= 2; /* sectors -> kbytes */
  673. e[PGPGOUT] /= 2;
  674. #endif
  675. return v + *pos;
  676. }
  677. static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
  678. {
  679. (*pos)++;
  680. if (*pos >= ARRAY_SIZE(vmstat_text))
  681. return NULL;
  682. return (unsigned long *)m->private + *pos;
  683. }
  684. static int vmstat_show(struct seq_file *m, void *arg)
  685. {
  686. unsigned long *l = arg;
  687. unsigned long off = l - (unsigned long *)m->private;
  688. seq_printf(m, "%s %lu\n", vmstat_text[off], *l);
  689. return 0;
  690. }
  691. static void vmstat_stop(struct seq_file *m, void *arg)
  692. {
  693. kfree(m->private);
  694. m->private = NULL;
  695. }
  696. const struct seq_operations vmstat_op = {
  697. .start = vmstat_start,
  698. .next = vmstat_next,
  699. .stop = vmstat_stop,
  700. .show = vmstat_show,
  701. };
  702. #endif /* CONFIG_PROC_FS */
  703. #ifdef CONFIG_SMP
  704. static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
  705. int sysctl_stat_interval __read_mostly = HZ;
  706. static void vmstat_update(struct work_struct *w)
  707. {
  708. refresh_cpu_vm_stats(smp_processor_id());
  709. schedule_delayed_work(&__get_cpu_var(vmstat_work),
  710. sysctl_stat_interval);
  711. }
  712. static void __cpuinit start_cpu_timer(int cpu)
  713. {
  714. struct delayed_work *vmstat_work = &per_cpu(vmstat_work, cpu);
  715. INIT_DELAYED_WORK_DEFERRABLE(vmstat_work, vmstat_update);
  716. schedule_delayed_work_on(cpu, vmstat_work, HZ + cpu);
  717. }
  718. /*
  719. * Use the cpu notifier to insure that the thresholds are recalculated
  720. * when necessary.
  721. */
  722. static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
  723. unsigned long action,
  724. void *hcpu)
  725. {
  726. long cpu = (long)hcpu;
  727. switch (action) {
  728. case CPU_ONLINE:
  729. case CPU_ONLINE_FROZEN:
  730. start_cpu_timer(cpu);
  731. break;
  732. case CPU_DOWN_PREPARE:
  733. case CPU_DOWN_PREPARE_FROZEN:
  734. cancel_rearming_delayed_work(&per_cpu(vmstat_work, cpu));
  735. per_cpu(vmstat_work, cpu).work.func = NULL;
  736. break;
  737. case CPU_DOWN_FAILED:
  738. case CPU_DOWN_FAILED_FROZEN:
  739. start_cpu_timer(cpu);
  740. break;
  741. case CPU_DEAD:
  742. case CPU_DEAD_FROZEN:
  743. refresh_zone_stat_thresholds();
  744. break;
  745. default:
  746. break;
  747. }
  748. return NOTIFY_OK;
  749. }
  750. static struct notifier_block __cpuinitdata vmstat_notifier =
  751. { &vmstat_cpuup_callback, NULL, 0 };
  752. static int __init setup_vmstat(void)
  753. {
  754. int cpu;
  755. refresh_zone_stat_thresholds();
  756. register_cpu_notifier(&vmstat_notifier);
  757. for_each_online_cpu(cpu)
  758. start_cpu_timer(cpu);
  759. return 0;
  760. }
  761. module_init(setup_vmstat)
  762. #endif