14 #include <linux/module.h>
15 #include <linux/slab.h>
18 #include <linux/sched.h>
23 #ifdef CONFIG_VM_EVENT_COUNTERS
27 static void sum_vm_events(
unsigned long *
ret)
35 struct vm_event_state *
this = &
per_cpu(vm_event_states, cpu);
38 ret[i] += this->
event[i];
47 void all_vm_events(
unsigned long *ret)
62 void vm_events_fold_cpu(
int cpu)
64 struct vm_event_state *fold_state = &
per_cpu(vm_event_states, cpu);
68 count_vm_events(i, fold_state->event[i]);
69 fold_state->event[
i] = 0;
86 int calculate_pressure_threshold(
struct zone *
zone)
89 int watermark_distance;
105 threshold =
min(125, threshold);
110 int calculate_normal_threshold(
struct zone *zone)
152 threshold =
min(125, threshold);
160 void refresh_zone_stat_thresholds(
void)
167 unsigned long max_drift, tolerate_drift;
169 threshold = calculate_normal_threshold(zone);
182 if (max_drift > tolerate_drift)
189 int (*calculate_pressure)(
struct zone *))
196 for (i = 0; i < pgdat->nr_zones; i++) {
197 zone = &pgdat->node_zones[
i];
201 threshold = (*calculate_pressure)(zone);
224 zone_page_state_add(x, zone, item);
254 void __inc_zone_state(
struct zone *zone,
enum zone_stat_item item)
263 s8 overstep = t >> 1;
265 zone_page_state_add(v + overstep, zone, item);
272 __inc_zone_state(page_zone(page), item);
276 void __dec_zone_state(
struct zone *zone,
enum zone_stat_item item)
285 s8 overstep = t >> 1;
287 zone_page_state_add(v - overstep, zone, item);
292 void __dec_zone_page_state(
struct page *page,
enum zone_stat_item item)
294 __dec_zone_state(page_zone(page), item);
298 #ifdef CONFIG_HAVE_CMPXCHG_LOCAL
311 static inline void mod_state(
struct zone *zone,
336 if (n > t || n < -t) {
337 int os = overstep_mode * (t >> 1) ;
346 zone_page_state_add(z, zone, item);
352 mod_state(zone, item, delta, 0);
358 mod_state(zone, item, 1, 1);
363 mod_state(page_zone(page), item, 1, 1);
369 mod_state(page_zone(page), item, -1, -1);
382 __mod_zone_page_state(zone, item, delta);
392 __inc_zone_state(zone, item);
401 zone = page_zone(page);
403 __inc_zone_state(zone, item);
413 __dec_zone_page_state(page, item);
437 void refresh_cpu_vm_stats(
int cpu)
449 if (p->vm_stat_diff[i]) {
454 v = p->vm_stat_diff[
i];
455 p->vm_stat_diff[
i] = 0;
457 atomic_long_add(v, &zone->
vm_stat[i]);
473 if (!p->expire || !p->
pcp.count)
495 atomic_long_add(global_diff[i], &vm_stat[i]);
503 if (pset->vm_stat_diff[i]) {
504 int v = pset->vm_stat_diff[
i];
505 pset->vm_stat_diff[
i] = 0;
506 atomic_long_add(v, &zone->
vm_stat[i]);
507 atomic_long_add(v, &vm_stat[i]);
526 __inc_zone_state(z, NUMA_HIT);
528 __inc_zone_state(z, NUMA_MISS);
529 __inc_zone_state(preferred_zone, NUMA_FOREIGN);
533 __inc_zone_state(z, NUMA_LOCAL);
535 __inc_zone_state(z, NUMA_OTHER);
539 #ifdef CONFIG_COMPACTION
541 struct contig_page_info {
543 unsigned long free_blocks_total;
544 unsigned long free_blocks_suitable;
555 static void fill_contig_page_info(
struct zone *zone,
556 unsigned int suitable_order,
557 struct contig_page_info *
info)
561 info->free_pages = 0;
562 info->free_blocks_total = 0;
563 info->free_blocks_suitable = 0;
565 for (order = 0; order <
MAX_ORDER; order++) {
566 unsigned long blocks;
570 info->free_blocks_total += blocks;
573 info->free_pages += blocks <<
order;
576 if (order >= suitable_order)
577 info->free_blocks_suitable += blocks <<
578 (order - suitable_order);
589 static int __fragmentation_index(
unsigned int order,
struct contig_page_info *info)
591 unsigned long requested = 1
UL <<
order;
593 if (!info->free_blocks_total)
597 if (info->free_blocks_suitable)
606 return 1000 - div_u64( (1000+(div_u64(info->free_pages * 1000ULL, requested))), info->free_blocks_total);
610 int fragmentation_index(
struct zone *zone,
unsigned int order)
612 struct contig_page_info info;
614 fill_contig_page_info(zone, order, &info);
615 return __fragmentation_index(order, &info);
619 #if defined(CONFIG_PROC_FS) || defined(CONFIG_COMPACTION)
634 static void *frag_start(
struct seq_file *
m, loff_t *
pos)
654 static void frag_stop(
struct seq_file *m,
void *
arg)
666 for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
667 if (!populated_zone(zone))
671 print(m, pgdat, zone);
672 spin_unlock_irqrestore(&zone->
lock, flags);
677 #if defined(CONFIG_PROC_FS) || defined(CONFIG_SYSFS) || defined(CONFIG_NUMA)
678 #ifdef CONFIG_ZONE_DMA
679 #define TEXT_FOR_DMA(xx) xx "_dma",
681 #define TEXT_FOR_DMA(xx)
684 #ifdef CONFIG_ZONE_DMA32
685 #define TEXT_FOR_DMA32(xx) xx "_dma32",
687 #define TEXT_FOR_DMA32(xx)
690 #ifdef CONFIG_HIGHMEM
691 #define TEXT_FOR_HIGHMEM(xx) xx "_high",
693 #define TEXT_FOR_HIGHMEM(xx)
696 #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \
697 TEXT_FOR_HIGHMEM(xx) xx "_movable",
713 "nr_slab_reclaimable",
714 "nr_slab_unreclaimable",
715 "nr_page_table_pages",
720 "nr_vmscan_immediate_reclaim",
736 "nr_anon_transparent_hugepages",
738 "nr_dirty_threshold",
739 "nr_dirty_background_threshold",
741 #ifdef CONFIG_VM_EVENT_COUNTERS
747 TEXTS_FOR_ZONES(
"pgalloc")
756 TEXTS_FOR_ZONES(
"pgrefill")
757 TEXTS_FOR_ZONES("pgsteal_kswapd")
758 TEXTS_FOR_ZONES("pgsteal_direct")
759 TEXTS_FOR_ZONES("pgscan_kswapd")
760 TEXTS_FOR_ZONES("pgscan_direct")
761 "pgscan_direct_throttle",
764 "zone_reclaim_failed",
769 "kswapd_low_wmark_hit_quickly",
770 "kswapd_high_wmark_hit_quickly",
771 "kswapd_skip_congestion_wait",
777 #ifdef CONFIG_COMPACTION
778 "compact_blocks_moved",
779 "compact_pages_moved",
780 "compact_pagemigrate_failed",
786 #ifdef CONFIG_HUGETLB_PAGE
787 "htlb_buddy_alloc_success",
788 "htlb_buddy_alloc_fail",
790 "unevictable_pgs_culled",
791 "unevictable_pgs_scanned",
792 "unevictable_pgs_rescued",
793 "unevictable_pgs_mlocked",
794 "unevictable_pgs_munlocked",
795 "unevictable_pgs_cleared",
796 "unevictable_pgs_stranded",
798 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
800 "thp_fault_fallback",
801 "thp_collapse_alloc",
802 "thp_collapse_alloc_failed",
811 #ifdef CONFIG_PROC_FS
826 static int frag_show(
struct seq_file *m,
void *
arg)
829 walk_zones_in_node(m, pgdat, frag_show_print);
833 static void pagetypeinfo_showfree_print(
struct seq_file *m,
839 seq_printf(m,
"Node %4d, zone %8s, type %12s ",
842 migratetype_names[mtype]);
844 unsigned long freecount = 0;
865 seq_printf(m,
"%-43s ",
"Free pages count per migrate type at order");
870 walk_zones_in_node(m, pgdat, pagetypeinfo_showfree_print);
875 static void pagetypeinfo_showblockcount_print(
struct seq_file *m,
893 if (!memmap_valid_within(pfn, page, zone))
896 mtype = get_pageblock_migratetype(page);
898 if (mtype < MIGRATE_TYPES)
910 static int pagetypeinfo_showblockcount(
struct seq_file *m,
void *arg)
915 seq_printf(m,
"\n%-23s",
"Number of blocks type ");
917 seq_printf(m,
"%12s ", migratetype_names[mtype]);
919 walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print);
928 static int pagetypeinfo_show(
struct seq_file *m,
void *arg)
939 pagetypeinfo_showfree(m, pgdat);
940 pagetypeinfo_showblockcount(m, pgdat);
954 return seq_open(file, &fragmentation_op);
958 .
open = fragmentation_open,
968 .show = pagetypeinfo_show,
973 return seq_open(file, &pagetypeinfo_op);
977 .
open = pagetypeinfo_open,
1005 seq_printf(m,
"\n %-12s %lu", vmstat_text[i],
1006 zone_page_state(zone, i));
1009 "\n protection: (%lu",
1028 pageset->
pcp.batch);
1031 pageset->stat_threshold);
1035 "\n all_unreclaimable: %u"
1037 "\n inactive_ratio: %u",
1047 static int zoneinfo_show(
struct seq_file *m,
void *arg)
1050 walk_zones_in_node(m, pgdat, zoneinfo_show_print);
1055 .
start = frag_start,
1059 .show = zoneinfo_show,
1064 return seq_open(file, &zoneinfo_op);
1068 .
open = zoneinfo_open,
1074 enum writeback_stat_item {
1076 NR_DIRTY_BG_THRESHOLD,
1077 NR_VM_WRITEBACK_STAT_ITEMS,
1080 static void *vmstat_start(
struct seq_file *m, loff_t *pos)
1083 int i, stat_items_size;
1087 stat_items_size = NR_VM_ZONE_STAT_ITEMS *
sizeof(
unsigned long) +
1088 NR_VM_WRITEBACK_STAT_ITEMS *
sizeof(
unsigned long);
1090 #ifdef CONFIG_VM_EVENT_COUNTERS
1091 stat_items_size +=
sizeof(
struct vm_event_state);
1099 v[i] = global_page_state(i);
1103 v + NR_DIRTY_THRESHOLD);
1104 v += NR_VM_WRITEBACK_STAT_ITEMS;
1106 #ifdef CONFIG_VM_EVENT_COUNTERS
1114 static void *vmstat_next(
struct seq_file *m,
void *arg, loff_t *pos)
1122 static int vmstat_show(
struct seq_file *m,
void *arg)
1124 unsigned long *
l =
arg;
1125 unsigned long off = l - (
unsigned long *)m->
private;
1127 seq_printf(m,
"%s %lu\n", vmstat_text[off], *l);
1131 static void vmstat_stop(
struct seq_file *m,
void *arg)
1138 .
start = vmstat_start,
1139 .next = vmstat_next,
1140 .stop = vmstat_stop,
1141 .show = vmstat_show,
1150 .
open = vmstat_open,
1168 static void __cpuinit start_cpu_timer(
int cpu)
1184 long cpu = (
long)hcpu;
1189 refresh_zone_stat_thresholds();
1190 start_cpu_timer(cpu);
1200 start_cpu_timer(cpu);
1204 refresh_zone_stat_thresholds();
1213 { &vmstat_cpuup_callback,
NULL, 0 };
1216 static int __init setup_vmstat(
void)
1221 register_cpu_notifier(&vmstat_notifier);
1224 start_cpu_timer(cpu);
1226 #ifdef CONFIG_PROC_FS
1227 proc_create(
"buddyinfo",
S_IRUGO,
NULL, &fragmentation_file_operations);
1228 proc_create(
"pagetypeinfo",
S_IRUGO,
NULL, &pagetypeinfo_file_ops);
1229 proc_create(
"vmstat",
S_IRUGO,
NULL, &proc_vmstat_file_operations);
1230 proc_create(
"zoneinfo",
S_IRUGO,
NULL, &proc_zoneinfo_file_operations);
1236 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION)
1244 static int unusable_free_index(
unsigned int order,
1245 struct contig_page_info *info)
1248 if (info->free_pages == 0)
1258 return div_u64((info->free_pages - (info->free_blocks_suitable << order)) * 1000ULL, info->free_pages);
1262 static void unusable_show_print(
struct seq_file *m,
1267 struct contig_page_info info;
1273 fill_contig_page_info(zone, order, &info);
1274 index = unusable_free_index(order, &info);
1275 seq_printf(m,
"%d.%03d ", index / 1000, index % 1000);
1290 static int unusable_show(
struct seq_file *m,
void *arg)
1298 walk_zones_in_node(m, pgdat, unusable_show_print);
1304 .
start = frag_start,
1307 .show = unusable_show,
1312 return seq_open(file, &unusable_op);
1316 .
open = unusable_open,
1322 static void extfrag_show_print(
struct seq_file *m,
1329 struct contig_page_info info;
1335 fill_contig_page_info(zone, order, &info);
1336 index = __fragmentation_index(order, &info);
1337 seq_printf(m,
"%d.%03d ", index / 1000, index % 1000);
1346 static int extfrag_show(
struct seq_file *m,
void *arg)
1350 walk_zones_in_node(m, pgdat, extfrag_show_print);
1356 .
start = frag_start,
1359 .show = extfrag_show,
1364 return seq_open(file, &extfrag_op);
1368 .
open = extfrag_open,
1374 static int __init extfrag_debug_init(
void)
1376 struct dentry *extfrag_debug_root;
1379 if (!extfrag_debug_root)
1383 extfrag_debug_root,
NULL, &unusable_file_ops))
1387 extfrag_debug_root,
NULL, &extfrag_file_ops))