vmstat.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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/fs.h>
  12. #include <linux/mm.h>
  13. #include <linux/err.h>
  14. #include <linux/module.h>
  15. #include <linux/cpu.h>
  16. #include <linux/vmstat.h>
  17. #include <linux/sched.h>
  18. #ifdef CONFIG_VM_EVENT_COUNTERS
  19. DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}};
  20. EXPORT_PER_CPU_SYMBOL(vm_event_states);
  21. static void sum_vm_events(unsigned long *ret, const struct cpumask *cpumask)
  22. {
  23. int cpu;
  24. int i;
  25. memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long));
  26. for_each_cpu(cpu, cpumask) {
  27. struct vm_event_state *this = &per_cpu(vm_event_states, cpu);
  28. for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
  29. ret[i] += this->event[i];
  30. }
  31. }
  32. /*
  33. * Accumulate the vm event counters across all CPUs.
  34. * The result is unavoidably approximate - it can change
  35. * during and after execution of this function.
  36. */
  37. void all_vm_events(unsigned long *ret)
  38. {
  39. get_online_cpus();
  40. sum_vm_events(ret, cpu_online_mask);
  41. put_online_cpus();
  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_populated_zone(zone) {
  120. threshold = calculate_threshold(zone);
  121. for_each_online_cpu(cpu)
  122. zone_pcp(zone, cpu)->stat_threshold = threshold;
  123. }
  124. }
  125. /*
  126. * For use when we know that interrupts are disabled.
  127. */
  128. void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
  129. int delta)
  130. {
  131. struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
  132. s8 *p = pcp->vm_stat_diff + item;
  133. long x;
  134. x = delta + *p;
  135. if (unlikely(x > pcp->stat_threshold || x < -pcp->stat_threshold)) {
  136. zone_page_state_add(x, zone, item);
  137. x = 0;
  138. }
  139. *p = x;
  140. }
  141. EXPORT_SYMBOL(__mod_zone_page_state);
  142. /*
  143. * For an unknown interrupt state
  144. */
  145. void mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
  146. int delta)
  147. {
  148. unsigned long flags;
  149. local_irq_save(flags);
  150. __mod_zone_page_state(zone, item, delta);
  151. local_irq_restore(flags);
  152. }
  153. EXPORT_SYMBOL(mod_zone_page_state);
  154. /*
  155. * Optimized increment and decrement functions.
  156. *
  157. * These are only for a single page and therefore can take a struct page *
  158. * argument instead of struct zone *. This allows the inclusion of the code
  159. * generated for page_zone(page) into the optimized functions.
  160. *
  161. * No overflow check is necessary and therefore the differential can be
  162. * incremented or decremented in place which may allow the compilers to
  163. * generate better code.
  164. * The increment or decrement is known and therefore one boundary check can
  165. * be omitted.
  166. *
  167. * NOTE: These functions are very performance sensitive. Change only
  168. * with care.
  169. *
  170. * Some processors have inc/dec instructions that are atomic vs an interrupt.
  171. * However, the code must first determine the differential location in a zone
  172. * based on the processor number and then inc/dec the counter. There is no
  173. * guarantee without disabling preemption that the processor will not change
  174. * in between and therefore the atomicity vs. interrupt cannot be exploited
  175. * in a useful way here.
  176. */
  177. void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
  178. {
  179. struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
  180. s8 *p = pcp->vm_stat_diff + item;
  181. (*p)++;
  182. if (unlikely(*p > pcp->stat_threshold)) {
  183. int overstep = pcp->stat_threshold / 2;
  184. zone_page_state_add(*p + overstep, zone, item);
  185. *p = -overstep;
  186. }
  187. }
  188. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  189. {
  190. __inc_zone_state(page_zone(page), item);
  191. }
  192. EXPORT_SYMBOL(__inc_zone_page_state);
  193. void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
  194. {
  195. struct per_cpu_pageset *pcp = zone_pcp(zone, smp_processor_id());
  196. s8 *p = pcp->vm_stat_diff + item;
  197. (*p)--;
  198. if (unlikely(*p < - pcp->stat_threshold)) {
  199. int overstep = pcp->stat_threshold / 2;
  200. zone_page_state_add(*p - overstep, zone, item);
  201. *p = overstep;
  202. }
  203. }
  204. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  205. {
  206. __dec_zone_state(page_zone(page), item);
  207. }
  208. EXPORT_SYMBOL(__dec_zone_page_state);
  209. void inc_zone_state(struct zone *zone, enum zone_stat_item item)
  210. {
  211. unsigned long flags;
  212. local_irq_save(flags);
  213. __inc_zone_state(zone, item);
  214. local_irq_restore(flags);
  215. }
  216. void inc_zone_page_state(struct page *page, enum zone_stat_item item)
  217. {
  218. unsigned long flags;
  219. struct zone *zone;
  220. zone = page_zone(page);
  221. local_irq_save(flags);
  222. __inc_zone_state(zone, item);
  223. local_irq_restore(flags);
  224. }
  225. EXPORT_SYMBOL(inc_zone_page_state);
  226. void dec_zone_page_state(struct page *page, enum zone_stat_item item)
  227. {
  228. unsigned long flags;
  229. local_irq_save(flags);
  230. __dec_zone_page_state(page, item);
  231. local_irq_restore(flags);
  232. }
  233. EXPORT_SYMBOL(dec_zone_page_state);
  234. /*
  235. * Update the zone counters for one cpu.
  236. *
  237. * The cpu specified must be either the current cpu or a processor that
  238. * is not online. If it is the current cpu then the execution thread must
  239. * be pinned to the current cpu.
  240. *
  241. * Note that refresh_cpu_vm_stats strives to only access
  242. * node local memory. The per cpu pagesets on remote zones are placed
  243. * in the memory local to the processor using that pageset. So the
  244. * loop over all zones will access a series of cachelines local to
  245. * the processor.
  246. *
  247. * The call to zone_page_state_add updates the cachelines with the
  248. * statistics in the remote zone struct as well as the global cachelines
  249. * with the global counters. These could cause remote node cache line
  250. * bouncing and will have to be only done when necessary.
  251. */
  252. void refresh_cpu_vm_stats(int cpu)
  253. {
  254. struct zone *zone;
  255. int i;
  256. int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, };
  257. for_each_populated_zone(zone) {
  258. struct per_cpu_pageset *p;
  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/proc_fs.h>
  328. #include <linux/seq_file.h>
  329. static char * const migratetype_names[MIGRATE_TYPES] = {
  330. "Unmovable",
  331. "Reclaimable",
  332. "Movable",
  333. "Reserve",
  334. "Isolate",
  335. };
  336. static void *frag_start(struct seq_file *m, loff_t *pos)
  337. {
  338. pg_data_t *pgdat;
  339. loff_t node = *pos;
  340. for (pgdat = first_online_pgdat();
  341. pgdat && node;
  342. pgdat = next_online_pgdat(pgdat))
  343. --node;
  344. return pgdat;
  345. }
  346. static void *frag_next(struct seq_file *m, void *arg, loff_t *pos)
  347. {
  348. pg_data_t *pgdat = (pg_data_t *)arg;
  349. (*pos)++;
  350. return next_online_pgdat(pgdat);
  351. }
  352. static void frag_stop(struct seq_file *m, void *arg)
  353. {
  354. }
  355. /* Walk all the zones in a node and print using a callback */
  356. static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat,
  357. void (*print)(struct seq_file *m, pg_data_t *, struct zone *))
  358. {
  359. struct zone *zone;
  360. struct zone *node_zones = pgdat->node_zones;
  361. unsigned long flags;
  362. for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
  363. if (!populated_zone(zone))
  364. continue;
  365. spin_lock_irqsave(&zone->lock, flags);
  366. print(m, pgdat, zone);
  367. spin_unlock_irqrestore(&zone->lock, flags);
  368. }
  369. }
  370. static void frag_show_print(struct seq_file *m, pg_data_t *pgdat,
  371. struct zone *zone)
  372. {
  373. int order;
  374. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  375. for (order = 0; order < MAX_ORDER; ++order)
  376. seq_printf(m, "%6lu ", zone->free_area[order].nr_free);
  377. seq_putc(m, '\n');
  378. }
  379. /*
  380. * This walks the free areas for each zone.
  381. */
  382. static int frag_show(struct seq_file *m, void *arg)
  383. {
  384. pg_data_t *pgdat = (pg_data_t *)arg;
  385. walk_zones_in_node(m, pgdat, frag_show_print);
  386. return 0;
  387. }
  388. static void pagetypeinfo_showfree_print(struct seq_file *m,
  389. pg_data_t *pgdat, struct zone *zone)
  390. {
  391. int order, mtype;
  392. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) {
  393. seq_printf(m, "Node %4d, zone %8s, type %12s ",
  394. pgdat->node_id,
  395. zone->name,
  396. migratetype_names[mtype]);
  397. for (order = 0; order < MAX_ORDER; ++order) {
  398. unsigned long freecount = 0;
  399. struct free_area *area;
  400. struct list_head *curr;
  401. area = &(zone->free_area[order]);
  402. list_for_each(curr, &area->free_list[mtype])
  403. freecount++;
  404. seq_printf(m, "%6lu ", freecount);
  405. }
  406. seq_putc(m, '\n');
  407. }
  408. }
  409. /* Print out the free pages at each order for each migatetype */
  410. static int pagetypeinfo_showfree(struct seq_file *m, void *arg)
  411. {
  412. int order;
  413. pg_data_t *pgdat = (pg_data_t *)arg;
  414. /* Print header */
  415. seq_printf(m, "%-43s ", "Free pages count per migrate type at order");
  416. for (order = 0; order < MAX_ORDER; ++order)
  417. seq_printf(m, "%6d ", order);
  418. seq_putc(m, '\n');
  419. walk_zones_in_node(m, pgdat, pagetypeinfo_showfree_print);
  420. return 0;
  421. }
  422. static void pagetypeinfo_showblockcount_print(struct seq_file *m,
  423. pg_data_t *pgdat, struct zone *zone)
  424. {
  425. int mtype;
  426. unsigned long pfn;
  427. unsigned long start_pfn = zone->zone_start_pfn;
  428. unsigned long end_pfn = start_pfn + zone->spanned_pages;
  429. unsigned long count[MIGRATE_TYPES] = { 0, };
  430. for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
  431. struct page *page;
  432. if (!pfn_valid(pfn))
  433. continue;
  434. page = pfn_to_page(pfn);
  435. #ifdef CONFIG_ARCH_FLATMEM_HAS_HOLES
  436. /*
  437. * Ordinarily, memory holes in flatmem still have a valid
  438. * memmap for the PFN range. However, an architecture for
  439. * embedded systems (e.g. ARM) can free up the memmap backing
  440. * holes to save memory on the assumption the memmap is
  441. * never used. The page_zone linkages are then broken even
  442. * though pfn_valid() returns true. Skip the page if the
  443. * linkages are broken. Even if this test passed, the impact
  444. * is that the counters for the movable type are off but
  445. * fragmentation monitoring is likely meaningless on small
  446. * systems.
  447. */
  448. if (page_zone(page) != zone)
  449. continue;
  450. #endif
  451. mtype = get_pageblock_migratetype(page);
  452. if (mtype < MIGRATE_TYPES)
  453. count[mtype]++;
  454. }
  455. /* Print counts */
  456. seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name);
  457. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  458. seq_printf(m, "%12lu ", count[mtype]);
  459. seq_putc(m, '\n');
  460. }
  461. /* Print out the free pages at each order for each migratetype */
  462. static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg)
  463. {
  464. int mtype;
  465. pg_data_t *pgdat = (pg_data_t *)arg;
  466. seq_printf(m, "\n%-23s", "Number of blocks type ");
  467. for (mtype = 0; mtype < MIGRATE_TYPES; mtype++)
  468. seq_printf(m, "%12s ", migratetype_names[mtype]);
  469. seq_putc(m, '\n');
  470. walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print);
  471. return 0;
  472. }
  473. /*
  474. * This prints out statistics in relation to grouping pages by mobility.
  475. * It is expensive to collect so do not constantly read the file.
  476. */
  477. static int pagetypeinfo_show(struct seq_file *m, void *arg)
  478. {
  479. pg_data_t *pgdat = (pg_data_t *)arg;
  480. /* check memoryless node */
  481. if (!node_state(pgdat->node_id, N_HIGH_MEMORY))
  482. return 0;
  483. seq_printf(m, "Page block order: %d\n", pageblock_order);
  484. seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages);
  485. seq_putc(m, '\n');
  486. pagetypeinfo_showfree(m, pgdat);
  487. pagetypeinfo_showblockcount(m, pgdat);
  488. return 0;
  489. }
  490. static const struct seq_operations fragmentation_op = {
  491. .start = frag_start,
  492. .next = frag_next,
  493. .stop = frag_stop,
  494. .show = frag_show,
  495. };
  496. static int fragmentation_open(struct inode *inode, struct file *file)
  497. {
  498. return seq_open(file, &fragmentation_op);
  499. }
  500. static const struct file_operations fragmentation_file_operations = {
  501. .open = fragmentation_open,
  502. .read = seq_read,
  503. .llseek = seq_lseek,
  504. .release = seq_release,
  505. };
  506. static const struct seq_operations pagetypeinfo_op = {
  507. .start = frag_start,
  508. .next = frag_next,
  509. .stop = frag_stop,
  510. .show = pagetypeinfo_show,
  511. };
  512. static int pagetypeinfo_open(struct inode *inode, struct file *file)
  513. {
  514. return seq_open(file, &pagetypeinfo_op);
  515. }
  516. static const struct file_operations pagetypeinfo_file_ops = {
  517. .open = pagetypeinfo_open,
  518. .read = seq_read,
  519. .llseek = seq_lseek,
  520. .release = seq_release,
  521. };
  522. #ifdef CONFIG_ZONE_DMA
  523. #define TEXT_FOR_DMA(xx) xx "_dma",
  524. #else
  525. #define TEXT_FOR_DMA(xx)
  526. #endif
  527. #ifdef CONFIG_ZONE_DMA32
  528. #define TEXT_FOR_DMA32(xx) xx "_dma32",
  529. #else
  530. #define TEXT_FOR_DMA32(xx)
  531. #endif
  532. #ifdef CONFIG_HIGHMEM
  533. #define TEXT_FOR_HIGHMEM(xx) xx "_high",
  534. #else
  535. #define TEXT_FOR_HIGHMEM(xx)
  536. #endif
  537. #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \
  538. TEXT_FOR_HIGHMEM(xx) xx "_movable",
  539. static const char * const vmstat_text[] = {
  540. /* Zoned VM counters */
  541. "nr_free_pages",
  542. "nr_inactive_anon",
  543. "nr_active_anon",
  544. "nr_inactive_file",
  545. "nr_active_file",
  546. #ifdef CONFIG_UNEVICTABLE_LRU
  547. "nr_unevictable",
  548. "nr_mlock",
  549. #endif
  550. "nr_anon_pages",
  551. "nr_mapped",
  552. "nr_file_pages",
  553. "nr_dirty",
  554. "nr_writeback",
  555. "nr_slab_reclaimable",
  556. "nr_slab_unreclaimable",
  557. "nr_page_table_pages",
  558. "nr_unstable",
  559. "nr_bounce",
  560. "nr_vmscan_write",
  561. "nr_writeback_temp",
  562. #ifdef CONFIG_NUMA
  563. "numa_hit",
  564. "numa_miss",
  565. "numa_foreign",
  566. "numa_interleave",
  567. "numa_local",
  568. "numa_other",
  569. #endif
  570. #ifdef CONFIG_VM_EVENT_COUNTERS
  571. "pgpgin",
  572. "pgpgout",
  573. "pswpin",
  574. "pswpout",
  575. TEXTS_FOR_ZONES("pgalloc")
  576. "pgfree",
  577. "pgactivate",
  578. "pgdeactivate",
  579. "pgfault",
  580. "pgmajfault",
  581. TEXTS_FOR_ZONES("pgrefill")
  582. TEXTS_FOR_ZONES("pgsteal")
  583. TEXTS_FOR_ZONES("pgscan_kswapd")
  584. TEXTS_FOR_ZONES("pgscan_direct")
  585. "pginodesteal",
  586. "slabs_scanned",
  587. "kswapd_steal",
  588. "kswapd_inodesteal",
  589. "pageoutrun",
  590. "allocstall",
  591. "pgrotated",
  592. #ifdef CONFIG_HUGETLB_PAGE
  593. "htlb_buddy_alloc_success",
  594. "htlb_buddy_alloc_fail",
  595. #endif
  596. #ifdef CONFIG_UNEVICTABLE_LRU
  597. "unevictable_pgs_culled",
  598. "unevictable_pgs_scanned",
  599. "unevictable_pgs_rescued",
  600. "unevictable_pgs_mlocked",
  601. "unevictable_pgs_munlocked",
  602. "unevictable_pgs_cleared",
  603. "unevictable_pgs_stranded",
  604. "unevictable_pgs_mlockfreed",
  605. #endif
  606. #endif
  607. };
  608. static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat,
  609. struct zone *zone)
  610. {
  611. int i;
  612. seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name);
  613. seq_printf(m,
  614. "\n pages free %lu"
  615. "\n min %lu"
  616. "\n low %lu"
  617. "\n high %lu"
  618. "\n scanned %lu (aa: %lu ia: %lu af: %lu if: %lu)"
  619. "\n spanned %lu"
  620. "\n present %lu",
  621. zone_page_state(zone, NR_FREE_PAGES),
  622. zone->pages_min,
  623. zone->pages_low,
  624. zone->pages_high,
  625. zone->pages_scanned,
  626. zone->lru[LRU_ACTIVE_ANON].nr_scan,
  627. zone->lru[LRU_INACTIVE_ANON].nr_scan,
  628. zone->lru[LRU_ACTIVE_FILE].nr_scan,
  629. zone->lru[LRU_INACTIVE_FILE].nr_scan,
  630. zone->spanned_pages,
  631. zone->present_pages);
  632. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  633. seq_printf(m, "\n %-12s %lu", vmstat_text[i],
  634. zone_page_state(zone, i));
  635. seq_printf(m,
  636. "\n protection: (%lu",
  637. zone->lowmem_reserve[0]);
  638. for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++)
  639. seq_printf(m, ", %lu", zone->lowmem_reserve[i]);
  640. seq_printf(m,
  641. ")"
  642. "\n pagesets");
  643. for_each_online_cpu(i) {
  644. struct per_cpu_pageset *pageset;
  645. pageset = zone_pcp(zone, i);
  646. seq_printf(m,
  647. "\n cpu: %i"
  648. "\n count: %i"
  649. "\n high: %i"
  650. "\n batch: %i",
  651. i,
  652. pageset->pcp.count,
  653. pageset->pcp.high,
  654. pageset->pcp.batch);
  655. #ifdef CONFIG_SMP
  656. seq_printf(m, "\n vm stats threshold: %d",
  657. pageset->stat_threshold);
  658. #endif
  659. }
  660. seq_printf(m,
  661. "\n all_unreclaimable: %u"
  662. "\n prev_priority: %i"
  663. "\n start_pfn: %lu"
  664. "\n inactive_ratio: %u",
  665. zone_is_all_unreclaimable(zone),
  666. zone->prev_priority,
  667. zone->zone_start_pfn,
  668. zone->inactive_ratio);
  669. seq_putc(m, '\n');
  670. }
  671. /*
  672. * Output information about zones in @pgdat.
  673. */
  674. static int zoneinfo_show(struct seq_file *m, void *arg)
  675. {
  676. pg_data_t *pgdat = (pg_data_t *)arg;
  677. walk_zones_in_node(m, pgdat, zoneinfo_show_print);
  678. return 0;
  679. }
  680. static const struct seq_operations zoneinfo_op = {
  681. .start = frag_start, /* iterate over all zones. The same as in
  682. * fragmentation. */
  683. .next = frag_next,
  684. .stop = frag_stop,
  685. .show = zoneinfo_show,
  686. };
  687. static int zoneinfo_open(struct inode *inode, struct file *file)
  688. {
  689. return seq_open(file, &zoneinfo_op);
  690. }
  691. static const struct file_operations proc_zoneinfo_file_operations = {
  692. .open = zoneinfo_open,
  693. .read = seq_read,
  694. .llseek = seq_lseek,
  695. .release = seq_release,
  696. };
  697. static void *vmstat_start(struct seq_file *m, loff_t *pos)
  698. {
  699. unsigned long *v;
  700. #ifdef CONFIG_VM_EVENT_COUNTERS
  701. unsigned long *e;
  702. #endif
  703. int i;
  704. if (*pos >= ARRAY_SIZE(vmstat_text))
  705. return NULL;
  706. #ifdef CONFIG_VM_EVENT_COUNTERS
  707. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long)
  708. + sizeof(struct vm_event_state), GFP_KERNEL);
  709. #else
  710. v = kmalloc(NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long),
  711. GFP_KERNEL);
  712. #endif
  713. m->private = v;
  714. if (!v)
  715. return ERR_PTR(-ENOMEM);
  716. for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
  717. v[i] = global_page_state(i);
  718. #ifdef CONFIG_VM_EVENT_COUNTERS
  719. e = v + NR_VM_ZONE_STAT_ITEMS;
  720. all_vm_events(e);
  721. e[PGPGIN] /= 2; /* sectors -> kbytes */
  722. e[PGPGOUT] /= 2;
  723. #endif
  724. return v + *pos;
  725. }
  726. static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos)
  727. {
  728. (*pos)++;
  729. if (*pos >= ARRAY_SIZE(vmstat_text))
  730. return NULL;
  731. return (unsigned long *)m->private + *pos;
  732. }
  733. static int vmstat_show(struct seq_file *m, void *arg)
  734. {
  735. unsigned long *l = arg;
  736. unsigned long off = l - (unsigned long *)m->private;
  737. seq_printf(m, "%s %lu\n", vmstat_text[off], *l);
  738. return 0;
  739. }
  740. static void vmstat_stop(struct seq_file *m, void *arg)
  741. {
  742. kfree(m->private);
  743. m->private = NULL;
  744. }
  745. static const struct seq_operations vmstat_op = {
  746. .start = vmstat_start,
  747. .next = vmstat_next,
  748. .stop = vmstat_stop,
  749. .show = vmstat_show,
  750. };
  751. static int vmstat_open(struct inode *inode, struct file *file)
  752. {
  753. return seq_open(file, &vmstat_op);
  754. }
  755. static const struct file_operations proc_vmstat_file_operations = {
  756. .open = vmstat_open,
  757. .read = seq_read,
  758. .llseek = seq_lseek,
  759. .release = seq_release,
  760. };
  761. #endif /* CONFIG_PROC_FS */
  762. #ifdef CONFIG_SMP
  763. static DEFINE_PER_CPU(struct delayed_work, vmstat_work);
  764. int sysctl_stat_interval __read_mostly = HZ;
  765. static void vmstat_update(struct work_struct *w)
  766. {
  767. refresh_cpu_vm_stats(smp_processor_id());
  768. schedule_delayed_work(&__get_cpu_var(vmstat_work),
  769. round_jiffies_relative(sysctl_stat_interval));
  770. }
  771. static void __cpuinit start_cpu_timer(int cpu)
  772. {
  773. struct delayed_work *vmstat_work = &per_cpu(vmstat_work, cpu);
  774. INIT_DELAYED_WORK_DEFERRABLE(vmstat_work, vmstat_update);
  775. schedule_delayed_work_on(cpu, vmstat_work,
  776. __round_jiffies_relative(HZ, cpu));
  777. }
  778. /*
  779. * Use the cpu notifier to insure that the thresholds are recalculated
  780. * when necessary.
  781. */
  782. static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
  783. unsigned long action,
  784. void *hcpu)
  785. {
  786. long cpu = (long)hcpu;
  787. switch (action) {
  788. case CPU_ONLINE:
  789. case CPU_ONLINE_FROZEN:
  790. start_cpu_timer(cpu);
  791. break;
  792. case CPU_DOWN_PREPARE:
  793. case CPU_DOWN_PREPARE_FROZEN:
  794. cancel_rearming_delayed_work(&per_cpu(vmstat_work, cpu));
  795. per_cpu(vmstat_work, cpu).work.func = NULL;
  796. break;
  797. case CPU_DOWN_FAILED:
  798. case CPU_DOWN_FAILED_FROZEN:
  799. start_cpu_timer(cpu);
  800. break;
  801. case CPU_DEAD:
  802. case CPU_DEAD_FROZEN:
  803. refresh_zone_stat_thresholds();
  804. break;
  805. default:
  806. break;
  807. }
  808. return NOTIFY_OK;
  809. }
  810. static struct notifier_block __cpuinitdata vmstat_notifier =
  811. { &vmstat_cpuup_callback, NULL, 0 };
  812. #endif
  813. static int __init setup_vmstat(void)
  814. {
  815. #ifdef CONFIG_SMP
  816. int cpu;
  817. refresh_zone_stat_thresholds();
  818. register_cpu_notifier(&vmstat_notifier);
  819. for_each_online_cpu(cpu)
  820. start_cpu_timer(cpu);
  821. #endif
  822. #ifdef CONFIG_PROC_FS
  823. proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
  824. proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
  825. proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
  826. proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
  827. #endif
  828. return 0;
  829. }
  830. module_init(setup_vmstat)