1f6ac2354SChristoph Lameter /* 2f6ac2354SChristoph Lameter * linux/mm/vmstat.c 3f6ac2354SChristoph Lameter * 4f6ac2354SChristoph Lameter * Manages VM statistics 5f6ac2354SChristoph Lameter * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 62244b95aSChristoph Lameter * 72244b95aSChristoph Lameter * zoned VM statistics 82244b95aSChristoph Lameter * Copyright (C) 2006 Silicon Graphics, Inc., 92244b95aSChristoph Lameter * Christoph Lameter <christoph@lameter.com> 10*7cc36bbdSChristoph Lameter * Copyright (C) 2008-2014 Christoph Lameter 11f6ac2354SChristoph Lameter */ 128f32f7e5SAlexey Dobriyan #include <linux/fs.h> 13f6ac2354SChristoph Lameter #include <linux/mm.h> 144e950f6fSAlexey Dobriyan #include <linux/err.h> 152244b95aSChristoph Lameter #include <linux/module.h> 165a0e3ad6STejun Heo #include <linux/slab.h> 17df9ecabaSChristoph Lameter #include <linux/cpu.h> 18*7cc36bbdSChristoph Lameter #include <linux/cpumask.h> 19c748e134SAdrian Bunk #include <linux/vmstat.h> 20e8edc6e0SAlexey Dobriyan #include <linux/sched.h> 21f1a5ab12SMel Gorman #include <linux/math64.h> 2279da826aSMichael Rubin #include <linux/writeback.h> 2336deb0beSNamhyung Kim #include <linux/compaction.h> 246e543d57SLisa Du #include <linux/mm_inline.h> 256e543d57SLisa Du 266e543d57SLisa Du #include "internal.h" 27f6ac2354SChristoph Lameter 28f8891e5eSChristoph Lameter #ifdef CONFIG_VM_EVENT_COUNTERS 29f8891e5eSChristoph Lameter DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; 30f8891e5eSChristoph Lameter EXPORT_PER_CPU_SYMBOL(vm_event_states); 31f8891e5eSChristoph Lameter 3231f961a8SMinchan Kim static void sum_vm_events(unsigned long *ret) 33f8891e5eSChristoph Lameter { 349eccf2a8SChristoph Lameter int cpu; 35f8891e5eSChristoph Lameter int i; 36f8891e5eSChristoph Lameter 37f8891e5eSChristoph Lameter memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); 38f8891e5eSChristoph Lameter 3931f961a8SMinchan Kim for_each_online_cpu(cpu) { 40f8891e5eSChristoph Lameter struct vm_event_state *this = &per_cpu(vm_event_states, cpu); 41f8891e5eSChristoph Lameter 42f8891e5eSChristoph Lameter for (i = 0; i < NR_VM_EVENT_ITEMS; i++) 43f8891e5eSChristoph Lameter ret[i] += this->event[i]; 44f8891e5eSChristoph Lameter } 45f8891e5eSChristoph Lameter } 46f8891e5eSChristoph Lameter 47f8891e5eSChristoph Lameter /* 48f8891e5eSChristoph Lameter * Accumulate the vm event counters across all CPUs. 49f8891e5eSChristoph Lameter * The result is unavoidably approximate - it can change 50f8891e5eSChristoph Lameter * during and after execution of this function. 51f8891e5eSChristoph Lameter */ 52f8891e5eSChristoph Lameter void all_vm_events(unsigned long *ret) 53f8891e5eSChristoph Lameter { 54b5be1132SKOSAKI Motohiro get_online_cpus(); 5531f961a8SMinchan Kim sum_vm_events(ret); 56b5be1132SKOSAKI Motohiro put_online_cpus(); 57f8891e5eSChristoph Lameter } 5832dd66fcSHeiko Carstens EXPORT_SYMBOL_GPL(all_vm_events); 59f8891e5eSChristoph Lameter 60f8891e5eSChristoph Lameter /* 61f8891e5eSChristoph Lameter * Fold the foreign cpu events into our own. 62f8891e5eSChristoph Lameter * 63f8891e5eSChristoph Lameter * This is adding to the events on one processor 64f8891e5eSChristoph Lameter * but keeps the global counts constant. 65f8891e5eSChristoph Lameter */ 66f8891e5eSChristoph Lameter void vm_events_fold_cpu(int cpu) 67f8891e5eSChristoph Lameter { 68f8891e5eSChristoph Lameter struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); 69f8891e5eSChristoph Lameter int i; 70f8891e5eSChristoph Lameter 71f8891e5eSChristoph Lameter for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { 72f8891e5eSChristoph Lameter count_vm_events(i, fold_state->event[i]); 73f8891e5eSChristoph Lameter fold_state->event[i] = 0; 74f8891e5eSChristoph Lameter } 75f8891e5eSChristoph Lameter } 76f8891e5eSChristoph Lameter 77f8891e5eSChristoph Lameter #endif /* CONFIG_VM_EVENT_COUNTERS */ 78f8891e5eSChristoph Lameter 792244b95aSChristoph Lameter /* 802244b95aSChristoph Lameter * Manage combined zone based / global counters 812244b95aSChristoph Lameter * 822244b95aSChristoph Lameter * vm_stat contains the global counters 832244b95aSChristoph Lameter */ 84a1cb2c60SDimitri Sivanich atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp; 852244b95aSChristoph Lameter EXPORT_SYMBOL(vm_stat); 862244b95aSChristoph Lameter 872244b95aSChristoph Lameter #ifdef CONFIG_SMP 882244b95aSChristoph Lameter 89b44129b3SMel Gorman int calculate_pressure_threshold(struct zone *zone) 9088f5acf8SMel Gorman { 9188f5acf8SMel Gorman int threshold; 9288f5acf8SMel Gorman int watermark_distance; 9388f5acf8SMel Gorman 9488f5acf8SMel Gorman /* 9588f5acf8SMel Gorman * As vmstats are not up to date, there is drift between the estimated 9688f5acf8SMel Gorman * and real values. For high thresholds and a high number of CPUs, it 9788f5acf8SMel Gorman * is possible for the min watermark to be breached while the estimated 9888f5acf8SMel Gorman * value looks fine. The pressure threshold is a reduced value such 9988f5acf8SMel Gorman * that even the maximum amount of drift will not accidentally breach 10088f5acf8SMel Gorman * the min watermark 10188f5acf8SMel Gorman */ 10288f5acf8SMel Gorman watermark_distance = low_wmark_pages(zone) - min_wmark_pages(zone); 10388f5acf8SMel Gorman threshold = max(1, (int)(watermark_distance / num_online_cpus())); 10488f5acf8SMel Gorman 10588f5acf8SMel Gorman /* 10688f5acf8SMel Gorman * Maximum threshold is 125 10788f5acf8SMel Gorman */ 10888f5acf8SMel Gorman threshold = min(125, threshold); 10988f5acf8SMel Gorman 11088f5acf8SMel Gorman return threshold; 11188f5acf8SMel Gorman } 11288f5acf8SMel Gorman 113b44129b3SMel Gorman int calculate_normal_threshold(struct zone *zone) 114df9ecabaSChristoph Lameter { 115df9ecabaSChristoph Lameter int threshold; 116df9ecabaSChristoph Lameter int mem; /* memory in 128 MB units */ 1172244b95aSChristoph Lameter 1182244b95aSChristoph Lameter /* 119df9ecabaSChristoph Lameter * The threshold scales with the number of processors and the amount 120df9ecabaSChristoph Lameter * of memory per zone. More memory means that we can defer updates for 121df9ecabaSChristoph Lameter * longer, more processors could lead to more contention. 122df9ecabaSChristoph Lameter * fls() is used to have a cheap way of logarithmic scaling. 1232244b95aSChristoph Lameter * 124df9ecabaSChristoph Lameter * Some sample thresholds: 125df9ecabaSChristoph Lameter * 126df9ecabaSChristoph Lameter * Threshold Processors (fls) Zonesize fls(mem+1) 127df9ecabaSChristoph Lameter * ------------------------------------------------------------------ 128df9ecabaSChristoph Lameter * 8 1 1 0.9-1 GB 4 129df9ecabaSChristoph Lameter * 16 2 2 0.9-1 GB 4 130df9ecabaSChristoph Lameter * 20 2 2 1-2 GB 5 131df9ecabaSChristoph Lameter * 24 2 2 2-4 GB 6 132df9ecabaSChristoph Lameter * 28 2 2 4-8 GB 7 133df9ecabaSChristoph Lameter * 32 2 2 8-16 GB 8 134df9ecabaSChristoph Lameter * 4 2 2 <128M 1 135df9ecabaSChristoph Lameter * 30 4 3 2-4 GB 5 136df9ecabaSChristoph Lameter * 48 4 3 8-16 GB 8 137df9ecabaSChristoph Lameter * 32 8 4 1-2 GB 4 138df9ecabaSChristoph Lameter * 32 8 4 0.9-1GB 4 139df9ecabaSChristoph Lameter * 10 16 5 <128M 1 140df9ecabaSChristoph Lameter * 40 16 5 900M 4 141df9ecabaSChristoph Lameter * 70 64 7 2-4 GB 5 142df9ecabaSChristoph Lameter * 84 64 7 4-8 GB 6 143df9ecabaSChristoph Lameter * 108 512 9 4-8 GB 6 144df9ecabaSChristoph Lameter * 125 1024 10 8-16 GB 8 145df9ecabaSChristoph Lameter * 125 1024 10 16-32 GB 9 1462244b95aSChristoph Lameter */ 147df9ecabaSChristoph Lameter 148b40da049SJiang Liu mem = zone->managed_pages >> (27 - PAGE_SHIFT); 149df9ecabaSChristoph Lameter 150df9ecabaSChristoph Lameter threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem)); 151df9ecabaSChristoph Lameter 152df9ecabaSChristoph Lameter /* 153df9ecabaSChristoph Lameter * Maximum threshold is 125 154df9ecabaSChristoph Lameter */ 155df9ecabaSChristoph Lameter threshold = min(125, threshold); 156df9ecabaSChristoph Lameter 157df9ecabaSChristoph Lameter return threshold; 158df9ecabaSChristoph Lameter } 159df9ecabaSChristoph Lameter 160df9ecabaSChristoph Lameter /* 161df9ecabaSChristoph Lameter * Refresh the thresholds for each zone. 162df9ecabaSChristoph Lameter */ 163a6cccdc3SKOSAKI Motohiro void refresh_zone_stat_thresholds(void) 1642244b95aSChristoph Lameter { 165df9ecabaSChristoph Lameter struct zone *zone; 166df9ecabaSChristoph Lameter int cpu; 167df9ecabaSChristoph Lameter int threshold; 168df9ecabaSChristoph Lameter 169ee99c71cSKOSAKI Motohiro for_each_populated_zone(zone) { 170aa454840SChristoph Lameter unsigned long max_drift, tolerate_drift; 171aa454840SChristoph Lameter 172b44129b3SMel Gorman threshold = calculate_normal_threshold(zone); 173df9ecabaSChristoph Lameter 174df9ecabaSChristoph Lameter for_each_online_cpu(cpu) 17599dcc3e5SChristoph Lameter per_cpu_ptr(zone->pageset, cpu)->stat_threshold 17699dcc3e5SChristoph Lameter = threshold; 177aa454840SChristoph Lameter 178aa454840SChristoph Lameter /* 179aa454840SChristoph Lameter * Only set percpu_drift_mark if there is a danger that 180aa454840SChristoph Lameter * NR_FREE_PAGES reports the low watermark is ok when in fact 181aa454840SChristoph Lameter * the min watermark could be breached by an allocation 182aa454840SChristoph Lameter */ 183aa454840SChristoph Lameter tolerate_drift = low_wmark_pages(zone) - min_wmark_pages(zone); 184aa454840SChristoph Lameter max_drift = num_online_cpus() * threshold; 185aa454840SChristoph Lameter if (max_drift > tolerate_drift) 186aa454840SChristoph Lameter zone->percpu_drift_mark = high_wmark_pages(zone) + 187aa454840SChristoph Lameter max_drift; 188df9ecabaSChristoph Lameter } 1892244b95aSChristoph Lameter } 1902244b95aSChristoph Lameter 191b44129b3SMel Gorman void set_pgdat_percpu_threshold(pg_data_t *pgdat, 192b44129b3SMel Gorman int (*calculate_pressure)(struct zone *)) 19388f5acf8SMel Gorman { 19488f5acf8SMel Gorman struct zone *zone; 19588f5acf8SMel Gorman int cpu; 19688f5acf8SMel Gorman int threshold; 19788f5acf8SMel Gorman int i; 19888f5acf8SMel Gorman 19988f5acf8SMel Gorman for (i = 0; i < pgdat->nr_zones; i++) { 20088f5acf8SMel Gorman zone = &pgdat->node_zones[i]; 20188f5acf8SMel Gorman if (!zone->percpu_drift_mark) 20288f5acf8SMel Gorman continue; 20388f5acf8SMel Gorman 204b44129b3SMel Gorman threshold = (*calculate_pressure)(zone); 205bb0b6dffSMel Gorman for_each_online_cpu(cpu) 20688f5acf8SMel Gorman per_cpu_ptr(zone->pageset, cpu)->stat_threshold 20788f5acf8SMel Gorman = threshold; 20888f5acf8SMel Gorman } 20988f5acf8SMel Gorman } 21088f5acf8SMel Gorman 2112244b95aSChristoph Lameter /* 212bea04b07SJianyu Zhan * For use when we know that interrupts are disabled, 213bea04b07SJianyu Zhan * or when we know that preemption is disabled and that 214bea04b07SJianyu Zhan * particular counter cannot be updated from interrupt context. 2152244b95aSChristoph Lameter */ 2162244b95aSChristoph Lameter void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, 2172244b95aSChristoph Lameter int delta) 2182244b95aSChristoph Lameter { 21912938a92SChristoph Lameter struct per_cpu_pageset __percpu *pcp = zone->pageset; 22012938a92SChristoph Lameter s8 __percpu *p = pcp->vm_stat_diff + item; 2212244b95aSChristoph Lameter long x; 22212938a92SChristoph Lameter long t; 2232244b95aSChristoph Lameter 22412938a92SChristoph Lameter x = delta + __this_cpu_read(*p); 2252244b95aSChristoph Lameter 22612938a92SChristoph Lameter t = __this_cpu_read(pcp->stat_threshold); 22712938a92SChristoph Lameter 22812938a92SChristoph Lameter if (unlikely(x > t || x < -t)) { 2292244b95aSChristoph Lameter zone_page_state_add(x, zone, item); 2302244b95aSChristoph Lameter x = 0; 2312244b95aSChristoph Lameter } 23212938a92SChristoph Lameter __this_cpu_write(*p, x); 2332244b95aSChristoph Lameter } 2342244b95aSChristoph Lameter EXPORT_SYMBOL(__mod_zone_page_state); 2352244b95aSChristoph Lameter 2362244b95aSChristoph Lameter /* 2372244b95aSChristoph Lameter * Optimized increment and decrement functions. 2382244b95aSChristoph Lameter * 2392244b95aSChristoph Lameter * These are only for a single page and therefore can take a struct page * 2402244b95aSChristoph Lameter * argument instead of struct zone *. This allows the inclusion of the code 2412244b95aSChristoph Lameter * generated for page_zone(page) into the optimized functions. 2422244b95aSChristoph Lameter * 2432244b95aSChristoph Lameter * No overflow check is necessary and therefore the differential can be 2442244b95aSChristoph Lameter * incremented or decremented in place which may allow the compilers to 2452244b95aSChristoph Lameter * generate better code. 2462244b95aSChristoph Lameter * The increment or decrement is known and therefore one boundary check can 2472244b95aSChristoph Lameter * be omitted. 2482244b95aSChristoph Lameter * 249df9ecabaSChristoph Lameter * NOTE: These functions are very performance sensitive. Change only 250df9ecabaSChristoph Lameter * with care. 251df9ecabaSChristoph Lameter * 2522244b95aSChristoph Lameter * Some processors have inc/dec instructions that are atomic vs an interrupt. 2532244b95aSChristoph Lameter * However, the code must first determine the differential location in a zone 2542244b95aSChristoph Lameter * based on the processor number and then inc/dec the counter. There is no 2552244b95aSChristoph Lameter * guarantee without disabling preemption that the processor will not change 2562244b95aSChristoph Lameter * in between and therefore the atomicity vs. interrupt cannot be exploited 2572244b95aSChristoph Lameter * in a useful way here. 2582244b95aSChristoph Lameter */ 259c8785385SChristoph Lameter void __inc_zone_state(struct zone *zone, enum zone_stat_item item) 2602244b95aSChristoph Lameter { 26112938a92SChristoph Lameter struct per_cpu_pageset __percpu *pcp = zone->pageset; 26212938a92SChristoph Lameter s8 __percpu *p = pcp->vm_stat_diff + item; 26312938a92SChristoph Lameter s8 v, t; 2642244b95aSChristoph Lameter 265908ee0f1SChristoph Lameter v = __this_cpu_inc_return(*p); 26612938a92SChristoph Lameter t = __this_cpu_read(pcp->stat_threshold); 26712938a92SChristoph Lameter if (unlikely(v > t)) { 26812938a92SChristoph Lameter s8 overstep = t >> 1; 2692244b95aSChristoph Lameter 27012938a92SChristoph Lameter zone_page_state_add(v + overstep, zone, item); 27112938a92SChristoph Lameter __this_cpu_write(*p, -overstep); 2722244b95aSChristoph Lameter } 2732244b95aSChristoph Lameter } 274ca889e6cSChristoph Lameter 275ca889e6cSChristoph Lameter void __inc_zone_page_state(struct page *page, enum zone_stat_item item) 276ca889e6cSChristoph Lameter { 277ca889e6cSChristoph Lameter __inc_zone_state(page_zone(page), item); 278ca889e6cSChristoph Lameter } 2792244b95aSChristoph Lameter EXPORT_SYMBOL(__inc_zone_page_state); 2802244b95aSChristoph Lameter 281c8785385SChristoph Lameter void __dec_zone_state(struct zone *zone, enum zone_stat_item item) 2822244b95aSChristoph Lameter { 28312938a92SChristoph Lameter struct per_cpu_pageset __percpu *pcp = zone->pageset; 28412938a92SChristoph Lameter s8 __percpu *p = pcp->vm_stat_diff + item; 28512938a92SChristoph Lameter s8 v, t; 2862244b95aSChristoph Lameter 287908ee0f1SChristoph Lameter v = __this_cpu_dec_return(*p); 28812938a92SChristoph Lameter t = __this_cpu_read(pcp->stat_threshold); 28912938a92SChristoph Lameter if (unlikely(v < - t)) { 29012938a92SChristoph Lameter s8 overstep = t >> 1; 2912244b95aSChristoph Lameter 29212938a92SChristoph Lameter zone_page_state_add(v - overstep, zone, item); 29312938a92SChristoph Lameter __this_cpu_write(*p, overstep); 2942244b95aSChristoph Lameter } 2952244b95aSChristoph Lameter } 296c8785385SChristoph Lameter 297c8785385SChristoph Lameter void __dec_zone_page_state(struct page *page, enum zone_stat_item item) 298c8785385SChristoph Lameter { 299c8785385SChristoph Lameter __dec_zone_state(page_zone(page), item); 300c8785385SChristoph Lameter } 3012244b95aSChristoph Lameter EXPORT_SYMBOL(__dec_zone_page_state); 3022244b95aSChristoph Lameter 3034156153cSHeiko Carstens #ifdef CONFIG_HAVE_CMPXCHG_LOCAL 3047c839120SChristoph Lameter /* 3057c839120SChristoph Lameter * If we have cmpxchg_local support then we do not need to incur the overhead 3067c839120SChristoph Lameter * that comes with local_irq_save/restore if we use this_cpu_cmpxchg. 3077c839120SChristoph Lameter * 3087c839120SChristoph Lameter * mod_state() modifies the zone counter state through atomic per cpu 3097c839120SChristoph Lameter * operations. 3107c839120SChristoph Lameter * 3117c839120SChristoph Lameter * Overstep mode specifies how overstep should handled: 3127c839120SChristoph Lameter * 0 No overstepping 3137c839120SChristoph Lameter * 1 Overstepping half of threshold 3147c839120SChristoph Lameter * -1 Overstepping minus half of threshold 3157c839120SChristoph Lameter */ 3167c839120SChristoph Lameter static inline void mod_state(struct zone *zone, 3177c839120SChristoph Lameter enum zone_stat_item item, int delta, int overstep_mode) 3187c839120SChristoph Lameter { 3197c839120SChristoph Lameter struct per_cpu_pageset __percpu *pcp = zone->pageset; 3207c839120SChristoph Lameter s8 __percpu *p = pcp->vm_stat_diff + item; 3217c839120SChristoph Lameter long o, n, t, z; 3227c839120SChristoph Lameter 3237c839120SChristoph Lameter do { 3247c839120SChristoph Lameter z = 0; /* overflow to zone counters */ 3257c839120SChristoph Lameter 3267c839120SChristoph Lameter /* 3277c839120SChristoph Lameter * The fetching of the stat_threshold is racy. We may apply 3287c839120SChristoph Lameter * a counter threshold to the wrong the cpu if we get 329d3bc2367SChristoph Lameter * rescheduled while executing here. However, the next 330d3bc2367SChristoph Lameter * counter update will apply the threshold again and 331d3bc2367SChristoph Lameter * therefore bring the counter under the threshold again. 332d3bc2367SChristoph Lameter * 333d3bc2367SChristoph Lameter * Most of the time the thresholds are the same anyways 334d3bc2367SChristoph Lameter * for all cpus in a zone. 3357c839120SChristoph Lameter */ 3367c839120SChristoph Lameter t = this_cpu_read(pcp->stat_threshold); 3377c839120SChristoph Lameter 3387c839120SChristoph Lameter o = this_cpu_read(*p); 3397c839120SChristoph Lameter n = delta + o; 3407c839120SChristoph Lameter 3417c839120SChristoph Lameter if (n > t || n < -t) { 3427c839120SChristoph Lameter int os = overstep_mode * (t >> 1) ; 3437c839120SChristoph Lameter 3447c839120SChristoph Lameter /* Overflow must be added to zone counters */ 3457c839120SChristoph Lameter z = n + os; 3467c839120SChristoph Lameter n = -os; 3477c839120SChristoph Lameter } 3487c839120SChristoph Lameter } while (this_cpu_cmpxchg(*p, o, n) != o); 3497c839120SChristoph Lameter 3507c839120SChristoph Lameter if (z) 3517c839120SChristoph Lameter zone_page_state_add(z, zone, item); 3527c839120SChristoph Lameter } 3537c839120SChristoph Lameter 3547c839120SChristoph Lameter void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, 3557c839120SChristoph Lameter int delta) 3567c839120SChristoph Lameter { 3577c839120SChristoph Lameter mod_state(zone, item, delta, 0); 3587c839120SChristoph Lameter } 3597c839120SChristoph Lameter EXPORT_SYMBOL(mod_zone_page_state); 3607c839120SChristoph Lameter 3617c839120SChristoph Lameter void inc_zone_state(struct zone *zone, enum zone_stat_item item) 3627c839120SChristoph Lameter { 3637c839120SChristoph Lameter mod_state(zone, item, 1, 1); 3647c839120SChristoph Lameter } 3657c839120SChristoph Lameter 3667c839120SChristoph Lameter void inc_zone_page_state(struct page *page, enum zone_stat_item item) 3677c839120SChristoph Lameter { 3687c839120SChristoph Lameter mod_state(page_zone(page), item, 1, 1); 3697c839120SChristoph Lameter } 3707c839120SChristoph Lameter EXPORT_SYMBOL(inc_zone_page_state); 3717c839120SChristoph Lameter 3727c839120SChristoph Lameter void dec_zone_page_state(struct page *page, enum zone_stat_item item) 3737c839120SChristoph Lameter { 3747c839120SChristoph Lameter mod_state(page_zone(page), item, -1, -1); 3757c839120SChristoph Lameter } 3767c839120SChristoph Lameter EXPORT_SYMBOL(dec_zone_page_state); 3777c839120SChristoph Lameter #else 3787c839120SChristoph Lameter /* 3797c839120SChristoph Lameter * Use interrupt disable to serialize counter updates 3807c839120SChristoph Lameter */ 3817c839120SChristoph Lameter void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, 3827c839120SChristoph Lameter int delta) 3837c839120SChristoph Lameter { 3847c839120SChristoph Lameter unsigned long flags; 3857c839120SChristoph Lameter 3867c839120SChristoph Lameter local_irq_save(flags); 3877c839120SChristoph Lameter __mod_zone_page_state(zone, item, delta); 3887c839120SChristoph Lameter local_irq_restore(flags); 3897c839120SChristoph Lameter } 3907c839120SChristoph Lameter EXPORT_SYMBOL(mod_zone_page_state); 3917c839120SChristoph Lameter 392ca889e6cSChristoph Lameter void inc_zone_state(struct zone *zone, enum zone_stat_item item) 393ca889e6cSChristoph Lameter { 394ca889e6cSChristoph Lameter unsigned long flags; 395ca889e6cSChristoph Lameter 396ca889e6cSChristoph Lameter local_irq_save(flags); 397ca889e6cSChristoph Lameter __inc_zone_state(zone, item); 398ca889e6cSChristoph Lameter local_irq_restore(flags); 399ca889e6cSChristoph Lameter } 400ca889e6cSChristoph Lameter 4012244b95aSChristoph Lameter void inc_zone_page_state(struct page *page, enum zone_stat_item item) 4022244b95aSChristoph Lameter { 4032244b95aSChristoph Lameter unsigned long flags; 4042244b95aSChristoph Lameter struct zone *zone; 4052244b95aSChristoph Lameter 4062244b95aSChristoph Lameter zone = page_zone(page); 4072244b95aSChristoph Lameter local_irq_save(flags); 408ca889e6cSChristoph Lameter __inc_zone_state(zone, item); 4092244b95aSChristoph Lameter local_irq_restore(flags); 4102244b95aSChristoph Lameter } 4112244b95aSChristoph Lameter EXPORT_SYMBOL(inc_zone_page_state); 4122244b95aSChristoph Lameter 4132244b95aSChristoph Lameter void dec_zone_page_state(struct page *page, enum zone_stat_item item) 4142244b95aSChristoph Lameter { 4152244b95aSChristoph Lameter unsigned long flags; 4162244b95aSChristoph Lameter 4172244b95aSChristoph Lameter local_irq_save(flags); 418a302eb4eSChristoph Lameter __dec_zone_page_state(page, item); 4192244b95aSChristoph Lameter local_irq_restore(flags); 4202244b95aSChristoph Lameter } 4212244b95aSChristoph Lameter EXPORT_SYMBOL(dec_zone_page_state); 4227c839120SChristoph Lameter #endif 4232244b95aSChristoph Lameter 424*7cc36bbdSChristoph Lameter 425*7cc36bbdSChristoph Lameter /* 426*7cc36bbdSChristoph Lameter * Fold a differential into the global counters. 427*7cc36bbdSChristoph Lameter * Returns the number of counters updated. 428*7cc36bbdSChristoph Lameter */ 429*7cc36bbdSChristoph Lameter static int fold_diff(int *diff) 4304edb0748SChristoph Lameter { 4314edb0748SChristoph Lameter int i; 432*7cc36bbdSChristoph Lameter int changes = 0; 4334edb0748SChristoph Lameter 4344edb0748SChristoph Lameter for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) 435*7cc36bbdSChristoph Lameter if (diff[i]) { 4364edb0748SChristoph Lameter atomic_long_add(diff[i], &vm_stat[i]); 437*7cc36bbdSChristoph Lameter changes++; 438*7cc36bbdSChristoph Lameter } 439*7cc36bbdSChristoph Lameter return changes; 4404edb0748SChristoph Lameter } 4414edb0748SChristoph Lameter 4422244b95aSChristoph Lameter /* 4432bb921e5SChristoph Lameter * Update the zone counters for the current cpu. 444a7f75e25SChristoph Lameter * 4454037d452SChristoph Lameter * Note that refresh_cpu_vm_stats strives to only access 4464037d452SChristoph Lameter * node local memory. The per cpu pagesets on remote zones are placed 4474037d452SChristoph Lameter * in the memory local to the processor using that pageset. So the 4484037d452SChristoph Lameter * loop over all zones will access a series of cachelines local to 4494037d452SChristoph Lameter * the processor. 4504037d452SChristoph Lameter * 4514037d452SChristoph Lameter * The call to zone_page_state_add updates the cachelines with the 4524037d452SChristoph Lameter * statistics in the remote zone struct as well as the global cachelines 4534037d452SChristoph Lameter * with the global counters. These could cause remote node cache line 4544037d452SChristoph Lameter * bouncing and will have to be only done when necessary. 455*7cc36bbdSChristoph Lameter * 456*7cc36bbdSChristoph Lameter * The function returns the number of global counters updated. 4572244b95aSChristoph Lameter */ 458*7cc36bbdSChristoph Lameter static int refresh_cpu_vm_stats(void) 4592244b95aSChristoph Lameter { 4602244b95aSChristoph Lameter struct zone *zone; 4612244b95aSChristoph Lameter int i; 462a7f75e25SChristoph Lameter int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; 463*7cc36bbdSChristoph Lameter int changes = 0; 4642244b95aSChristoph Lameter 465ee99c71cSKOSAKI Motohiro for_each_populated_zone(zone) { 466fbc2edb0SChristoph Lameter struct per_cpu_pageset __percpu *p = zone->pageset; 4672244b95aSChristoph Lameter 468fbc2edb0SChristoph Lameter for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { 469a7f75e25SChristoph Lameter int v; 470a7f75e25SChristoph Lameter 471fbc2edb0SChristoph Lameter v = this_cpu_xchg(p->vm_stat_diff[i], 0); 472fbc2edb0SChristoph Lameter if (v) { 473fbc2edb0SChristoph Lameter 474a7f75e25SChristoph Lameter atomic_long_add(v, &zone->vm_stat[i]); 475a7f75e25SChristoph Lameter global_diff[i] += v; 4764037d452SChristoph Lameter #ifdef CONFIG_NUMA 4774037d452SChristoph Lameter /* 3 seconds idle till flush */ 478fbc2edb0SChristoph Lameter __this_cpu_write(p->expire, 3); 4794037d452SChristoph Lameter #endif 4802244b95aSChristoph Lameter } 481fbc2edb0SChristoph Lameter } 482468fd62eSDimitri Sivanich cond_resched(); 4834037d452SChristoph Lameter #ifdef CONFIG_NUMA 4844037d452SChristoph Lameter /* 4854037d452SChristoph Lameter * Deal with draining the remote pageset of this 4864037d452SChristoph Lameter * processor 4874037d452SChristoph Lameter * 4884037d452SChristoph Lameter * Check if there are pages remaining in this pageset 4894037d452SChristoph Lameter * if not then there is nothing to expire. 4904037d452SChristoph Lameter */ 491fbc2edb0SChristoph Lameter if (!__this_cpu_read(p->expire) || 492fbc2edb0SChristoph Lameter !__this_cpu_read(p->pcp.count)) 4934037d452SChristoph Lameter continue; 4944037d452SChristoph Lameter 4954037d452SChristoph Lameter /* 4964037d452SChristoph Lameter * We never drain zones local to this processor. 4974037d452SChristoph Lameter */ 4984037d452SChristoph Lameter if (zone_to_nid(zone) == numa_node_id()) { 499fbc2edb0SChristoph Lameter __this_cpu_write(p->expire, 0); 5004037d452SChristoph Lameter continue; 5014037d452SChristoph Lameter } 5024037d452SChristoph Lameter 503fbc2edb0SChristoph Lameter if (__this_cpu_dec_return(p->expire)) 5044037d452SChristoph Lameter continue; 5054037d452SChristoph Lameter 506*7cc36bbdSChristoph Lameter if (__this_cpu_read(p->pcp.count)) { 5077c8e0181SChristoph Lameter drain_zone_pages(zone, this_cpu_ptr(&p->pcp)); 508*7cc36bbdSChristoph Lameter changes++; 509*7cc36bbdSChristoph Lameter } 5104037d452SChristoph Lameter #endif 5112244b95aSChristoph Lameter } 512*7cc36bbdSChristoph Lameter changes += fold_diff(global_diff); 513*7cc36bbdSChristoph Lameter return changes; 5142244b95aSChristoph Lameter } 5152244b95aSChristoph Lameter 51640f4b1eaSCody P Schafer /* 5172bb921e5SChristoph Lameter * Fold the data for an offline cpu into the global array. 5182bb921e5SChristoph Lameter * There cannot be any access by the offline cpu and therefore 5192bb921e5SChristoph Lameter * synchronization is simplified. 5202bb921e5SChristoph Lameter */ 5212bb921e5SChristoph Lameter void cpu_vm_stats_fold(int cpu) 5222bb921e5SChristoph Lameter { 5232bb921e5SChristoph Lameter struct zone *zone; 5242bb921e5SChristoph Lameter int i; 5252bb921e5SChristoph Lameter int global_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; 5262bb921e5SChristoph Lameter 5272bb921e5SChristoph Lameter for_each_populated_zone(zone) { 5282bb921e5SChristoph Lameter struct per_cpu_pageset *p; 5292bb921e5SChristoph Lameter 5302bb921e5SChristoph Lameter p = per_cpu_ptr(zone->pageset, cpu); 5312bb921e5SChristoph Lameter 5322bb921e5SChristoph Lameter for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) 5332bb921e5SChristoph Lameter if (p->vm_stat_diff[i]) { 5342bb921e5SChristoph Lameter int v; 5352bb921e5SChristoph Lameter 5362bb921e5SChristoph Lameter v = p->vm_stat_diff[i]; 5372bb921e5SChristoph Lameter p->vm_stat_diff[i] = 0; 5382bb921e5SChristoph Lameter atomic_long_add(v, &zone->vm_stat[i]); 5392bb921e5SChristoph Lameter global_diff[i] += v; 5402bb921e5SChristoph Lameter } 5412bb921e5SChristoph Lameter } 5422bb921e5SChristoph Lameter 5434edb0748SChristoph Lameter fold_diff(global_diff); 5442bb921e5SChristoph Lameter } 5452bb921e5SChristoph Lameter 5462bb921e5SChristoph Lameter /* 54740f4b1eaSCody P Schafer * this is only called if !populated_zone(zone), which implies no other users of 54840f4b1eaSCody P Schafer * pset->vm_stat_diff[] exsist. 54940f4b1eaSCody P Schafer */ 5505a883813SMinchan Kim void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset) 5515a883813SMinchan Kim { 5525a883813SMinchan Kim int i; 5535a883813SMinchan Kim 5545a883813SMinchan Kim for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) 5555a883813SMinchan Kim if (pset->vm_stat_diff[i]) { 5565a883813SMinchan Kim int v = pset->vm_stat_diff[i]; 5575a883813SMinchan Kim pset->vm_stat_diff[i] = 0; 5585a883813SMinchan Kim atomic_long_add(v, &zone->vm_stat[i]); 5595a883813SMinchan Kim atomic_long_add(v, &vm_stat[i]); 5605a883813SMinchan Kim } 5615a883813SMinchan Kim } 5622244b95aSChristoph Lameter #endif 5632244b95aSChristoph Lameter 564ca889e6cSChristoph Lameter #ifdef CONFIG_NUMA 565ca889e6cSChristoph Lameter /* 566ca889e6cSChristoph Lameter * zonelist = the list of zones passed to the allocator 567ca889e6cSChristoph Lameter * z = the zone from which the allocation occurred. 568ca889e6cSChristoph Lameter * 569ca889e6cSChristoph Lameter * Must be called with interrupts disabled. 57078afd561SAndi Kleen * 57178afd561SAndi Kleen * When __GFP_OTHER_NODE is set assume the node of the preferred 57278afd561SAndi Kleen * zone is the local node. This is useful for daemons who allocate 57378afd561SAndi Kleen * memory on behalf of other processes. 574ca889e6cSChristoph Lameter */ 57578afd561SAndi Kleen void zone_statistics(struct zone *preferred_zone, struct zone *z, gfp_t flags) 576ca889e6cSChristoph Lameter { 57718ea7e71SMel Gorman if (z->zone_pgdat == preferred_zone->zone_pgdat) { 578ca889e6cSChristoph Lameter __inc_zone_state(z, NUMA_HIT); 579ca889e6cSChristoph Lameter } else { 580ca889e6cSChristoph Lameter __inc_zone_state(z, NUMA_MISS); 58118ea7e71SMel Gorman __inc_zone_state(preferred_zone, NUMA_FOREIGN); 582ca889e6cSChristoph Lameter } 58378afd561SAndi Kleen if (z->node == ((flags & __GFP_OTHER_NODE) ? 58478afd561SAndi Kleen preferred_zone->node : numa_node_id())) 585ca889e6cSChristoph Lameter __inc_zone_state(z, NUMA_LOCAL); 586ca889e6cSChristoph Lameter else 587ca889e6cSChristoph Lameter __inc_zone_state(z, NUMA_OTHER); 588ca889e6cSChristoph Lameter } 589ca889e6cSChristoph Lameter #endif 590ca889e6cSChristoph Lameter 591d7a5752cSMel Gorman #ifdef CONFIG_COMPACTION 59236deb0beSNamhyung Kim 593d7a5752cSMel Gorman struct contig_page_info { 594d7a5752cSMel Gorman unsigned long free_pages; 595d7a5752cSMel Gorman unsigned long free_blocks_total; 596d7a5752cSMel Gorman unsigned long free_blocks_suitable; 597d7a5752cSMel Gorman }; 598d7a5752cSMel Gorman 599d7a5752cSMel Gorman /* 600d7a5752cSMel Gorman * Calculate the number of free pages in a zone, how many contiguous 601d7a5752cSMel Gorman * pages are free and how many are large enough to satisfy an allocation of 602d7a5752cSMel Gorman * the target size. Note that this function makes no attempt to estimate 603d7a5752cSMel Gorman * how many suitable free blocks there *might* be if MOVABLE pages were 604d7a5752cSMel Gorman * migrated. Calculating that is possible, but expensive and can be 605d7a5752cSMel Gorman * figured out from userspace 606d7a5752cSMel Gorman */ 607d7a5752cSMel Gorman static void fill_contig_page_info(struct zone *zone, 608d7a5752cSMel Gorman unsigned int suitable_order, 609d7a5752cSMel Gorman struct contig_page_info *info) 610d7a5752cSMel Gorman { 611d7a5752cSMel Gorman unsigned int order; 612d7a5752cSMel Gorman 613d7a5752cSMel Gorman info->free_pages = 0; 614d7a5752cSMel Gorman info->free_blocks_total = 0; 615d7a5752cSMel Gorman info->free_blocks_suitable = 0; 616d7a5752cSMel Gorman 617d7a5752cSMel Gorman for (order = 0; order < MAX_ORDER; order++) { 618d7a5752cSMel Gorman unsigned long blocks; 619d7a5752cSMel Gorman 620d7a5752cSMel Gorman /* Count number of free blocks */ 621d7a5752cSMel Gorman blocks = zone->free_area[order].nr_free; 622d7a5752cSMel Gorman info->free_blocks_total += blocks; 623d7a5752cSMel Gorman 624d7a5752cSMel Gorman /* Count free base pages */ 625d7a5752cSMel Gorman info->free_pages += blocks << order; 626d7a5752cSMel Gorman 627d7a5752cSMel Gorman /* Count the suitable free blocks */ 628d7a5752cSMel Gorman if (order >= suitable_order) 629d7a5752cSMel Gorman info->free_blocks_suitable += blocks << 630d7a5752cSMel Gorman (order - suitable_order); 631d7a5752cSMel Gorman } 632d7a5752cSMel Gorman } 633f1a5ab12SMel Gorman 634f1a5ab12SMel Gorman /* 635f1a5ab12SMel Gorman * A fragmentation index only makes sense if an allocation of a requested 636f1a5ab12SMel Gorman * size would fail. If that is true, the fragmentation index indicates 637f1a5ab12SMel Gorman * whether external fragmentation or a lack of memory was the problem. 638f1a5ab12SMel Gorman * The value can be used to determine if page reclaim or compaction 639f1a5ab12SMel Gorman * should be used 640f1a5ab12SMel Gorman */ 64156de7263SMel Gorman static int __fragmentation_index(unsigned int order, struct contig_page_info *info) 642f1a5ab12SMel Gorman { 643f1a5ab12SMel Gorman unsigned long requested = 1UL << order; 644f1a5ab12SMel Gorman 645f1a5ab12SMel Gorman if (!info->free_blocks_total) 646f1a5ab12SMel Gorman return 0; 647f1a5ab12SMel Gorman 648f1a5ab12SMel Gorman /* Fragmentation index only makes sense when a request would fail */ 649f1a5ab12SMel Gorman if (info->free_blocks_suitable) 650f1a5ab12SMel Gorman return -1000; 651f1a5ab12SMel Gorman 652f1a5ab12SMel Gorman /* 653f1a5ab12SMel Gorman * Index is between 0 and 1 so return within 3 decimal places 654f1a5ab12SMel Gorman * 655f1a5ab12SMel Gorman * 0 => allocation would fail due to lack of memory 656f1a5ab12SMel Gorman * 1 => allocation would fail due to fragmentation 657f1a5ab12SMel Gorman */ 658f1a5ab12SMel Gorman return 1000 - div_u64( (1000+(div_u64(info->free_pages * 1000ULL, requested))), info->free_blocks_total); 659f1a5ab12SMel Gorman } 66056de7263SMel Gorman 66156de7263SMel Gorman /* Same as __fragmentation index but allocs contig_page_info on stack */ 66256de7263SMel Gorman int fragmentation_index(struct zone *zone, unsigned int order) 66356de7263SMel Gorman { 66456de7263SMel Gorman struct contig_page_info info; 66556de7263SMel Gorman 66656de7263SMel Gorman fill_contig_page_info(zone, order, &info); 66756de7263SMel Gorman return __fragmentation_index(order, &info); 66856de7263SMel Gorman } 669d7a5752cSMel Gorman #endif 670d7a5752cSMel Gorman 671d7a5752cSMel Gorman #if defined(CONFIG_PROC_FS) || defined(CONFIG_COMPACTION) 6728f32f7e5SAlexey Dobriyan #include <linux/proc_fs.h> 673f6ac2354SChristoph Lameter #include <linux/seq_file.h> 674f6ac2354SChristoph Lameter 675467c996cSMel Gorman static char * const migratetype_names[MIGRATE_TYPES] = { 676467c996cSMel Gorman "Unmovable", 677467c996cSMel Gorman "Reclaimable", 678467c996cSMel Gorman "Movable", 679467c996cSMel Gorman "Reserve", 68047118af0SMichal Nazarewicz #ifdef CONFIG_CMA 68147118af0SMichal Nazarewicz "CMA", 68247118af0SMichal Nazarewicz #endif 683194159fbSMinchan Kim #ifdef CONFIG_MEMORY_ISOLATION 68491446b06SKOSAKI Motohiro "Isolate", 685194159fbSMinchan Kim #endif 686467c996cSMel Gorman }; 687467c996cSMel Gorman 688f6ac2354SChristoph Lameter static void *frag_start(struct seq_file *m, loff_t *pos) 689f6ac2354SChristoph Lameter { 690f6ac2354SChristoph Lameter pg_data_t *pgdat; 691f6ac2354SChristoph Lameter loff_t node = *pos; 692f6ac2354SChristoph Lameter for (pgdat = first_online_pgdat(); 693f6ac2354SChristoph Lameter pgdat && node; 694f6ac2354SChristoph Lameter pgdat = next_online_pgdat(pgdat)) 695f6ac2354SChristoph Lameter --node; 696f6ac2354SChristoph Lameter 697f6ac2354SChristoph Lameter return pgdat; 698f6ac2354SChristoph Lameter } 699f6ac2354SChristoph Lameter 700f6ac2354SChristoph Lameter static void *frag_next(struct seq_file *m, void *arg, loff_t *pos) 701f6ac2354SChristoph Lameter { 702f6ac2354SChristoph Lameter pg_data_t *pgdat = (pg_data_t *)arg; 703f6ac2354SChristoph Lameter 704f6ac2354SChristoph Lameter (*pos)++; 705f6ac2354SChristoph Lameter return next_online_pgdat(pgdat); 706f6ac2354SChristoph Lameter } 707f6ac2354SChristoph Lameter 708f6ac2354SChristoph Lameter static void frag_stop(struct seq_file *m, void *arg) 709f6ac2354SChristoph Lameter { 710f6ac2354SChristoph Lameter } 711f6ac2354SChristoph Lameter 712467c996cSMel Gorman /* Walk all the zones in a node and print using a callback */ 713467c996cSMel Gorman static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat, 714467c996cSMel Gorman void (*print)(struct seq_file *m, pg_data_t *, struct zone *)) 715f6ac2354SChristoph Lameter { 716f6ac2354SChristoph Lameter struct zone *zone; 717f6ac2354SChristoph Lameter struct zone *node_zones = pgdat->node_zones; 718f6ac2354SChristoph Lameter unsigned long flags; 719f6ac2354SChristoph Lameter 720f6ac2354SChristoph Lameter for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { 721f6ac2354SChristoph Lameter if (!populated_zone(zone)) 722f6ac2354SChristoph Lameter continue; 723f6ac2354SChristoph Lameter 724f6ac2354SChristoph Lameter spin_lock_irqsave(&zone->lock, flags); 725467c996cSMel Gorman print(m, pgdat, zone); 726467c996cSMel Gorman spin_unlock_irqrestore(&zone->lock, flags); 727467c996cSMel Gorman } 728467c996cSMel Gorman } 729d7a5752cSMel Gorman #endif 730467c996cSMel Gorman 7310d6617c7SDavid Rientjes #if defined(CONFIG_PROC_FS) || defined(CONFIG_SYSFS) || defined(CONFIG_NUMA) 732fa25c503SKOSAKI Motohiro #ifdef CONFIG_ZONE_DMA 733fa25c503SKOSAKI Motohiro #define TEXT_FOR_DMA(xx) xx "_dma", 734fa25c503SKOSAKI Motohiro #else 735fa25c503SKOSAKI Motohiro #define TEXT_FOR_DMA(xx) 736fa25c503SKOSAKI Motohiro #endif 737fa25c503SKOSAKI Motohiro 738fa25c503SKOSAKI Motohiro #ifdef CONFIG_ZONE_DMA32 739fa25c503SKOSAKI Motohiro #define TEXT_FOR_DMA32(xx) xx "_dma32", 740fa25c503SKOSAKI Motohiro #else 741fa25c503SKOSAKI Motohiro #define TEXT_FOR_DMA32(xx) 742fa25c503SKOSAKI Motohiro #endif 743fa25c503SKOSAKI Motohiro 744fa25c503SKOSAKI Motohiro #ifdef CONFIG_HIGHMEM 745fa25c503SKOSAKI Motohiro #define TEXT_FOR_HIGHMEM(xx) xx "_high", 746fa25c503SKOSAKI Motohiro #else 747fa25c503SKOSAKI Motohiro #define TEXT_FOR_HIGHMEM(xx) 748fa25c503SKOSAKI Motohiro #endif 749fa25c503SKOSAKI Motohiro 750fa25c503SKOSAKI Motohiro #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \ 751fa25c503SKOSAKI Motohiro TEXT_FOR_HIGHMEM(xx) xx "_movable", 752fa25c503SKOSAKI Motohiro 753fa25c503SKOSAKI Motohiro const char * const vmstat_text[] = { 75409316c09SKonstantin Khlebnikov /* enum zone_stat_item countes */ 755fa25c503SKOSAKI Motohiro "nr_free_pages", 75681c0a2bbSJohannes Weiner "nr_alloc_batch", 757fa25c503SKOSAKI Motohiro "nr_inactive_anon", 758fa25c503SKOSAKI Motohiro "nr_active_anon", 759fa25c503SKOSAKI Motohiro "nr_inactive_file", 760fa25c503SKOSAKI Motohiro "nr_active_file", 761fa25c503SKOSAKI Motohiro "nr_unevictable", 762fa25c503SKOSAKI Motohiro "nr_mlock", 763fa25c503SKOSAKI Motohiro "nr_anon_pages", 764fa25c503SKOSAKI Motohiro "nr_mapped", 765fa25c503SKOSAKI Motohiro "nr_file_pages", 766fa25c503SKOSAKI Motohiro "nr_dirty", 767fa25c503SKOSAKI Motohiro "nr_writeback", 768fa25c503SKOSAKI Motohiro "nr_slab_reclaimable", 769fa25c503SKOSAKI Motohiro "nr_slab_unreclaimable", 770fa25c503SKOSAKI Motohiro "nr_page_table_pages", 771fa25c503SKOSAKI Motohiro "nr_kernel_stack", 772fa25c503SKOSAKI Motohiro "nr_unstable", 773fa25c503SKOSAKI Motohiro "nr_bounce", 774fa25c503SKOSAKI Motohiro "nr_vmscan_write", 77549ea7eb6SMel Gorman "nr_vmscan_immediate_reclaim", 776fa25c503SKOSAKI Motohiro "nr_writeback_temp", 777fa25c503SKOSAKI Motohiro "nr_isolated_anon", 778fa25c503SKOSAKI Motohiro "nr_isolated_file", 779fa25c503SKOSAKI Motohiro "nr_shmem", 780fa25c503SKOSAKI Motohiro "nr_dirtied", 781fa25c503SKOSAKI Motohiro "nr_written", 7820d5d823aSMel Gorman "nr_pages_scanned", 783fa25c503SKOSAKI Motohiro 784fa25c503SKOSAKI Motohiro #ifdef CONFIG_NUMA 785fa25c503SKOSAKI Motohiro "numa_hit", 786fa25c503SKOSAKI Motohiro "numa_miss", 787fa25c503SKOSAKI Motohiro "numa_foreign", 788fa25c503SKOSAKI Motohiro "numa_interleave", 789fa25c503SKOSAKI Motohiro "numa_local", 790fa25c503SKOSAKI Motohiro "numa_other", 791fa25c503SKOSAKI Motohiro #endif 792a528910eSJohannes Weiner "workingset_refault", 793a528910eSJohannes Weiner "workingset_activate", 794449dd698SJohannes Weiner "workingset_nodereclaim", 795fa25c503SKOSAKI Motohiro "nr_anon_transparent_hugepages", 796d1ce749aSBartlomiej Zolnierkiewicz "nr_free_cma", 79709316c09SKonstantin Khlebnikov 79809316c09SKonstantin Khlebnikov /* enum writeback_stat_item counters */ 799fa25c503SKOSAKI Motohiro "nr_dirty_threshold", 800fa25c503SKOSAKI Motohiro "nr_dirty_background_threshold", 801fa25c503SKOSAKI Motohiro 802fa25c503SKOSAKI Motohiro #ifdef CONFIG_VM_EVENT_COUNTERS 80309316c09SKonstantin Khlebnikov /* enum vm_event_item counters */ 804fa25c503SKOSAKI Motohiro "pgpgin", 805fa25c503SKOSAKI Motohiro "pgpgout", 806fa25c503SKOSAKI Motohiro "pswpin", 807fa25c503SKOSAKI Motohiro "pswpout", 808fa25c503SKOSAKI Motohiro 809fa25c503SKOSAKI Motohiro TEXTS_FOR_ZONES("pgalloc") 810fa25c503SKOSAKI Motohiro 811fa25c503SKOSAKI Motohiro "pgfree", 812fa25c503SKOSAKI Motohiro "pgactivate", 813fa25c503SKOSAKI Motohiro "pgdeactivate", 814fa25c503SKOSAKI Motohiro 815fa25c503SKOSAKI Motohiro "pgfault", 816fa25c503SKOSAKI Motohiro "pgmajfault", 817fa25c503SKOSAKI Motohiro 818fa25c503SKOSAKI Motohiro TEXTS_FOR_ZONES("pgrefill") 819904249aaSYing Han TEXTS_FOR_ZONES("pgsteal_kswapd") 820904249aaSYing Han TEXTS_FOR_ZONES("pgsteal_direct") 821fa25c503SKOSAKI Motohiro TEXTS_FOR_ZONES("pgscan_kswapd") 822fa25c503SKOSAKI Motohiro TEXTS_FOR_ZONES("pgscan_direct") 82368243e76SMel Gorman "pgscan_direct_throttle", 824fa25c503SKOSAKI Motohiro 825fa25c503SKOSAKI Motohiro #ifdef CONFIG_NUMA 826fa25c503SKOSAKI Motohiro "zone_reclaim_failed", 827fa25c503SKOSAKI Motohiro #endif 828fa25c503SKOSAKI Motohiro "pginodesteal", 829fa25c503SKOSAKI Motohiro "slabs_scanned", 830fa25c503SKOSAKI Motohiro "kswapd_inodesteal", 831fa25c503SKOSAKI Motohiro "kswapd_low_wmark_hit_quickly", 832fa25c503SKOSAKI Motohiro "kswapd_high_wmark_hit_quickly", 833fa25c503SKOSAKI Motohiro "pageoutrun", 834fa25c503SKOSAKI Motohiro "allocstall", 835fa25c503SKOSAKI Motohiro 836fa25c503SKOSAKI Motohiro "pgrotated", 837fa25c503SKOSAKI Motohiro 8385509a5d2SDave Hansen "drop_pagecache", 8395509a5d2SDave Hansen "drop_slab", 8405509a5d2SDave Hansen 84103c5a6e1SMel Gorman #ifdef CONFIG_NUMA_BALANCING 84203c5a6e1SMel Gorman "numa_pte_updates", 84372403b4aSMel Gorman "numa_huge_pte_updates", 84403c5a6e1SMel Gorman "numa_hint_faults", 84503c5a6e1SMel Gorman "numa_hint_faults_local", 84603c5a6e1SMel Gorman "numa_pages_migrated", 84703c5a6e1SMel Gorman #endif 8485647bc29SMel Gorman #ifdef CONFIG_MIGRATION 8495647bc29SMel Gorman "pgmigrate_success", 8505647bc29SMel Gorman "pgmigrate_fail", 8515647bc29SMel Gorman #endif 852fa25c503SKOSAKI Motohiro #ifdef CONFIG_COMPACTION 853397487dbSMel Gorman "compact_migrate_scanned", 854397487dbSMel Gorman "compact_free_scanned", 855397487dbSMel Gorman "compact_isolated", 856fa25c503SKOSAKI Motohiro "compact_stall", 857fa25c503SKOSAKI Motohiro "compact_fail", 858fa25c503SKOSAKI Motohiro "compact_success", 859fa25c503SKOSAKI Motohiro #endif 860fa25c503SKOSAKI Motohiro 861fa25c503SKOSAKI Motohiro #ifdef CONFIG_HUGETLB_PAGE 862fa25c503SKOSAKI Motohiro "htlb_buddy_alloc_success", 863fa25c503SKOSAKI Motohiro "htlb_buddy_alloc_fail", 864fa25c503SKOSAKI Motohiro #endif 865fa25c503SKOSAKI Motohiro "unevictable_pgs_culled", 866fa25c503SKOSAKI Motohiro "unevictable_pgs_scanned", 867fa25c503SKOSAKI Motohiro "unevictable_pgs_rescued", 868fa25c503SKOSAKI Motohiro "unevictable_pgs_mlocked", 869fa25c503SKOSAKI Motohiro "unevictable_pgs_munlocked", 870fa25c503SKOSAKI Motohiro "unevictable_pgs_cleared", 871fa25c503SKOSAKI Motohiro "unevictable_pgs_stranded", 872fa25c503SKOSAKI Motohiro 873fa25c503SKOSAKI Motohiro #ifdef CONFIG_TRANSPARENT_HUGEPAGE 874fa25c503SKOSAKI Motohiro "thp_fault_alloc", 875fa25c503SKOSAKI Motohiro "thp_fault_fallback", 876fa25c503SKOSAKI Motohiro "thp_collapse_alloc", 877fa25c503SKOSAKI Motohiro "thp_collapse_alloc_failed", 878fa25c503SKOSAKI Motohiro "thp_split", 879d8a8e1f0SKirill A. Shutemov "thp_zero_page_alloc", 880d8a8e1f0SKirill A. Shutemov "thp_zero_page_alloc_failed", 881fa25c503SKOSAKI Motohiro #endif 88209316c09SKonstantin Khlebnikov #ifdef CONFIG_MEMORY_BALLOON 88309316c09SKonstantin Khlebnikov "balloon_inflate", 88409316c09SKonstantin Khlebnikov "balloon_deflate", 88509316c09SKonstantin Khlebnikov #ifdef CONFIG_BALLOON_COMPACTION 88609316c09SKonstantin Khlebnikov "balloon_migrate", 88709316c09SKonstantin Khlebnikov #endif 88809316c09SKonstantin Khlebnikov #endif /* CONFIG_MEMORY_BALLOON */ 889ec659934SMel Gorman #ifdef CONFIG_DEBUG_TLBFLUSH 8906df46865SDave Hansen #ifdef CONFIG_SMP 8919824cf97SDave Hansen "nr_tlb_remote_flush", 8929824cf97SDave Hansen "nr_tlb_remote_flush_received", 893ec659934SMel Gorman #endif /* CONFIG_SMP */ 8949824cf97SDave Hansen "nr_tlb_local_flush_all", 8959824cf97SDave Hansen "nr_tlb_local_flush_one", 896ec659934SMel Gorman #endif /* CONFIG_DEBUG_TLBFLUSH */ 897fa25c503SKOSAKI Motohiro 8984f115147SDavidlohr Bueso #ifdef CONFIG_DEBUG_VM_VMACACHE 8994f115147SDavidlohr Bueso "vmacache_find_calls", 9004f115147SDavidlohr Bueso "vmacache_find_hits", 9014f115147SDavidlohr Bueso #endif 902fa25c503SKOSAKI Motohiro #endif /* CONFIG_VM_EVENTS_COUNTERS */ 903fa25c503SKOSAKI Motohiro }; 9040d6617c7SDavid Rientjes #endif /* CONFIG_PROC_FS || CONFIG_SYSFS || CONFIG_NUMA */ 905fa25c503SKOSAKI Motohiro 906fa25c503SKOSAKI Motohiro 907d7a5752cSMel Gorman #ifdef CONFIG_PROC_FS 908467c996cSMel Gorman static void frag_show_print(struct seq_file *m, pg_data_t *pgdat, 909467c996cSMel Gorman struct zone *zone) 910467c996cSMel Gorman { 911467c996cSMel Gorman int order; 912467c996cSMel Gorman 913f6ac2354SChristoph Lameter seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); 914f6ac2354SChristoph Lameter for (order = 0; order < MAX_ORDER; ++order) 915f6ac2354SChristoph Lameter seq_printf(m, "%6lu ", zone->free_area[order].nr_free); 916f6ac2354SChristoph Lameter seq_putc(m, '\n'); 917f6ac2354SChristoph Lameter } 918467c996cSMel Gorman 919467c996cSMel Gorman /* 920467c996cSMel Gorman * This walks the free areas for each zone. 921467c996cSMel Gorman */ 922467c996cSMel Gorman static int frag_show(struct seq_file *m, void *arg) 923467c996cSMel Gorman { 924467c996cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 925467c996cSMel Gorman walk_zones_in_node(m, pgdat, frag_show_print); 926467c996cSMel Gorman return 0; 927467c996cSMel Gorman } 928467c996cSMel Gorman 929467c996cSMel Gorman static void pagetypeinfo_showfree_print(struct seq_file *m, 930467c996cSMel Gorman pg_data_t *pgdat, struct zone *zone) 931467c996cSMel Gorman { 932467c996cSMel Gorman int order, mtype; 933467c996cSMel Gorman 934467c996cSMel Gorman for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) { 935467c996cSMel Gorman seq_printf(m, "Node %4d, zone %8s, type %12s ", 936467c996cSMel Gorman pgdat->node_id, 937467c996cSMel Gorman zone->name, 938467c996cSMel Gorman migratetype_names[mtype]); 939467c996cSMel Gorman for (order = 0; order < MAX_ORDER; ++order) { 940467c996cSMel Gorman unsigned long freecount = 0; 941467c996cSMel Gorman struct free_area *area; 942467c996cSMel Gorman struct list_head *curr; 943467c996cSMel Gorman 944467c996cSMel Gorman area = &(zone->free_area[order]); 945467c996cSMel Gorman 946467c996cSMel Gorman list_for_each(curr, &area->free_list[mtype]) 947467c996cSMel Gorman freecount++; 948467c996cSMel Gorman seq_printf(m, "%6lu ", freecount); 949467c996cSMel Gorman } 950467c996cSMel Gorman seq_putc(m, '\n'); 951467c996cSMel Gorman } 952467c996cSMel Gorman } 953467c996cSMel Gorman 954467c996cSMel Gorman /* Print out the free pages at each order for each migatetype */ 955467c996cSMel Gorman static int pagetypeinfo_showfree(struct seq_file *m, void *arg) 956467c996cSMel Gorman { 957467c996cSMel Gorman int order; 958467c996cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 959467c996cSMel Gorman 960467c996cSMel Gorman /* Print header */ 961467c996cSMel Gorman seq_printf(m, "%-43s ", "Free pages count per migrate type at order"); 962467c996cSMel Gorman for (order = 0; order < MAX_ORDER; ++order) 963467c996cSMel Gorman seq_printf(m, "%6d ", order); 964467c996cSMel Gorman seq_putc(m, '\n'); 965467c996cSMel Gorman 966467c996cSMel Gorman walk_zones_in_node(m, pgdat, pagetypeinfo_showfree_print); 967467c996cSMel Gorman 968467c996cSMel Gorman return 0; 969467c996cSMel Gorman } 970467c996cSMel Gorman 971467c996cSMel Gorman static void pagetypeinfo_showblockcount_print(struct seq_file *m, 972467c996cSMel Gorman pg_data_t *pgdat, struct zone *zone) 973467c996cSMel Gorman { 974467c996cSMel Gorman int mtype; 975467c996cSMel Gorman unsigned long pfn; 976467c996cSMel Gorman unsigned long start_pfn = zone->zone_start_pfn; 977108bcc96SCody P Schafer unsigned long end_pfn = zone_end_pfn(zone); 978467c996cSMel Gorman unsigned long count[MIGRATE_TYPES] = { 0, }; 979467c996cSMel Gorman 980467c996cSMel Gorman for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { 981467c996cSMel Gorman struct page *page; 982467c996cSMel Gorman 983467c996cSMel Gorman if (!pfn_valid(pfn)) 984467c996cSMel Gorman continue; 985467c996cSMel Gorman 986467c996cSMel Gorman page = pfn_to_page(pfn); 987eb33575cSMel Gorman 988eb33575cSMel Gorman /* Watch for unexpected holes punched in the memmap */ 989eb33575cSMel Gorman if (!memmap_valid_within(pfn, page, zone)) 990e80d6a24SMel Gorman continue; 991eb33575cSMel Gorman 992467c996cSMel Gorman mtype = get_pageblock_migratetype(page); 993467c996cSMel Gorman 994e80d6a24SMel Gorman if (mtype < MIGRATE_TYPES) 995467c996cSMel Gorman count[mtype]++; 996467c996cSMel Gorman } 997467c996cSMel Gorman 998467c996cSMel Gorman /* Print counts */ 999467c996cSMel Gorman seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); 1000467c996cSMel Gorman for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) 1001467c996cSMel Gorman seq_printf(m, "%12lu ", count[mtype]); 1002467c996cSMel Gorman seq_putc(m, '\n'); 1003467c996cSMel Gorman } 1004467c996cSMel Gorman 1005467c996cSMel Gorman /* Print out the free pages at each order for each migratetype */ 1006467c996cSMel Gorman static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg) 1007467c996cSMel Gorman { 1008467c996cSMel Gorman int mtype; 1009467c996cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 1010467c996cSMel Gorman 1011467c996cSMel Gorman seq_printf(m, "\n%-23s", "Number of blocks type "); 1012467c996cSMel Gorman for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) 1013467c996cSMel Gorman seq_printf(m, "%12s ", migratetype_names[mtype]); 1014467c996cSMel Gorman seq_putc(m, '\n'); 1015467c996cSMel Gorman walk_zones_in_node(m, pgdat, pagetypeinfo_showblockcount_print); 1016467c996cSMel Gorman 1017467c996cSMel Gorman return 0; 1018467c996cSMel Gorman } 1019467c996cSMel Gorman 1020467c996cSMel Gorman /* 1021467c996cSMel Gorman * This prints out statistics in relation to grouping pages by mobility. 1022467c996cSMel Gorman * It is expensive to collect so do not constantly read the file. 1023467c996cSMel Gorman */ 1024467c996cSMel Gorman static int pagetypeinfo_show(struct seq_file *m, void *arg) 1025467c996cSMel Gorman { 1026467c996cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 1027467c996cSMel Gorman 102841b25a37SKOSAKI Motohiro /* check memoryless node */ 1029a47b53c5SLai Jiangshan if (!node_state(pgdat->node_id, N_MEMORY)) 103041b25a37SKOSAKI Motohiro return 0; 103141b25a37SKOSAKI Motohiro 1032467c996cSMel Gorman seq_printf(m, "Page block order: %d\n", pageblock_order); 1033467c996cSMel Gorman seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages); 1034467c996cSMel Gorman seq_putc(m, '\n'); 1035467c996cSMel Gorman pagetypeinfo_showfree(m, pgdat); 1036467c996cSMel Gorman pagetypeinfo_showblockcount(m, pgdat); 1037467c996cSMel Gorman 1038f6ac2354SChristoph Lameter return 0; 1039f6ac2354SChristoph Lameter } 1040f6ac2354SChristoph Lameter 10418f32f7e5SAlexey Dobriyan static const struct seq_operations fragmentation_op = { 1042f6ac2354SChristoph Lameter .start = frag_start, 1043f6ac2354SChristoph Lameter .next = frag_next, 1044f6ac2354SChristoph Lameter .stop = frag_stop, 1045f6ac2354SChristoph Lameter .show = frag_show, 1046f6ac2354SChristoph Lameter }; 1047f6ac2354SChristoph Lameter 10488f32f7e5SAlexey Dobriyan static int fragmentation_open(struct inode *inode, struct file *file) 10498f32f7e5SAlexey Dobriyan { 10508f32f7e5SAlexey Dobriyan return seq_open(file, &fragmentation_op); 10518f32f7e5SAlexey Dobriyan } 10528f32f7e5SAlexey Dobriyan 10538f32f7e5SAlexey Dobriyan static const struct file_operations fragmentation_file_operations = { 10548f32f7e5SAlexey Dobriyan .open = fragmentation_open, 10558f32f7e5SAlexey Dobriyan .read = seq_read, 10568f32f7e5SAlexey Dobriyan .llseek = seq_lseek, 10578f32f7e5SAlexey Dobriyan .release = seq_release, 10588f32f7e5SAlexey Dobriyan }; 10598f32f7e5SAlexey Dobriyan 106074e2e8e8SAlexey Dobriyan static const struct seq_operations pagetypeinfo_op = { 1061467c996cSMel Gorman .start = frag_start, 1062467c996cSMel Gorman .next = frag_next, 1063467c996cSMel Gorman .stop = frag_stop, 1064467c996cSMel Gorman .show = pagetypeinfo_show, 1065467c996cSMel Gorman }; 1066467c996cSMel Gorman 106774e2e8e8SAlexey Dobriyan static int pagetypeinfo_open(struct inode *inode, struct file *file) 106874e2e8e8SAlexey Dobriyan { 106974e2e8e8SAlexey Dobriyan return seq_open(file, &pagetypeinfo_op); 107074e2e8e8SAlexey Dobriyan } 107174e2e8e8SAlexey Dobriyan 107274e2e8e8SAlexey Dobriyan static const struct file_operations pagetypeinfo_file_ops = { 107374e2e8e8SAlexey Dobriyan .open = pagetypeinfo_open, 107474e2e8e8SAlexey Dobriyan .read = seq_read, 107574e2e8e8SAlexey Dobriyan .llseek = seq_lseek, 107674e2e8e8SAlexey Dobriyan .release = seq_release, 107774e2e8e8SAlexey Dobriyan }; 107874e2e8e8SAlexey Dobriyan 1079467c996cSMel Gorman static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat, 1080467c996cSMel Gorman struct zone *zone) 1081f6ac2354SChristoph Lameter { 1082f6ac2354SChristoph Lameter int i; 1083f6ac2354SChristoph Lameter seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name); 1084f6ac2354SChristoph Lameter seq_printf(m, 1085f6ac2354SChristoph Lameter "\n pages free %lu" 1086f6ac2354SChristoph Lameter "\n min %lu" 1087f6ac2354SChristoph Lameter "\n low %lu" 1088f6ac2354SChristoph Lameter "\n high %lu" 108908d9ae7cSWu Fengguang "\n scanned %lu" 1090f6ac2354SChristoph Lameter "\n spanned %lu" 10919feedc9dSJiang Liu "\n present %lu" 10929feedc9dSJiang Liu "\n managed %lu", 109388f5acf8SMel Gorman zone_page_state(zone, NR_FREE_PAGES), 109441858966SMel Gorman min_wmark_pages(zone), 109541858966SMel Gorman low_wmark_pages(zone), 109641858966SMel Gorman high_wmark_pages(zone), 10970d5d823aSMel Gorman zone_page_state(zone, NR_PAGES_SCANNED), 1098f6ac2354SChristoph Lameter zone->spanned_pages, 10999feedc9dSJiang Liu zone->present_pages, 11009feedc9dSJiang Liu zone->managed_pages); 11012244b95aSChristoph Lameter 11022244b95aSChristoph Lameter for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) 11032244b95aSChristoph Lameter seq_printf(m, "\n %-12s %lu", vmstat_text[i], 11042244b95aSChristoph Lameter zone_page_state(zone, i)); 11052244b95aSChristoph Lameter 1106f6ac2354SChristoph Lameter seq_printf(m, 11073484b2deSMel Gorman "\n protection: (%ld", 1108f6ac2354SChristoph Lameter zone->lowmem_reserve[0]); 1109f6ac2354SChristoph Lameter for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++) 11103484b2deSMel Gorman seq_printf(m, ", %ld", zone->lowmem_reserve[i]); 1111f6ac2354SChristoph Lameter seq_printf(m, 1112f6ac2354SChristoph Lameter ")" 1113f6ac2354SChristoph Lameter "\n pagesets"); 1114f6ac2354SChristoph Lameter for_each_online_cpu(i) { 1115f6ac2354SChristoph Lameter struct per_cpu_pageset *pageset; 1116f6ac2354SChristoph Lameter 111799dcc3e5SChristoph Lameter pageset = per_cpu_ptr(zone->pageset, i); 1118f6ac2354SChristoph Lameter seq_printf(m, 11193dfa5721SChristoph Lameter "\n cpu: %i" 1120f6ac2354SChristoph Lameter "\n count: %i" 1121f6ac2354SChristoph Lameter "\n high: %i" 1122f6ac2354SChristoph Lameter "\n batch: %i", 11233dfa5721SChristoph Lameter i, 11243dfa5721SChristoph Lameter pageset->pcp.count, 11253dfa5721SChristoph Lameter pageset->pcp.high, 11263dfa5721SChristoph Lameter pageset->pcp.batch); 1127df9ecabaSChristoph Lameter #ifdef CONFIG_SMP 1128df9ecabaSChristoph Lameter seq_printf(m, "\n vm stats threshold: %d", 1129df9ecabaSChristoph Lameter pageset->stat_threshold); 1130df9ecabaSChristoph Lameter #endif 1131f6ac2354SChristoph Lameter } 1132f6ac2354SChristoph Lameter seq_printf(m, 1133f6ac2354SChristoph Lameter "\n all_unreclaimable: %u" 1134556adecbSRik van Riel "\n start_pfn: %lu" 1135556adecbSRik van Riel "\n inactive_ratio: %u", 11366e543d57SLisa Du !zone_reclaimable(zone), 1137556adecbSRik van Riel zone->zone_start_pfn, 1138556adecbSRik van Riel zone->inactive_ratio); 1139f6ac2354SChristoph Lameter seq_putc(m, '\n'); 1140f6ac2354SChristoph Lameter } 1141467c996cSMel Gorman 1142467c996cSMel Gorman /* 1143467c996cSMel Gorman * Output information about zones in @pgdat. 1144467c996cSMel Gorman */ 1145467c996cSMel Gorman static int zoneinfo_show(struct seq_file *m, void *arg) 1146467c996cSMel Gorman { 1147467c996cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 1148467c996cSMel Gorman walk_zones_in_node(m, pgdat, zoneinfo_show_print); 1149f6ac2354SChristoph Lameter return 0; 1150f6ac2354SChristoph Lameter } 1151f6ac2354SChristoph Lameter 11525c9fe628SAlexey Dobriyan static const struct seq_operations zoneinfo_op = { 1153f6ac2354SChristoph Lameter .start = frag_start, /* iterate over all zones. The same as in 1154f6ac2354SChristoph Lameter * fragmentation. */ 1155f6ac2354SChristoph Lameter .next = frag_next, 1156f6ac2354SChristoph Lameter .stop = frag_stop, 1157f6ac2354SChristoph Lameter .show = zoneinfo_show, 1158f6ac2354SChristoph Lameter }; 1159f6ac2354SChristoph Lameter 11605c9fe628SAlexey Dobriyan static int zoneinfo_open(struct inode *inode, struct file *file) 11615c9fe628SAlexey Dobriyan { 11625c9fe628SAlexey Dobriyan return seq_open(file, &zoneinfo_op); 11635c9fe628SAlexey Dobriyan } 11645c9fe628SAlexey Dobriyan 11655c9fe628SAlexey Dobriyan static const struct file_operations proc_zoneinfo_file_operations = { 11665c9fe628SAlexey Dobriyan .open = zoneinfo_open, 11675c9fe628SAlexey Dobriyan .read = seq_read, 11685c9fe628SAlexey Dobriyan .llseek = seq_lseek, 11695c9fe628SAlexey Dobriyan .release = seq_release, 11705c9fe628SAlexey Dobriyan }; 11715c9fe628SAlexey Dobriyan 117279da826aSMichael Rubin enum writeback_stat_item { 117379da826aSMichael Rubin NR_DIRTY_THRESHOLD, 117479da826aSMichael Rubin NR_DIRTY_BG_THRESHOLD, 117579da826aSMichael Rubin NR_VM_WRITEBACK_STAT_ITEMS, 117679da826aSMichael Rubin }; 117779da826aSMichael Rubin 1178f6ac2354SChristoph Lameter static void *vmstat_start(struct seq_file *m, loff_t *pos) 1179f6ac2354SChristoph Lameter { 11802244b95aSChristoph Lameter unsigned long *v; 118179da826aSMichael Rubin int i, stat_items_size; 1182f6ac2354SChristoph Lameter 1183f6ac2354SChristoph Lameter if (*pos >= ARRAY_SIZE(vmstat_text)) 1184f6ac2354SChristoph Lameter return NULL; 118579da826aSMichael Rubin stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) + 118679da826aSMichael Rubin NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long); 1187f6ac2354SChristoph Lameter 1188f8891e5eSChristoph Lameter #ifdef CONFIG_VM_EVENT_COUNTERS 118979da826aSMichael Rubin stat_items_size += sizeof(struct vm_event_state); 1190f8891e5eSChristoph Lameter #endif 119179da826aSMichael Rubin 119279da826aSMichael Rubin v = kmalloc(stat_items_size, GFP_KERNEL); 11932244b95aSChristoph Lameter m->private = v; 11942244b95aSChristoph Lameter if (!v) 1195f6ac2354SChristoph Lameter return ERR_PTR(-ENOMEM); 11962244b95aSChristoph Lameter for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) 11972244b95aSChristoph Lameter v[i] = global_page_state(i); 119879da826aSMichael Rubin v += NR_VM_ZONE_STAT_ITEMS; 119979da826aSMichael Rubin 120079da826aSMichael Rubin global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, 120179da826aSMichael Rubin v + NR_DIRTY_THRESHOLD); 120279da826aSMichael Rubin v += NR_VM_WRITEBACK_STAT_ITEMS; 120379da826aSMichael Rubin 1204f8891e5eSChristoph Lameter #ifdef CONFIG_VM_EVENT_COUNTERS 120579da826aSMichael Rubin all_vm_events(v); 120679da826aSMichael Rubin v[PGPGIN] /= 2; /* sectors -> kbytes */ 120779da826aSMichael Rubin v[PGPGOUT] /= 2; 1208f8891e5eSChristoph Lameter #endif 1209ff8b16d7SWu Fengguang return (unsigned long *)m->private + *pos; 1210f6ac2354SChristoph Lameter } 1211f6ac2354SChristoph Lameter 1212f6ac2354SChristoph Lameter static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) 1213f6ac2354SChristoph Lameter { 1214f6ac2354SChristoph Lameter (*pos)++; 1215f6ac2354SChristoph Lameter if (*pos >= ARRAY_SIZE(vmstat_text)) 1216f6ac2354SChristoph Lameter return NULL; 1217f6ac2354SChristoph Lameter return (unsigned long *)m->private + *pos; 1218f6ac2354SChristoph Lameter } 1219f6ac2354SChristoph Lameter 1220f6ac2354SChristoph Lameter static int vmstat_show(struct seq_file *m, void *arg) 1221f6ac2354SChristoph Lameter { 1222f6ac2354SChristoph Lameter unsigned long *l = arg; 1223f6ac2354SChristoph Lameter unsigned long off = l - (unsigned long *)m->private; 1224f6ac2354SChristoph Lameter 1225f6ac2354SChristoph Lameter seq_printf(m, "%s %lu\n", vmstat_text[off], *l); 1226f6ac2354SChristoph Lameter return 0; 1227f6ac2354SChristoph Lameter } 1228f6ac2354SChristoph Lameter 1229f6ac2354SChristoph Lameter static void vmstat_stop(struct seq_file *m, void *arg) 1230f6ac2354SChristoph Lameter { 1231f6ac2354SChristoph Lameter kfree(m->private); 1232f6ac2354SChristoph Lameter m->private = NULL; 1233f6ac2354SChristoph Lameter } 1234f6ac2354SChristoph Lameter 1235b6aa44abSAlexey Dobriyan static const struct seq_operations vmstat_op = { 1236f6ac2354SChristoph Lameter .start = vmstat_start, 1237f6ac2354SChristoph Lameter .next = vmstat_next, 1238f6ac2354SChristoph Lameter .stop = vmstat_stop, 1239f6ac2354SChristoph Lameter .show = vmstat_show, 1240f6ac2354SChristoph Lameter }; 1241f6ac2354SChristoph Lameter 1242b6aa44abSAlexey Dobriyan static int vmstat_open(struct inode *inode, struct file *file) 1243b6aa44abSAlexey Dobriyan { 1244b6aa44abSAlexey Dobriyan return seq_open(file, &vmstat_op); 1245b6aa44abSAlexey Dobriyan } 1246b6aa44abSAlexey Dobriyan 1247b6aa44abSAlexey Dobriyan static const struct file_operations proc_vmstat_file_operations = { 1248b6aa44abSAlexey Dobriyan .open = vmstat_open, 1249b6aa44abSAlexey Dobriyan .read = seq_read, 1250b6aa44abSAlexey Dobriyan .llseek = seq_lseek, 1251b6aa44abSAlexey Dobriyan .release = seq_release, 1252b6aa44abSAlexey Dobriyan }; 1253f6ac2354SChristoph Lameter #endif /* CONFIG_PROC_FS */ 1254f6ac2354SChristoph Lameter 1255df9ecabaSChristoph Lameter #ifdef CONFIG_SMP 1256d1187ed2SChristoph Lameter static DEFINE_PER_CPU(struct delayed_work, vmstat_work); 125777461ab3SChristoph Lameter int sysctl_stat_interval __read_mostly = HZ; 1258*7cc36bbdSChristoph Lameter static cpumask_var_t cpu_stat_off; 1259d1187ed2SChristoph Lameter 1260d1187ed2SChristoph Lameter static void vmstat_update(struct work_struct *w) 1261d1187ed2SChristoph Lameter { 1262*7cc36bbdSChristoph Lameter if (refresh_cpu_vm_stats()) 1263*7cc36bbdSChristoph Lameter /* 1264*7cc36bbdSChristoph Lameter * Counters were updated so we expect more updates 1265*7cc36bbdSChristoph Lameter * to occur in the future. Keep on running the 1266*7cc36bbdSChristoph Lameter * update worker thread. 1267*7cc36bbdSChristoph Lameter */ 12687c8e0181SChristoph Lameter schedule_delayed_work(this_cpu_ptr(&vmstat_work), 126998f4ebb2SAnton Blanchard round_jiffies_relative(sysctl_stat_interval)); 1270*7cc36bbdSChristoph Lameter else { 1271*7cc36bbdSChristoph Lameter /* 1272*7cc36bbdSChristoph Lameter * We did not update any counters so the app may be in 1273*7cc36bbdSChristoph Lameter * a mode where it does not cause counter updates. 1274*7cc36bbdSChristoph Lameter * We may be uselessly running vmstat_update. 1275*7cc36bbdSChristoph Lameter * Defer the checking for differentials to the 1276*7cc36bbdSChristoph Lameter * shepherd thread on a different processor. 1277*7cc36bbdSChristoph Lameter */ 1278*7cc36bbdSChristoph Lameter int r; 1279*7cc36bbdSChristoph Lameter /* 1280*7cc36bbdSChristoph Lameter * Shepherd work thread does not race since it never 1281*7cc36bbdSChristoph Lameter * changes the bit if its zero but the cpu 1282*7cc36bbdSChristoph Lameter * online / off line code may race if 1283*7cc36bbdSChristoph Lameter * worker threads are still allowed during 1284*7cc36bbdSChristoph Lameter * shutdown / startup. 1285*7cc36bbdSChristoph Lameter */ 1286*7cc36bbdSChristoph Lameter r = cpumask_test_and_set_cpu(smp_processor_id(), 1287*7cc36bbdSChristoph Lameter cpu_stat_off); 1288*7cc36bbdSChristoph Lameter VM_BUG_ON(r); 1289*7cc36bbdSChristoph Lameter } 1290d1187ed2SChristoph Lameter } 1291d1187ed2SChristoph Lameter 1292*7cc36bbdSChristoph Lameter /* 1293*7cc36bbdSChristoph Lameter * Check if the diffs for a certain cpu indicate that 1294*7cc36bbdSChristoph Lameter * an update is needed. 1295*7cc36bbdSChristoph Lameter */ 1296*7cc36bbdSChristoph Lameter static bool need_update(int cpu) 1297d1187ed2SChristoph Lameter { 1298*7cc36bbdSChristoph Lameter struct zone *zone; 1299d1187ed2SChristoph Lameter 1300*7cc36bbdSChristoph Lameter for_each_populated_zone(zone) { 1301*7cc36bbdSChristoph Lameter struct per_cpu_pageset *p = per_cpu_ptr(zone->pageset, cpu); 1302*7cc36bbdSChristoph Lameter 1303*7cc36bbdSChristoph Lameter BUILD_BUG_ON(sizeof(p->vm_stat_diff[0]) != 1); 1304*7cc36bbdSChristoph Lameter /* 1305*7cc36bbdSChristoph Lameter * The fast way of checking if there are any vmstat diffs. 1306*7cc36bbdSChristoph Lameter * This works because the diffs are byte sized items. 1307*7cc36bbdSChristoph Lameter */ 1308*7cc36bbdSChristoph Lameter if (memchr_inv(p->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS)) 1309*7cc36bbdSChristoph Lameter return true; 1310*7cc36bbdSChristoph Lameter 1311*7cc36bbdSChristoph Lameter } 1312*7cc36bbdSChristoph Lameter return false; 1313*7cc36bbdSChristoph Lameter } 1314*7cc36bbdSChristoph Lameter 1315*7cc36bbdSChristoph Lameter 1316*7cc36bbdSChristoph Lameter /* 1317*7cc36bbdSChristoph Lameter * Shepherd worker thread that checks the 1318*7cc36bbdSChristoph Lameter * differentials of processors that have their worker 1319*7cc36bbdSChristoph Lameter * threads for vm statistics updates disabled because of 1320*7cc36bbdSChristoph Lameter * inactivity. 1321*7cc36bbdSChristoph Lameter */ 1322*7cc36bbdSChristoph Lameter static void vmstat_shepherd(struct work_struct *w); 1323*7cc36bbdSChristoph Lameter 1324*7cc36bbdSChristoph Lameter static DECLARE_DELAYED_WORK(shepherd, vmstat_shepherd); 1325*7cc36bbdSChristoph Lameter 1326*7cc36bbdSChristoph Lameter static void vmstat_shepherd(struct work_struct *w) 1327*7cc36bbdSChristoph Lameter { 1328*7cc36bbdSChristoph Lameter int cpu; 1329*7cc36bbdSChristoph Lameter 1330*7cc36bbdSChristoph Lameter get_online_cpus(); 1331*7cc36bbdSChristoph Lameter /* Check processors whose vmstat worker threads have been disabled */ 1332*7cc36bbdSChristoph Lameter for_each_cpu(cpu, cpu_stat_off) 1333*7cc36bbdSChristoph Lameter if (need_update(cpu) && 1334*7cc36bbdSChristoph Lameter cpumask_test_and_clear_cpu(cpu, cpu_stat_off)) 1335*7cc36bbdSChristoph Lameter 1336*7cc36bbdSChristoph Lameter schedule_delayed_work_on(cpu, &per_cpu(vmstat_work, cpu), 1337*7cc36bbdSChristoph Lameter __round_jiffies_relative(sysctl_stat_interval, cpu)); 1338*7cc36bbdSChristoph Lameter 1339*7cc36bbdSChristoph Lameter put_online_cpus(); 1340*7cc36bbdSChristoph Lameter 1341*7cc36bbdSChristoph Lameter schedule_delayed_work(&shepherd, 1342*7cc36bbdSChristoph Lameter round_jiffies_relative(sysctl_stat_interval)); 1343*7cc36bbdSChristoph Lameter 1344*7cc36bbdSChristoph Lameter } 1345*7cc36bbdSChristoph Lameter 1346*7cc36bbdSChristoph Lameter static void __init start_shepherd_timer(void) 1347*7cc36bbdSChristoph Lameter { 1348*7cc36bbdSChristoph Lameter int cpu; 1349*7cc36bbdSChristoph Lameter 1350*7cc36bbdSChristoph Lameter for_each_possible_cpu(cpu) 1351*7cc36bbdSChristoph Lameter INIT_DEFERRABLE_WORK(per_cpu_ptr(&vmstat_work, cpu), 1352*7cc36bbdSChristoph Lameter vmstat_update); 1353*7cc36bbdSChristoph Lameter 1354*7cc36bbdSChristoph Lameter if (!alloc_cpumask_var(&cpu_stat_off, GFP_KERNEL)) 1355*7cc36bbdSChristoph Lameter BUG(); 1356*7cc36bbdSChristoph Lameter cpumask_copy(cpu_stat_off, cpu_online_mask); 1357*7cc36bbdSChristoph Lameter 1358*7cc36bbdSChristoph Lameter schedule_delayed_work(&shepherd, 1359*7cc36bbdSChristoph Lameter round_jiffies_relative(sysctl_stat_interval)); 1360d1187ed2SChristoph Lameter } 1361d1187ed2SChristoph Lameter 1362807a1bd2SToshi Kani static void vmstat_cpu_dead(int node) 1363807a1bd2SToshi Kani { 1364807a1bd2SToshi Kani int cpu; 1365807a1bd2SToshi Kani 1366807a1bd2SToshi Kani get_online_cpus(); 1367807a1bd2SToshi Kani for_each_online_cpu(cpu) 1368807a1bd2SToshi Kani if (cpu_to_node(cpu) == node) 1369807a1bd2SToshi Kani goto end; 1370807a1bd2SToshi Kani 1371807a1bd2SToshi Kani node_clear_state(node, N_CPU); 1372807a1bd2SToshi Kani end: 1373807a1bd2SToshi Kani put_online_cpus(); 1374807a1bd2SToshi Kani } 1375807a1bd2SToshi Kani 1376df9ecabaSChristoph Lameter /* 1377df9ecabaSChristoph Lameter * Use the cpu notifier to insure that the thresholds are recalculated 1378df9ecabaSChristoph Lameter * when necessary. 1379df9ecabaSChristoph Lameter */ 13800db0628dSPaul Gortmaker static int vmstat_cpuup_callback(struct notifier_block *nfb, 1381df9ecabaSChristoph Lameter unsigned long action, 1382df9ecabaSChristoph Lameter void *hcpu) 1383df9ecabaSChristoph Lameter { 1384d1187ed2SChristoph Lameter long cpu = (long)hcpu; 1385d1187ed2SChristoph Lameter 1386df9ecabaSChristoph Lameter switch (action) { 1387d1187ed2SChristoph Lameter case CPU_ONLINE: 1388d1187ed2SChristoph Lameter case CPU_ONLINE_FROZEN: 13895ee28a44SKAMEZAWA Hiroyuki refresh_zone_stat_thresholds(); 1390ad596925SChristoph Lameter node_set_state(cpu_to_node(cpu), N_CPU); 1391*7cc36bbdSChristoph Lameter cpumask_set_cpu(cpu, cpu_stat_off); 1392d1187ed2SChristoph Lameter break; 1393d1187ed2SChristoph Lameter case CPU_DOWN_PREPARE: 1394d1187ed2SChristoph Lameter case CPU_DOWN_PREPARE_FROZEN: 1395afe2c511STejun Heo cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu)); 1396*7cc36bbdSChristoph Lameter cpumask_clear_cpu(cpu, cpu_stat_off); 1397d1187ed2SChristoph Lameter break; 1398d1187ed2SChristoph Lameter case CPU_DOWN_FAILED: 1399d1187ed2SChristoph Lameter case CPU_DOWN_FAILED_FROZEN: 1400*7cc36bbdSChristoph Lameter cpumask_set_cpu(cpu, cpu_stat_off); 1401d1187ed2SChristoph Lameter break; 1402df9ecabaSChristoph Lameter case CPU_DEAD: 14038bb78442SRafael J. Wysocki case CPU_DEAD_FROZEN: 1404df9ecabaSChristoph Lameter refresh_zone_stat_thresholds(); 1405807a1bd2SToshi Kani vmstat_cpu_dead(cpu_to_node(cpu)); 1406df9ecabaSChristoph Lameter break; 1407df9ecabaSChristoph Lameter default: 1408df9ecabaSChristoph Lameter break; 1409df9ecabaSChristoph Lameter } 1410df9ecabaSChristoph Lameter return NOTIFY_OK; 1411df9ecabaSChristoph Lameter } 1412df9ecabaSChristoph Lameter 14130db0628dSPaul Gortmaker static struct notifier_block vmstat_notifier = 1414df9ecabaSChristoph Lameter { &vmstat_cpuup_callback, NULL, 0 }; 14158f32f7e5SAlexey Dobriyan #endif 1416df9ecabaSChristoph Lameter 1417e2fc88d0SAdrian Bunk static int __init setup_vmstat(void) 1418df9ecabaSChristoph Lameter { 14198f32f7e5SAlexey Dobriyan #ifdef CONFIG_SMP 14200be94badSSrivatsa S. Bhat cpu_notifier_register_begin(); 14210be94badSSrivatsa S. Bhat __register_cpu_notifier(&vmstat_notifier); 1422d1187ed2SChristoph Lameter 1423*7cc36bbdSChristoph Lameter start_shepherd_timer(); 14240be94badSSrivatsa S. Bhat cpu_notifier_register_done(); 14258f32f7e5SAlexey Dobriyan #endif 14268f32f7e5SAlexey Dobriyan #ifdef CONFIG_PROC_FS 14278f32f7e5SAlexey Dobriyan proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); 142874e2e8e8SAlexey Dobriyan proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); 1429b6aa44abSAlexey Dobriyan proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); 14305c9fe628SAlexey Dobriyan proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); 14318f32f7e5SAlexey Dobriyan #endif 1432df9ecabaSChristoph Lameter return 0; 1433df9ecabaSChristoph Lameter } 1434df9ecabaSChristoph Lameter module_init(setup_vmstat) 1435d7a5752cSMel Gorman 1436d7a5752cSMel Gorman #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION) 1437d7a5752cSMel Gorman #include <linux/debugfs.h> 1438d7a5752cSMel Gorman 1439d7a5752cSMel Gorman 1440d7a5752cSMel Gorman /* 1441d7a5752cSMel Gorman * Return an index indicating how much of the available free memory is 1442d7a5752cSMel Gorman * unusable for an allocation of the requested size. 1443d7a5752cSMel Gorman */ 1444d7a5752cSMel Gorman static int unusable_free_index(unsigned int order, 1445d7a5752cSMel Gorman struct contig_page_info *info) 1446d7a5752cSMel Gorman { 1447d7a5752cSMel Gorman /* No free memory is interpreted as all free memory is unusable */ 1448d7a5752cSMel Gorman if (info->free_pages == 0) 1449d7a5752cSMel Gorman return 1000; 1450d7a5752cSMel Gorman 1451d7a5752cSMel Gorman /* 1452d7a5752cSMel Gorman * Index should be a value between 0 and 1. Return a value to 3 1453d7a5752cSMel Gorman * decimal places. 1454d7a5752cSMel Gorman * 1455d7a5752cSMel Gorman * 0 => no fragmentation 1456d7a5752cSMel Gorman * 1 => high fragmentation 1457d7a5752cSMel Gorman */ 1458d7a5752cSMel Gorman return div_u64((info->free_pages - (info->free_blocks_suitable << order)) * 1000ULL, info->free_pages); 1459d7a5752cSMel Gorman 1460d7a5752cSMel Gorman } 1461d7a5752cSMel Gorman 1462d7a5752cSMel Gorman static void unusable_show_print(struct seq_file *m, 1463d7a5752cSMel Gorman pg_data_t *pgdat, struct zone *zone) 1464d7a5752cSMel Gorman { 1465d7a5752cSMel Gorman unsigned int order; 1466d7a5752cSMel Gorman int index; 1467d7a5752cSMel Gorman struct contig_page_info info; 1468d7a5752cSMel Gorman 1469d7a5752cSMel Gorman seq_printf(m, "Node %d, zone %8s ", 1470d7a5752cSMel Gorman pgdat->node_id, 1471d7a5752cSMel Gorman zone->name); 1472d7a5752cSMel Gorman for (order = 0; order < MAX_ORDER; ++order) { 1473d7a5752cSMel Gorman fill_contig_page_info(zone, order, &info); 1474d7a5752cSMel Gorman index = unusable_free_index(order, &info); 1475d7a5752cSMel Gorman seq_printf(m, "%d.%03d ", index / 1000, index % 1000); 1476d7a5752cSMel Gorman } 1477d7a5752cSMel Gorman 1478d7a5752cSMel Gorman seq_putc(m, '\n'); 1479d7a5752cSMel Gorman } 1480d7a5752cSMel Gorman 1481d7a5752cSMel Gorman /* 1482d7a5752cSMel Gorman * Display unusable free space index 1483d7a5752cSMel Gorman * 1484d7a5752cSMel Gorman * The unusable free space index measures how much of the available free 1485d7a5752cSMel Gorman * memory cannot be used to satisfy an allocation of a given size and is a 1486d7a5752cSMel Gorman * value between 0 and 1. The higher the value, the more of free memory is 1487d7a5752cSMel Gorman * unusable and by implication, the worse the external fragmentation is. This 1488d7a5752cSMel Gorman * can be expressed as a percentage by multiplying by 100. 1489d7a5752cSMel Gorman */ 1490d7a5752cSMel Gorman static int unusable_show(struct seq_file *m, void *arg) 1491d7a5752cSMel Gorman { 1492d7a5752cSMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 1493d7a5752cSMel Gorman 1494d7a5752cSMel Gorman /* check memoryless node */ 1495a47b53c5SLai Jiangshan if (!node_state(pgdat->node_id, N_MEMORY)) 1496d7a5752cSMel Gorman return 0; 1497d7a5752cSMel Gorman 1498d7a5752cSMel Gorman walk_zones_in_node(m, pgdat, unusable_show_print); 1499d7a5752cSMel Gorman 1500d7a5752cSMel Gorman return 0; 1501d7a5752cSMel Gorman } 1502d7a5752cSMel Gorman 1503d7a5752cSMel Gorman static const struct seq_operations unusable_op = { 1504d7a5752cSMel Gorman .start = frag_start, 1505d7a5752cSMel Gorman .next = frag_next, 1506d7a5752cSMel Gorman .stop = frag_stop, 1507d7a5752cSMel Gorman .show = unusable_show, 1508d7a5752cSMel Gorman }; 1509d7a5752cSMel Gorman 1510d7a5752cSMel Gorman static int unusable_open(struct inode *inode, struct file *file) 1511d7a5752cSMel Gorman { 1512d7a5752cSMel Gorman return seq_open(file, &unusable_op); 1513d7a5752cSMel Gorman } 1514d7a5752cSMel Gorman 1515d7a5752cSMel Gorman static const struct file_operations unusable_file_ops = { 1516d7a5752cSMel Gorman .open = unusable_open, 1517d7a5752cSMel Gorman .read = seq_read, 1518d7a5752cSMel Gorman .llseek = seq_lseek, 1519d7a5752cSMel Gorman .release = seq_release, 1520d7a5752cSMel Gorman }; 1521d7a5752cSMel Gorman 1522f1a5ab12SMel Gorman static void extfrag_show_print(struct seq_file *m, 1523f1a5ab12SMel Gorman pg_data_t *pgdat, struct zone *zone) 1524f1a5ab12SMel Gorman { 1525f1a5ab12SMel Gorman unsigned int order; 1526f1a5ab12SMel Gorman int index; 1527f1a5ab12SMel Gorman 1528f1a5ab12SMel Gorman /* Alloc on stack as interrupts are disabled for zone walk */ 1529f1a5ab12SMel Gorman struct contig_page_info info; 1530f1a5ab12SMel Gorman 1531f1a5ab12SMel Gorman seq_printf(m, "Node %d, zone %8s ", 1532f1a5ab12SMel Gorman pgdat->node_id, 1533f1a5ab12SMel Gorman zone->name); 1534f1a5ab12SMel Gorman for (order = 0; order < MAX_ORDER; ++order) { 1535f1a5ab12SMel Gorman fill_contig_page_info(zone, order, &info); 153656de7263SMel Gorman index = __fragmentation_index(order, &info); 1537f1a5ab12SMel Gorman seq_printf(m, "%d.%03d ", index / 1000, index % 1000); 1538f1a5ab12SMel Gorman } 1539f1a5ab12SMel Gorman 1540f1a5ab12SMel Gorman seq_putc(m, '\n'); 1541f1a5ab12SMel Gorman } 1542f1a5ab12SMel Gorman 1543f1a5ab12SMel Gorman /* 1544f1a5ab12SMel Gorman * Display fragmentation index for orders that allocations would fail for 1545f1a5ab12SMel Gorman */ 1546f1a5ab12SMel Gorman static int extfrag_show(struct seq_file *m, void *arg) 1547f1a5ab12SMel Gorman { 1548f1a5ab12SMel Gorman pg_data_t *pgdat = (pg_data_t *)arg; 1549f1a5ab12SMel Gorman 1550f1a5ab12SMel Gorman walk_zones_in_node(m, pgdat, extfrag_show_print); 1551f1a5ab12SMel Gorman 1552f1a5ab12SMel Gorman return 0; 1553f1a5ab12SMel Gorman } 1554f1a5ab12SMel Gorman 1555f1a5ab12SMel Gorman static const struct seq_operations extfrag_op = { 1556f1a5ab12SMel Gorman .start = frag_start, 1557f1a5ab12SMel Gorman .next = frag_next, 1558f1a5ab12SMel Gorman .stop = frag_stop, 1559f1a5ab12SMel Gorman .show = extfrag_show, 1560f1a5ab12SMel Gorman }; 1561f1a5ab12SMel Gorman 1562f1a5ab12SMel Gorman static int extfrag_open(struct inode *inode, struct file *file) 1563f1a5ab12SMel Gorman { 1564f1a5ab12SMel Gorman return seq_open(file, &extfrag_op); 1565f1a5ab12SMel Gorman } 1566f1a5ab12SMel Gorman 1567f1a5ab12SMel Gorman static const struct file_operations extfrag_file_ops = { 1568f1a5ab12SMel Gorman .open = extfrag_open, 1569f1a5ab12SMel Gorman .read = seq_read, 1570f1a5ab12SMel Gorman .llseek = seq_lseek, 1571f1a5ab12SMel Gorman .release = seq_release, 1572f1a5ab12SMel Gorman }; 1573f1a5ab12SMel Gorman 1574d7a5752cSMel Gorman static int __init extfrag_debug_init(void) 1575d7a5752cSMel Gorman { 1576bde8bd8aSSasikantha babu struct dentry *extfrag_debug_root; 1577bde8bd8aSSasikantha babu 1578d7a5752cSMel Gorman extfrag_debug_root = debugfs_create_dir("extfrag", NULL); 1579d7a5752cSMel Gorman if (!extfrag_debug_root) 1580d7a5752cSMel Gorman return -ENOMEM; 1581d7a5752cSMel Gorman 1582d7a5752cSMel Gorman if (!debugfs_create_file("unusable_index", 0444, 1583d7a5752cSMel Gorman extfrag_debug_root, NULL, &unusable_file_ops)) 1584bde8bd8aSSasikantha babu goto fail; 1585d7a5752cSMel Gorman 1586f1a5ab12SMel Gorman if (!debugfs_create_file("extfrag_index", 0444, 1587f1a5ab12SMel Gorman extfrag_debug_root, NULL, &extfrag_file_ops)) 1588bde8bd8aSSasikantha babu goto fail; 1589f1a5ab12SMel Gorman 1590d7a5752cSMel Gorman return 0; 1591bde8bd8aSSasikantha babu fail: 1592bde8bd8aSSasikantha babu debugfs_remove_recursive(extfrag_debug_root); 1593bde8bd8aSSasikantha babu return -ENOMEM; 1594d7a5752cSMel Gorman } 1595d7a5752cSMel Gorman 1596d7a5752cSMel Gorman module_init(extfrag_debug_init); 1597d7a5752cSMel Gorman #endif 1598