Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/vmstat.c |
| 3 | * |
| 4 | * Manages VM statistics |
| 5 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 6 | * |
| 7 | * zoned VM statistics |
| 8 | * Copyright (C) 2006 Silicon Graphics, Inc., |
| 9 | * Christoph Lameter <christoph@lameter.com> |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 10 | * Copyright (C) 2008-2014 Christoph Lameter |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 11 | */ |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 12 | #include <linux/fs.h> |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 13 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 14 | #include <linux/err.h> |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 17 | #include <linux/cpu.h> |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 18 | #include <linux/cpumask.h> |
Adrian Bunk | c748e13 | 2008-07-23 21:27:03 -0700 | [diff] [blame] | 19 | #include <linux/vmstat.h> |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 20 | #include <linux/proc_fs.h> |
| 21 | #include <linux/seq_file.h> |
| 22 | #include <linux/debugfs.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 23 | #include <linux/sched.h> |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 24 | #include <linux/math64.h> |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 25 | #include <linux/writeback.h> |
Namhyung Kim | 36deb0b | 2010-10-26 14:22:04 -0700 | [diff] [blame] | 26 | #include <linux/compaction.h> |
Lisa Du | 6e543d5 | 2013-09-11 14:22:36 -0700 | [diff] [blame] | 27 | #include <linux/mm_inline.h> |
Joonsoo Kim | 48c96a3 | 2014-12-12 16:56:01 -0800 | [diff] [blame] | 28 | #include <linux/page_ext.h> |
| 29 | #include <linux/page_owner.h> |
Lisa Du | 6e543d5 | 2013-09-11 14:22:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include "internal.h" |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 32 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_VM_EVENT_COUNTERS |
| 34 | DEFINE_PER_CPU(struct vm_event_state, vm_event_states) = {{0}}; |
| 35 | EXPORT_PER_CPU_SYMBOL(vm_event_states); |
| 36 | |
Minchan Kim | 31f961a | 2010-08-09 17:18:59 -0700 | [diff] [blame] | 37 | static void sum_vm_events(unsigned long *ret) |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 38 | { |
Christoph Lameter | 9eccf2a | 2008-02-04 22:29:22 -0800 | [diff] [blame] | 39 | int cpu; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 40 | int i; |
| 41 | |
| 42 | memset(ret, 0, NR_VM_EVENT_ITEMS * sizeof(unsigned long)); |
| 43 | |
Minchan Kim | 31f961a | 2010-08-09 17:18:59 -0700 | [diff] [blame] | 44 | for_each_online_cpu(cpu) { |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 45 | struct vm_event_state *this = &per_cpu(vm_event_states, cpu); |
| 46 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 47 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) |
| 48 | ret[i] += this->event[i]; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Accumulate the vm event counters across all CPUs. |
| 54 | * The result is unavoidably approximate - it can change |
| 55 | * during and after execution of this function. |
| 56 | */ |
| 57 | void all_vm_events(unsigned long *ret) |
| 58 | { |
KOSAKI Motohiro | b5be113 | 2008-05-12 14:02:06 -0700 | [diff] [blame] | 59 | get_online_cpus(); |
Minchan Kim | 31f961a | 2010-08-09 17:18:59 -0700 | [diff] [blame] | 60 | sum_vm_events(ret); |
KOSAKI Motohiro | b5be113 | 2008-05-12 14:02:06 -0700 | [diff] [blame] | 61 | put_online_cpus(); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 62 | } |
Heiko Carstens | 32dd66f | 2006-07-10 04:44:31 -0700 | [diff] [blame] | 63 | EXPORT_SYMBOL_GPL(all_vm_events); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 64 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 65 | /* |
| 66 | * Fold the foreign cpu events into our own. |
| 67 | * |
| 68 | * This is adding to the events on one processor |
| 69 | * but keeps the global counts constant. |
| 70 | */ |
| 71 | void vm_events_fold_cpu(int cpu) |
| 72 | { |
| 73 | struct vm_event_state *fold_state = &per_cpu(vm_event_states, cpu); |
| 74 | int i; |
| 75 | |
| 76 | for (i = 0; i < NR_VM_EVENT_ITEMS; i++) { |
| 77 | count_vm_events(i, fold_state->event[i]); |
| 78 | fold_state->event[i] = 0; |
| 79 | } |
| 80 | } |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 81 | |
| 82 | #endif /* CONFIG_VM_EVENT_COUNTERS */ |
| 83 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Manage combined zone based / global counters |
| 86 | * |
| 87 | * vm_stat contains the global counters |
| 88 | */ |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 89 | atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 90 | atomic_long_t vm_numa_stat[NR_VM_NUMA_STAT_ITEMS] __cacheline_aligned_in_smp; |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 91 | atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS] __cacheline_aligned_in_smp; |
| 92 | EXPORT_SYMBOL(vm_zone_stat); |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 93 | EXPORT_SYMBOL(vm_numa_stat); |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 94 | EXPORT_SYMBOL(vm_node_stat); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_SMP |
| 97 | |
Mel Gorman | b44129b | 2011-01-13 15:45:43 -0800 | [diff] [blame] | 98 | int calculate_pressure_threshold(struct zone *zone) |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 99 | { |
| 100 | int threshold; |
| 101 | int watermark_distance; |
| 102 | |
| 103 | /* |
| 104 | * As vmstats are not up to date, there is drift between the estimated |
| 105 | * and real values. For high thresholds and a high number of CPUs, it |
| 106 | * is possible for the min watermark to be breached while the estimated |
| 107 | * value looks fine. The pressure threshold is a reduced value such |
| 108 | * that even the maximum amount of drift will not accidentally breach |
| 109 | * the min watermark |
| 110 | */ |
| 111 | watermark_distance = low_wmark_pages(zone) - min_wmark_pages(zone); |
| 112 | threshold = max(1, (int)(watermark_distance / num_online_cpus())); |
| 113 | |
| 114 | /* |
| 115 | * Maximum threshold is 125 |
| 116 | */ |
| 117 | threshold = min(125, threshold); |
| 118 | |
| 119 | return threshold; |
| 120 | } |
| 121 | |
Mel Gorman | b44129b | 2011-01-13 15:45:43 -0800 | [diff] [blame] | 122 | int calculate_normal_threshold(struct zone *zone) |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 123 | { |
| 124 | int threshold; |
| 125 | int mem; /* memory in 128 MB units */ |
| 126 | |
| 127 | /* |
| 128 | * The threshold scales with the number of processors and the amount |
| 129 | * of memory per zone. More memory means that we can defer updates for |
| 130 | * longer, more processors could lead to more contention. |
| 131 | * fls() is used to have a cheap way of logarithmic scaling. |
| 132 | * |
| 133 | * Some sample thresholds: |
| 134 | * |
| 135 | * Threshold Processors (fls) Zonesize fls(mem+1) |
| 136 | * ------------------------------------------------------------------ |
| 137 | * 8 1 1 0.9-1 GB 4 |
| 138 | * 16 2 2 0.9-1 GB 4 |
| 139 | * 20 2 2 1-2 GB 5 |
| 140 | * 24 2 2 2-4 GB 6 |
| 141 | * 28 2 2 4-8 GB 7 |
| 142 | * 32 2 2 8-16 GB 8 |
| 143 | * 4 2 2 <128M 1 |
| 144 | * 30 4 3 2-4 GB 5 |
| 145 | * 48 4 3 8-16 GB 8 |
| 146 | * 32 8 4 1-2 GB 4 |
| 147 | * 32 8 4 0.9-1GB 4 |
| 148 | * 10 16 5 <128M 1 |
| 149 | * 40 16 5 900M 4 |
| 150 | * 70 64 7 2-4 GB 5 |
| 151 | * 84 64 7 4-8 GB 6 |
| 152 | * 108 512 9 4-8 GB 6 |
| 153 | * 125 1024 10 8-16 GB 8 |
| 154 | * 125 1024 10 16-32 GB 9 |
| 155 | */ |
| 156 | |
Jiang Liu | b40da04 | 2013-02-22 16:33:52 -0800 | [diff] [blame] | 157 | mem = zone->managed_pages >> (27 - PAGE_SHIFT); |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 158 | |
| 159 | threshold = 2 * fls(num_online_cpus()) * (1 + fls(mem)); |
| 160 | |
| 161 | /* |
| 162 | * Maximum threshold is 125 |
| 163 | */ |
| 164 | threshold = min(125, threshold); |
| 165 | |
| 166 | return threshold; |
| 167 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 168 | |
| 169 | /* |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 170 | * Refresh the thresholds for each zone. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 171 | */ |
KOSAKI Motohiro | a6cccdc | 2011-05-24 17:11:33 -0700 | [diff] [blame] | 172 | void refresh_zone_stat_thresholds(void) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 173 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 174 | struct pglist_data *pgdat; |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 175 | struct zone *zone; |
| 176 | int cpu; |
| 177 | int threshold; |
| 178 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 179 | /* Zero current pgdat thresholds */ |
| 180 | for_each_online_pgdat(pgdat) { |
| 181 | for_each_online_cpu(cpu) { |
| 182 | per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold = 0; |
| 183 | } |
| 184 | } |
| 185 | |
KOSAKI Motohiro | ee99c71 | 2009-03-31 15:19:31 -0700 | [diff] [blame] | 186 | for_each_populated_zone(zone) { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 187 | struct pglist_data *pgdat = zone->zone_pgdat; |
Christoph Lameter | aa45484 | 2010-09-09 16:38:17 -0700 | [diff] [blame] | 188 | unsigned long max_drift, tolerate_drift; |
| 189 | |
Mel Gorman | b44129b | 2011-01-13 15:45:43 -0800 | [diff] [blame] | 190 | threshold = calculate_normal_threshold(zone); |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 191 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 192 | for_each_online_cpu(cpu) { |
| 193 | int pgdat_threshold; |
| 194 | |
Christoph Lameter | 99dcc3e | 2010-01-05 15:34:51 +0900 | [diff] [blame] | 195 | per_cpu_ptr(zone->pageset, cpu)->stat_threshold |
| 196 | = threshold; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 197 | #ifdef CONFIG_NUMA |
| 198 | per_cpu_ptr(zone->pageset, cpu)->numa_stat_threshold |
| 199 | = threshold; |
| 200 | #endif |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 201 | /* Base nodestat threshold on the largest populated zone. */ |
| 202 | pgdat_threshold = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold; |
| 203 | per_cpu_ptr(pgdat->per_cpu_nodestats, cpu)->stat_threshold |
| 204 | = max(threshold, pgdat_threshold); |
| 205 | } |
| 206 | |
Christoph Lameter | aa45484 | 2010-09-09 16:38:17 -0700 | [diff] [blame] | 207 | /* |
| 208 | * Only set percpu_drift_mark if there is a danger that |
| 209 | * NR_FREE_PAGES reports the low watermark is ok when in fact |
| 210 | * the min watermark could be breached by an allocation |
| 211 | */ |
| 212 | tolerate_drift = low_wmark_pages(zone) - min_wmark_pages(zone); |
| 213 | max_drift = num_online_cpus() * threshold; |
| 214 | if (max_drift > tolerate_drift) |
| 215 | zone->percpu_drift_mark = high_wmark_pages(zone) + |
| 216 | max_drift; |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 217 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Mel Gorman | b44129b | 2011-01-13 15:45:43 -0800 | [diff] [blame] | 220 | void set_pgdat_percpu_threshold(pg_data_t *pgdat, |
| 221 | int (*calculate_pressure)(struct zone *)) |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 222 | { |
| 223 | struct zone *zone; |
| 224 | int cpu; |
| 225 | int threshold; |
| 226 | int i; |
| 227 | |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 228 | for (i = 0; i < pgdat->nr_zones; i++) { |
| 229 | zone = &pgdat->node_zones[i]; |
| 230 | if (!zone->percpu_drift_mark) |
| 231 | continue; |
| 232 | |
Mel Gorman | b44129b | 2011-01-13 15:45:43 -0800 | [diff] [blame] | 233 | threshold = (*calculate_pressure)(zone); |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 234 | for_each_online_cpu(cpu) { |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 235 | per_cpu_ptr(zone->pageset, cpu)->stat_threshold |
| 236 | = threshold; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 237 | #ifdef CONFIG_NUMA |
| 238 | per_cpu_ptr(zone->pageset, cpu)->numa_stat_threshold |
| 239 | = threshold; |
| 240 | #endif |
| 241 | } |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 242 | } |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 245 | /* |
Jianyu Zhan | bea04b0 | 2014-06-04 16:09:51 -0700 | [diff] [blame] | 246 | * For use when we know that interrupts are disabled, |
| 247 | * or when we know that preemption is disabled and that |
| 248 | * particular counter cannot be updated from interrupt context. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 249 | */ |
| 250 | void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
Heiko Carstens | 6cdb18a | 2015-12-29 14:54:32 -0800 | [diff] [blame] | 251 | long delta) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 252 | { |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 253 | struct per_cpu_pageset __percpu *pcp = zone->pageset; |
| 254 | s8 __percpu *p = pcp->vm_stat_diff + item; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 255 | long x; |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 256 | long t; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 257 | |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 258 | x = delta + __this_cpu_read(*p); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 259 | |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 260 | t = __this_cpu_read(pcp->stat_threshold); |
| 261 | |
| 262 | if (unlikely(x > t || x < -t)) { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 263 | zone_page_state_add(x, zone, item); |
| 264 | x = 0; |
| 265 | } |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 266 | __this_cpu_write(*p, x); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 267 | } |
| 268 | EXPORT_SYMBOL(__mod_zone_page_state); |
| 269 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 270 | void __mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, |
| 271 | long delta) |
| 272 | { |
| 273 | struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; |
| 274 | s8 __percpu *p = pcp->vm_node_stat_diff + item; |
| 275 | long x; |
| 276 | long t; |
| 277 | |
| 278 | x = delta + __this_cpu_read(*p); |
| 279 | |
| 280 | t = __this_cpu_read(pcp->stat_threshold); |
| 281 | |
| 282 | if (unlikely(x > t || x < -t)) { |
| 283 | node_page_state_add(x, pgdat, item); |
| 284 | x = 0; |
| 285 | } |
| 286 | __this_cpu_write(*p, x); |
| 287 | } |
| 288 | EXPORT_SYMBOL(__mod_node_page_state); |
| 289 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 290 | /* |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 291 | * Optimized increment and decrement functions. |
| 292 | * |
| 293 | * These are only for a single page and therefore can take a struct page * |
| 294 | * argument instead of struct zone *. This allows the inclusion of the code |
| 295 | * generated for page_zone(page) into the optimized functions. |
| 296 | * |
| 297 | * No overflow check is necessary and therefore the differential can be |
| 298 | * incremented or decremented in place which may allow the compilers to |
| 299 | * generate better code. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 300 | * The increment or decrement is known and therefore one boundary check can |
| 301 | * be omitted. |
| 302 | * |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 303 | * NOTE: These functions are very performance sensitive. Change only |
| 304 | * with care. |
| 305 | * |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 306 | * Some processors have inc/dec instructions that are atomic vs an interrupt. |
| 307 | * However, the code must first determine the differential location in a zone |
| 308 | * based on the processor number and then inc/dec the counter. There is no |
| 309 | * guarantee without disabling preemption that the processor will not change |
| 310 | * in between and therefore the atomicity vs. interrupt cannot be exploited |
| 311 | * in a useful way here. |
| 312 | */ |
Christoph Lameter | c878538 | 2007-02-10 01:43:01 -0800 | [diff] [blame] | 313 | void __inc_zone_state(struct zone *zone, enum zone_stat_item item) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 314 | { |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 315 | struct per_cpu_pageset __percpu *pcp = zone->pageset; |
| 316 | s8 __percpu *p = pcp->vm_stat_diff + item; |
| 317 | s8 v, t; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 318 | |
Christoph Lameter | 908ee0f | 2010-12-06 11:40:02 -0600 | [diff] [blame] | 319 | v = __this_cpu_inc_return(*p); |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 320 | t = __this_cpu_read(pcp->stat_threshold); |
| 321 | if (unlikely(v > t)) { |
| 322 | s8 overstep = t >> 1; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 323 | |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 324 | zone_page_state_add(v + overstep, zone, item); |
| 325 | __this_cpu_write(*p, -overstep); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 328 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 329 | void __inc_node_state(struct pglist_data *pgdat, enum node_stat_item item) |
| 330 | { |
| 331 | struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; |
| 332 | s8 __percpu *p = pcp->vm_node_stat_diff + item; |
| 333 | s8 v, t; |
| 334 | |
| 335 | v = __this_cpu_inc_return(*p); |
| 336 | t = __this_cpu_read(pcp->stat_threshold); |
| 337 | if (unlikely(v > t)) { |
| 338 | s8 overstep = t >> 1; |
| 339 | |
| 340 | node_page_state_add(v + overstep, pgdat, item); |
| 341 | __this_cpu_write(*p, -overstep); |
| 342 | } |
| 343 | } |
| 344 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 345 | void __inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 346 | { |
| 347 | __inc_zone_state(page_zone(page), item); |
| 348 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 349 | EXPORT_SYMBOL(__inc_zone_page_state); |
| 350 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 351 | void __inc_node_page_state(struct page *page, enum node_stat_item item) |
| 352 | { |
| 353 | __inc_node_state(page_pgdat(page), item); |
| 354 | } |
| 355 | EXPORT_SYMBOL(__inc_node_page_state); |
| 356 | |
Christoph Lameter | c878538 | 2007-02-10 01:43:01 -0800 | [diff] [blame] | 357 | void __dec_zone_state(struct zone *zone, enum zone_stat_item item) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 358 | { |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 359 | struct per_cpu_pageset __percpu *pcp = zone->pageset; |
| 360 | s8 __percpu *p = pcp->vm_stat_diff + item; |
| 361 | s8 v, t; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 362 | |
Christoph Lameter | 908ee0f | 2010-12-06 11:40:02 -0600 | [diff] [blame] | 363 | v = __this_cpu_dec_return(*p); |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 364 | t = __this_cpu_read(pcp->stat_threshold); |
| 365 | if (unlikely(v < - t)) { |
| 366 | s8 overstep = t >> 1; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 367 | |
Christoph Lameter | 12938a9 | 2010-12-06 11:16:20 -0600 | [diff] [blame] | 368 | zone_page_state_add(v - overstep, zone, item); |
| 369 | __this_cpu_write(*p, overstep); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
Christoph Lameter | c878538 | 2007-02-10 01:43:01 -0800 | [diff] [blame] | 372 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 373 | void __dec_node_state(struct pglist_data *pgdat, enum node_stat_item item) |
| 374 | { |
| 375 | struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; |
| 376 | s8 __percpu *p = pcp->vm_node_stat_diff + item; |
| 377 | s8 v, t; |
| 378 | |
| 379 | v = __this_cpu_dec_return(*p); |
| 380 | t = __this_cpu_read(pcp->stat_threshold); |
| 381 | if (unlikely(v < - t)) { |
| 382 | s8 overstep = t >> 1; |
| 383 | |
| 384 | node_page_state_add(v - overstep, pgdat, item); |
| 385 | __this_cpu_write(*p, overstep); |
| 386 | } |
| 387 | } |
| 388 | |
Christoph Lameter | c878538 | 2007-02-10 01:43:01 -0800 | [diff] [blame] | 389 | void __dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 390 | { |
| 391 | __dec_zone_state(page_zone(page), item); |
| 392 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 393 | EXPORT_SYMBOL(__dec_zone_page_state); |
| 394 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 395 | void __dec_node_page_state(struct page *page, enum node_stat_item item) |
| 396 | { |
| 397 | __dec_node_state(page_pgdat(page), item); |
| 398 | } |
| 399 | EXPORT_SYMBOL(__dec_node_page_state); |
| 400 | |
Heiko Carstens | 4156153 | 2012-01-12 17:17:30 -0800 | [diff] [blame] | 401 | #ifdef CONFIG_HAVE_CMPXCHG_LOCAL |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 402 | /* |
| 403 | * If we have cmpxchg_local support then we do not need to incur the overhead |
| 404 | * that comes with local_irq_save/restore if we use this_cpu_cmpxchg. |
| 405 | * |
| 406 | * mod_state() modifies the zone counter state through atomic per cpu |
| 407 | * operations. |
| 408 | * |
| 409 | * Overstep mode specifies how overstep should handled: |
| 410 | * 0 No overstepping |
| 411 | * 1 Overstepping half of threshold |
| 412 | * -1 Overstepping minus half of threshold |
| 413 | */ |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 414 | static inline void mod_zone_state(struct zone *zone, |
| 415 | enum zone_stat_item item, long delta, int overstep_mode) |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 416 | { |
| 417 | struct per_cpu_pageset __percpu *pcp = zone->pageset; |
| 418 | s8 __percpu *p = pcp->vm_stat_diff + item; |
| 419 | long o, n, t, z; |
| 420 | |
| 421 | do { |
| 422 | z = 0; /* overflow to zone counters */ |
| 423 | |
| 424 | /* |
| 425 | * The fetching of the stat_threshold is racy. We may apply |
| 426 | * a counter threshold to the wrong the cpu if we get |
Christoph Lameter | d3bc236 | 2011-04-14 15:21:58 -0700 | [diff] [blame] | 427 | * rescheduled while executing here. However, the next |
| 428 | * counter update will apply the threshold again and |
| 429 | * therefore bring the counter under the threshold again. |
| 430 | * |
| 431 | * Most of the time the thresholds are the same anyways |
| 432 | * for all cpus in a zone. |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 433 | */ |
| 434 | t = this_cpu_read(pcp->stat_threshold); |
| 435 | |
| 436 | o = this_cpu_read(*p); |
| 437 | n = delta + o; |
| 438 | |
| 439 | if (n > t || n < -t) { |
| 440 | int os = overstep_mode * (t >> 1) ; |
| 441 | |
| 442 | /* Overflow must be added to zone counters */ |
| 443 | z = n + os; |
| 444 | n = -os; |
| 445 | } |
| 446 | } while (this_cpu_cmpxchg(*p, o, n) != o); |
| 447 | |
| 448 | if (z) |
| 449 | zone_page_state_add(z, zone, item); |
| 450 | } |
| 451 | |
| 452 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
Heiko Carstens | 6cdb18a | 2015-12-29 14:54:32 -0800 | [diff] [blame] | 453 | long delta) |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 454 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 455 | mod_zone_state(zone, item, delta, 0); |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 456 | } |
| 457 | EXPORT_SYMBOL(mod_zone_page_state); |
| 458 | |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 459 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 460 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 461 | mod_zone_state(page_zone(page), item, 1, 1); |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 462 | } |
| 463 | EXPORT_SYMBOL(inc_zone_page_state); |
| 464 | |
| 465 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 466 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 467 | mod_zone_state(page_zone(page), item, -1, -1); |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 468 | } |
| 469 | EXPORT_SYMBOL(dec_zone_page_state); |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 470 | |
| 471 | static inline void mod_node_state(struct pglist_data *pgdat, |
| 472 | enum node_stat_item item, int delta, int overstep_mode) |
| 473 | { |
| 474 | struct per_cpu_nodestat __percpu *pcp = pgdat->per_cpu_nodestats; |
| 475 | s8 __percpu *p = pcp->vm_node_stat_diff + item; |
| 476 | long o, n, t, z; |
| 477 | |
| 478 | do { |
| 479 | z = 0; /* overflow to node counters */ |
| 480 | |
| 481 | /* |
| 482 | * The fetching of the stat_threshold is racy. We may apply |
| 483 | * a counter threshold to the wrong the cpu if we get |
| 484 | * rescheduled while executing here. However, the next |
| 485 | * counter update will apply the threshold again and |
| 486 | * therefore bring the counter under the threshold again. |
| 487 | * |
| 488 | * Most of the time the thresholds are the same anyways |
| 489 | * for all cpus in a node. |
| 490 | */ |
| 491 | t = this_cpu_read(pcp->stat_threshold); |
| 492 | |
| 493 | o = this_cpu_read(*p); |
| 494 | n = delta + o; |
| 495 | |
| 496 | if (n > t || n < -t) { |
| 497 | int os = overstep_mode * (t >> 1) ; |
| 498 | |
| 499 | /* Overflow must be added to node counters */ |
| 500 | z = n + os; |
| 501 | n = -os; |
| 502 | } |
| 503 | } while (this_cpu_cmpxchg(*p, o, n) != o); |
| 504 | |
| 505 | if (z) |
| 506 | node_page_state_add(z, pgdat, item); |
| 507 | } |
| 508 | |
| 509 | void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, |
| 510 | long delta) |
| 511 | { |
| 512 | mod_node_state(pgdat, item, delta, 0); |
| 513 | } |
| 514 | EXPORT_SYMBOL(mod_node_page_state); |
| 515 | |
| 516 | void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item) |
| 517 | { |
| 518 | mod_node_state(pgdat, item, 1, 1); |
| 519 | } |
| 520 | |
| 521 | void inc_node_page_state(struct page *page, enum node_stat_item item) |
| 522 | { |
| 523 | mod_node_state(page_pgdat(page), item, 1, 1); |
| 524 | } |
| 525 | EXPORT_SYMBOL(inc_node_page_state); |
| 526 | |
| 527 | void dec_node_page_state(struct page *page, enum node_stat_item item) |
| 528 | { |
| 529 | mod_node_state(page_pgdat(page), item, -1, -1); |
| 530 | } |
| 531 | EXPORT_SYMBOL(dec_node_page_state); |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 532 | #else |
| 533 | /* |
| 534 | * Use interrupt disable to serialize counter updates |
| 535 | */ |
| 536 | void mod_zone_page_state(struct zone *zone, enum zone_stat_item item, |
Heiko Carstens | 6cdb18a | 2015-12-29 14:54:32 -0800 | [diff] [blame] | 537 | long delta) |
Christoph Lameter | 7c83912 | 2010-12-14 10:28:46 -0600 | [diff] [blame] | 538 | { |
| 539 | unsigned long flags; |
| 540 | |
| 541 | local_irq_save(flags); |
| 542 | __mod_zone_page_state(zone, item, delta); |
| 543 | local_irq_restore(flags); |
| 544 | } |
| 545 | EXPORT_SYMBOL(mod_zone_page_state); |
| 546 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 547 | void inc_zone_page_state(struct page *page, enum zone_stat_item item) |
| 548 | { |
| 549 | unsigned long flags; |
| 550 | struct zone *zone; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 551 | |
| 552 | zone = page_zone(page); |
| 553 | local_irq_save(flags); |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 554 | __inc_zone_state(zone, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 555 | local_irq_restore(flags); |
| 556 | } |
| 557 | EXPORT_SYMBOL(inc_zone_page_state); |
| 558 | |
| 559 | void dec_zone_page_state(struct page *page, enum zone_stat_item item) |
| 560 | { |
| 561 | unsigned long flags; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 562 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 563 | local_irq_save(flags); |
Christoph Lameter | a302eb4 | 2006-08-31 21:27:34 -0700 | [diff] [blame] | 564 | __dec_zone_page_state(page, item); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 565 | local_irq_restore(flags); |
| 566 | } |
| 567 | EXPORT_SYMBOL(dec_zone_page_state); |
| 568 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 569 | void inc_node_state(struct pglist_data *pgdat, enum node_stat_item item) |
| 570 | { |
| 571 | unsigned long flags; |
| 572 | |
| 573 | local_irq_save(flags); |
| 574 | __inc_node_state(pgdat, item); |
| 575 | local_irq_restore(flags); |
| 576 | } |
| 577 | EXPORT_SYMBOL(inc_node_state); |
| 578 | |
| 579 | void mod_node_page_state(struct pglist_data *pgdat, enum node_stat_item item, |
| 580 | long delta) |
| 581 | { |
| 582 | unsigned long flags; |
| 583 | |
| 584 | local_irq_save(flags); |
| 585 | __mod_node_page_state(pgdat, item, delta); |
| 586 | local_irq_restore(flags); |
| 587 | } |
| 588 | EXPORT_SYMBOL(mod_node_page_state); |
| 589 | |
| 590 | void inc_node_page_state(struct page *page, enum node_stat_item item) |
| 591 | { |
| 592 | unsigned long flags; |
| 593 | struct pglist_data *pgdat; |
| 594 | |
| 595 | pgdat = page_pgdat(page); |
| 596 | local_irq_save(flags); |
| 597 | __inc_node_state(pgdat, item); |
| 598 | local_irq_restore(flags); |
| 599 | } |
| 600 | EXPORT_SYMBOL(inc_node_page_state); |
| 601 | |
| 602 | void dec_node_page_state(struct page *page, enum node_stat_item item) |
| 603 | { |
| 604 | unsigned long flags; |
| 605 | |
| 606 | local_irq_save(flags); |
| 607 | __dec_node_page_state(page, item); |
| 608 | local_irq_restore(flags); |
| 609 | } |
| 610 | EXPORT_SYMBOL(dec_node_page_state); |
| 611 | #endif |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 612 | |
| 613 | /* |
| 614 | * Fold a differential into the global counters. |
| 615 | * Returns the number of counters updated. |
| 616 | */ |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 617 | #ifdef CONFIG_NUMA |
| 618 | static int fold_diff(int *zone_diff, int *numa_diff, int *node_diff) |
| 619 | { |
| 620 | int i; |
| 621 | int changes = 0; |
| 622 | |
| 623 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 624 | if (zone_diff[i]) { |
| 625 | atomic_long_add(zone_diff[i], &vm_zone_stat[i]); |
| 626 | changes++; |
| 627 | } |
| 628 | |
| 629 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) |
| 630 | if (numa_diff[i]) { |
| 631 | atomic_long_add(numa_diff[i], &vm_numa_stat[i]); |
| 632 | changes++; |
| 633 | } |
| 634 | |
| 635 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) |
| 636 | if (node_diff[i]) { |
| 637 | atomic_long_add(node_diff[i], &vm_node_stat[i]); |
| 638 | changes++; |
| 639 | } |
| 640 | return changes; |
| 641 | } |
| 642 | #else |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 643 | static int fold_diff(int *zone_diff, int *node_diff) |
Christoph Lameter | 4edb074 | 2013-09-11 14:21:31 -0700 | [diff] [blame] | 644 | { |
| 645 | int i; |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 646 | int changes = 0; |
Christoph Lameter | 4edb074 | 2013-09-11 14:21:31 -0700 | [diff] [blame] | 647 | |
| 648 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 649 | if (zone_diff[i]) { |
| 650 | atomic_long_add(zone_diff[i], &vm_zone_stat[i]); |
| 651 | changes++; |
| 652 | } |
| 653 | |
| 654 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) |
| 655 | if (node_diff[i]) { |
| 656 | atomic_long_add(node_diff[i], &vm_node_stat[i]); |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 657 | changes++; |
| 658 | } |
| 659 | return changes; |
Christoph Lameter | 4edb074 | 2013-09-11 14:21:31 -0700 | [diff] [blame] | 660 | } |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 661 | #endif /* CONFIG_NUMA */ |
Christoph Lameter | 4edb074 | 2013-09-11 14:21:31 -0700 | [diff] [blame] | 662 | |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 663 | /* |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 664 | * Update the zone counters for the current cpu. |
Christoph Lameter | a7f75e2 | 2008-02-04 22:29:16 -0800 | [diff] [blame] | 665 | * |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 666 | * Note that refresh_cpu_vm_stats strives to only access |
| 667 | * node local memory. The per cpu pagesets on remote zones are placed |
| 668 | * in the memory local to the processor using that pageset. So the |
| 669 | * loop over all zones will access a series of cachelines local to |
| 670 | * the processor. |
| 671 | * |
| 672 | * The call to zone_page_state_add updates the cachelines with the |
| 673 | * statistics in the remote zone struct as well as the global cachelines |
| 674 | * with the global counters. These could cause remote node cache line |
| 675 | * bouncing and will have to be only done when necessary. |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 676 | * |
| 677 | * The function returns the number of global counters updated. |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 678 | */ |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 679 | static int refresh_cpu_vm_stats(bool do_pagesets) |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 680 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 681 | struct pglist_data *pgdat; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 682 | struct zone *zone; |
| 683 | int i; |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 684 | int global_zone_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 685 | #ifdef CONFIG_NUMA |
| 686 | int global_numa_diff[NR_VM_NUMA_STAT_ITEMS] = { 0, }; |
| 687 | #endif |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 688 | int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, }; |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 689 | int changes = 0; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 690 | |
KOSAKI Motohiro | ee99c71 | 2009-03-31 15:19:31 -0700 | [diff] [blame] | 691 | for_each_populated_zone(zone) { |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 692 | struct per_cpu_pageset __percpu *p = zone->pageset; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 693 | |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 694 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { |
| 695 | int v; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 696 | |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 697 | v = this_cpu_xchg(p->vm_stat_diff[i], 0); |
| 698 | if (v) { |
Christoph Lameter | a7f75e2 | 2008-02-04 22:29:16 -0800 | [diff] [blame] | 699 | |
Christoph Lameter | a7f75e2 | 2008-02-04 22:29:16 -0800 | [diff] [blame] | 700 | atomic_long_add(v, &zone->vm_stat[i]); |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 701 | global_zone_diff[i] += v; |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 702 | #ifdef CONFIG_NUMA |
| 703 | /* 3 seconds idle till flush */ |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 704 | __this_cpu_write(p->expire, 3); |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 705 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 706 | } |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 707 | } |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 708 | #ifdef CONFIG_NUMA |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 709 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) { |
| 710 | int v; |
| 711 | |
| 712 | v = this_cpu_xchg(p->vm_numa_stat_diff[i], 0); |
| 713 | if (v) { |
| 714 | |
| 715 | atomic_long_add(v, &zone->vm_numa_stat[i]); |
| 716 | global_numa_diff[i] += v; |
| 717 | __this_cpu_write(p->expire, 3); |
| 718 | } |
| 719 | } |
| 720 | |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 721 | if (do_pagesets) { |
| 722 | cond_resched(); |
| 723 | /* |
| 724 | * Deal with draining the remote pageset of this |
| 725 | * processor |
| 726 | * |
| 727 | * Check if there are pages remaining in this pageset |
| 728 | * if not then there is nothing to expire. |
| 729 | */ |
| 730 | if (!__this_cpu_read(p->expire) || |
Christoph Lameter | fbc2edb | 2013-09-11 14:21:32 -0700 | [diff] [blame] | 731 | !__this_cpu_read(p->pcp.count)) |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 732 | continue; |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 733 | |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 734 | /* |
| 735 | * We never drain zones local to this processor. |
| 736 | */ |
| 737 | if (zone_to_nid(zone) == numa_node_id()) { |
| 738 | __this_cpu_write(p->expire, 0); |
| 739 | continue; |
| 740 | } |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 741 | |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 742 | if (__this_cpu_dec_return(p->expire)) |
| 743 | continue; |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 744 | |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 745 | if (__this_cpu_read(p->pcp.count)) { |
| 746 | drain_zone_pages(zone, this_cpu_ptr(&p->pcp)); |
| 747 | changes++; |
| 748 | } |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 749 | } |
Christoph Lameter | 4037d45 | 2007-05-09 02:35:14 -0700 | [diff] [blame] | 750 | #endif |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 751 | } |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 752 | |
| 753 | for_each_online_pgdat(pgdat) { |
| 754 | struct per_cpu_nodestat __percpu *p = pgdat->per_cpu_nodestats; |
| 755 | |
| 756 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) { |
| 757 | int v; |
| 758 | |
| 759 | v = this_cpu_xchg(p->vm_node_stat_diff[i], 0); |
| 760 | if (v) { |
| 761 | atomic_long_add(v, &pgdat->vm_stat[i]); |
| 762 | global_node_diff[i] += v; |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 767 | #ifdef CONFIG_NUMA |
| 768 | changes += fold_diff(global_zone_diff, global_numa_diff, |
| 769 | global_node_diff); |
| 770 | #else |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 771 | changes += fold_diff(global_zone_diff, global_node_diff); |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 772 | #endif |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 773 | return changes; |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Cody P Schafer | 40f4b1e | 2013-04-29 15:08:38 -0700 | [diff] [blame] | 776 | /* |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 777 | * Fold the data for an offline cpu into the global array. |
| 778 | * There cannot be any access by the offline cpu and therefore |
| 779 | * synchronization is simplified. |
| 780 | */ |
| 781 | void cpu_vm_stats_fold(int cpu) |
| 782 | { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 783 | struct pglist_data *pgdat; |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 784 | struct zone *zone; |
| 785 | int i; |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 786 | int global_zone_diff[NR_VM_ZONE_STAT_ITEMS] = { 0, }; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 787 | #ifdef CONFIG_NUMA |
| 788 | int global_numa_diff[NR_VM_NUMA_STAT_ITEMS] = { 0, }; |
| 789 | #endif |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 790 | int global_node_diff[NR_VM_NODE_STAT_ITEMS] = { 0, }; |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 791 | |
| 792 | for_each_populated_zone(zone) { |
| 793 | struct per_cpu_pageset *p; |
| 794 | |
| 795 | p = per_cpu_ptr(zone->pageset, cpu); |
| 796 | |
| 797 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 798 | if (p->vm_stat_diff[i]) { |
| 799 | int v; |
| 800 | |
| 801 | v = p->vm_stat_diff[i]; |
| 802 | p->vm_stat_diff[i] = 0; |
| 803 | atomic_long_add(v, &zone->vm_stat[i]); |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 804 | global_zone_diff[i] += v; |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 805 | } |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 806 | |
| 807 | #ifdef CONFIG_NUMA |
| 808 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) |
| 809 | if (p->vm_numa_stat_diff[i]) { |
| 810 | int v; |
| 811 | |
| 812 | v = p->vm_numa_stat_diff[i]; |
| 813 | p->vm_numa_stat_diff[i] = 0; |
| 814 | atomic_long_add(v, &zone->vm_numa_stat[i]); |
| 815 | global_numa_diff[i] += v; |
| 816 | } |
| 817 | #endif |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 820 | for_each_online_pgdat(pgdat) { |
| 821 | struct per_cpu_nodestat *p; |
| 822 | |
| 823 | p = per_cpu_ptr(pgdat->per_cpu_nodestats, cpu); |
| 824 | |
| 825 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) |
| 826 | if (p->vm_node_stat_diff[i]) { |
| 827 | int v; |
| 828 | |
| 829 | v = p->vm_node_stat_diff[i]; |
| 830 | p->vm_node_stat_diff[i] = 0; |
| 831 | atomic_long_add(v, &pgdat->vm_stat[i]); |
| 832 | global_node_diff[i] += v; |
| 833 | } |
| 834 | } |
| 835 | |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 836 | #ifdef CONFIG_NUMA |
| 837 | fold_diff(global_zone_diff, global_numa_diff, global_node_diff); |
| 838 | #else |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 839 | fold_diff(global_zone_diff, global_node_diff); |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 840 | #endif |
Christoph Lameter | 2bb921e | 2013-09-11 14:21:30 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* |
Cody P Schafer | 40f4b1e | 2013-04-29 15:08:38 -0700 | [diff] [blame] | 844 | * this is only called if !populated_zone(zone), which implies no other users of |
| 845 | * pset->vm_stat_diff[] exsist. |
| 846 | */ |
Minchan Kim | 5a88381 | 2012-10-08 16:33:39 -0700 | [diff] [blame] | 847 | void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset) |
| 848 | { |
| 849 | int i; |
| 850 | |
| 851 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 852 | if (pset->vm_stat_diff[i]) { |
| 853 | int v = pset->vm_stat_diff[i]; |
| 854 | pset->vm_stat_diff[i] = 0; |
| 855 | atomic_long_add(v, &zone->vm_stat[i]); |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 856 | atomic_long_add(v, &vm_zone_stat[i]); |
Minchan Kim | 5a88381 | 2012-10-08 16:33:39 -0700 | [diff] [blame] | 857 | } |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 858 | |
| 859 | #ifdef CONFIG_NUMA |
| 860 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) |
| 861 | if (pset->vm_numa_stat_diff[i]) { |
| 862 | int v = pset->vm_numa_stat_diff[i]; |
| 863 | |
| 864 | pset->vm_numa_stat_diff[i] = 0; |
| 865 | atomic_long_add(v, &zone->vm_numa_stat[i]); |
| 866 | atomic_long_add(v, &vm_numa_stat[i]); |
| 867 | } |
| 868 | #endif |
Minchan Kim | 5a88381 | 2012-10-08 16:33:39 -0700 | [diff] [blame] | 869 | } |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 870 | #endif |
| 871 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 872 | #ifdef CONFIG_NUMA |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 873 | void __inc_numa_state(struct zone *zone, |
| 874 | enum numa_stat_item item) |
| 875 | { |
| 876 | struct per_cpu_pageset __percpu *pcp = zone->pageset; |
| 877 | s8 __percpu *p = pcp->vm_numa_stat_diff + item; |
| 878 | s8 v, t; |
| 879 | |
| 880 | v = __this_cpu_inc_return(*p); |
| 881 | t = __this_cpu_read(pcp->numa_stat_threshold); |
| 882 | if (unlikely(v > t)) { |
| 883 | s8 overstep = t >> 1; |
| 884 | |
| 885 | zone_numa_state_add(v + overstep, zone, item); |
| 886 | __this_cpu_write(*p, -overstep); |
| 887 | } |
| 888 | } |
| 889 | |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 890 | /* |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 891 | * Determine the per node value of a stat item. This function |
| 892 | * is called frequently in a NUMA machine, so try to be as |
| 893 | * frugal as possible. |
Andrew Morton | c2d42c1 | 2015-11-05 18:48:43 -0800 | [diff] [blame] | 894 | */ |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 895 | unsigned long sum_zone_node_page_state(int node, |
| 896 | enum zone_stat_item item) |
Andrew Morton | c2d42c1 | 2015-11-05 18:48:43 -0800 | [diff] [blame] | 897 | { |
| 898 | struct zone *zones = NODE_DATA(node)->node_zones; |
Joonsoo Kim | e87d59f | 2016-05-19 17:12:29 -0700 | [diff] [blame] | 899 | int i; |
| 900 | unsigned long count = 0; |
Andrew Morton | c2d42c1 | 2015-11-05 18:48:43 -0800 | [diff] [blame] | 901 | |
Joonsoo Kim | e87d59f | 2016-05-19 17:12:29 -0700 | [diff] [blame] | 902 | for (i = 0; i < MAX_NR_ZONES; i++) |
| 903 | count += zone_page_state(zones + i, item); |
| 904 | |
| 905 | return count; |
Andrew Morton | c2d42c1 | 2015-11-05 18:48:43 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 908 | unsigned long sum_zone_numa_state(int node, |
| 909 | enum numa_stat_item item) |
| 910 | { |
| 911 | struct zone *zones = NODE_DATA(node)->node_zones; |
| 912 | int i; |
| 913 | unsigned long count = 0; |
| 914 | |
| 915 | for (i = 0; i < MAX_NR_ZONES; i++) |
| 916 | count += zone_numa_state(zones + i, item); |
| 917 | |
| 918 | return count; |
| 919 | } |
| 920 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 921 | /* |
| 922 | * Determine the per node value of a stat item. |
| 923 | */ |
| 924 | unsigned long node_page_state(struct pglist_data *pgdat, |
| 925 | enum node_stat_item item) |
| 926 | { |
| 927 | long x = atomic_long_read(&pgdat->vm_stat[item]); |
| 928 | #ifdef CONFIG_SMP |
| 929 | if (x < 0) |
| 930 | x = 0; |
| 931 | #endif |
| 932 | return x; |
| 933 | } |
Christoph Lameter | ca889e6 | 2006-06-30 01:55:44 -0700 | [diff] [blame] | 934 | #endif |
| 935 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 936 | #ifdef CONFIG_COMPACTION |
Namhyung Kim | 36deb0b | 2010-10-26 14:22:04 -0700 | [diff] [blame] | 937 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 938 | struct contig_page_info { |
| 939 | unsigned long free_pages; |
| 940 | unsigned long free_blocks_total; |
| 941 | unsigned long free_blocks_suitable; |
| 942 | }; |
| 943 | |
| 944 | /* |
| 945 | * Calculate the number of free pages in a zone, how many contiguous |
| 946 | * pages are free and how many are large enough to satisfy an allocation of |
| 947 | * the target size. Note that this function makes no attempt to estimate |
| 948 | * how many suitable free blocks there *might* be if MOVABLE pages were |
| 949 | * migrated. Calculating that is possible, but expensive and can be |
| 950 | * figured out from userspace |
| 951 | */ |
| 952 | static void fill_contig_page_info(struct zone *zone, |
| 953 | unsigned int suitable_order, |
| 954 | struct contig_page_info *info) |
| 955 | { |
| 956 | unsigned int order; |
| 957 | |
| 958 | info->free_pages = 0; |
| 959 | info->free_blocks_total = 0; |
| 960 | info->free_blocks_suitable = 0; |
| 961 | |
| 962 | for (order = 0; order < MAX_ORDER; order++) { |
| 963 | unsigned long blocks; |
| 964 | |
| 965 | /* Count number of free blocks */ |
| 966 | blocks = zone->free_area[order].nr_free; |
| 967 | info->free_blocks_total += blocks; |
| 968 | |
| 969 | /* Count free base pages */ |
| 970 | info->free_pages += blocks << order; |
| 971 | |
| 972 | /* Count the suitable free blocks */ |
| 973 | if (order >= suitable_order) |
| 974 | info->free_blocks_suitable += blocks << |
| 975 | (order - suitable_order); |
| 976 | } |
| 977 | } |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * A fragmentation index only makes sense if an allocation of a requested |
| 981 | * size would fail. If that is true, the fragmentation index indicates |
| 982 | * whether external fragmentation or a lack of memory was the problem. |
| 983 | * The value can be used to determine if page reclaim or compaction |
| 984 | * should be used |
| 985 | */ |
Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 986 | static int __fragmentation_index(unsigned int order, struct contig_page_info *info) |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 987 | { |
| 988 | unsigned long requested = 1UL << order; |
| 989 | |
Wen Yang | 88d6ac4 | 2017-09-06 16:24:06 -0700 | [diff] [blame] | 990 | if (WARN_ON_ONCE(order >= MAX_ORDER)) |
| 991 | return 0; |
| 992 | |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 993 | if (!info->free_blocks_total) |
| 994 | return 0; |
| 995 | |
| 996 | /* Fragmentation index only makes sense when a request would fail */ |
| 997 | if (info->free_blocks_suitable) |
| 998 | return -1000; |
| 999 | |
| 1000 | /* |
| 1001 | * Index is between 0 and 1 so return within 3 decimal places |
| 1002 | * |
| 1003 | * 0 => allocation would fail due to lack of memory |
| 1004 | * 1 => allocation would fail due to fragmentation |
| 1005 | */ |
| 1006 | return 1000 - div_u64( (1000+(div_u64(info->free_pages * 1000ULL, requested))), info->free_blocks_total); |
| 1007 | } |
Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 1008 | |
| 1009 | /* Same as __fragmentation index but allocs contig_page_info on stack */ |
| 1010 | int fragmentation_index(struct zone *zone, unsigned int order) |
| 1011 | { |
| 1012 | struct contig_page_info info; |
| 1013 | |
| 1014 | fill_contig_page_info(zone, order, &info); |
| 1015 | return __fragmentation_index(order, &info); |
| 1016 | } |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 1017 | #endif |
| 1018 | |
David Rientjes | 0d6617c | 2011-09-14 16:21:05 -0700 | [diff] [blame] | 1019 | #if defined(CONFIG_PROC_FS) || defined(CONFIG_SYSFS) || defined(CONFIG_NUMA) |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1020 | #ifdef CONFIG_ZONE_DMA |
| 1021 | #define TEXT_FOR_DMA(xx) xx "_dma", |
| 1022 | #else |
| 1023 | #define TEXT_FOR_DMA(xx) |
| 1024 | #endif |
| 1025 | |
| 1026 | #ifdef CONFIG_ZONE_DMA32 |
| 1027 | #define TEXT_FOR_DMA32(xx) xx "_dma32", |
| 1028 | #else |
| 1029 | #define TEXT_FOR_DMA32(xx) |
| 1030 | #endif |
| 1031 | |
| 1032 | #ifdef CONFIG_HIGHMEM |
| 1033 | #define TEXT_FOR_HIGHMEM(xx) xx "_high", |
| 1034 | #else |
| 1035 | #define TEXT_FOR_HIGHMEM(xx) |
| 1036 | #endif |
| 1037 | |
| 1038 | #define TEXTS_FOR_ZONES(xx) TEXT_FOR_DMA(xx) TEXT_FOR_DMA32(xx) xx "_normal", \ |
| 1039 | TEXT_FOR_HIGHMEM(xx) xx "_movable", |
| 1040 | |
| 1041 | const char * const vmstat_text[] = { |
Konstantin Khlebnikov | 09316c0 | 2014-10-09 15:29:32 -0700 | [diff] [blame] | 1042 | /* enum zone_stat_item countes */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1043 | "nr_free_pages", |
Minchan Kim | 71c799f | 2016-07-28 15:47:26 -0700 | [diff] [blame] | 1044 | "nr_zone_inactive_anon", |
| 1045 | "nr_zone_active_anon", |
| 1046 | "nr_zone_inactive_file", |
| 1047 | "nr_zone_active_file", |
| 1048 | "nr_zone_unevictable", |
Mel Gorman | 5a1c84b | 2016-07-28 15:47:31 -0700 | [diff] [blame] | 1049 | "nr_zone_write_pending", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1050 | "nr_mlock", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1051 | "nr_page_table_pages", |
| 1052 | "nr_kernel_stack", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1053 | "nr_bounce", |
Minchan Kim | 91537fe | 2016-07-26 15:24:45 -0700 | [diff] [blame] | 1054 | #if IS_ENABLED(CONFIG_ZSMALLOC) |
| 1055 | "nr_zspages", |
| 1056 | #endif |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1057 | "nr_free_cma", |
| 1058 | |
| 1059 | /* enum numa_stat_item counters */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1060 | #ifdef CONFIG_NUMA |
| 1061 | "numa_hit", |
| 1062 | "numa_miss", |
| 1063 | "numa_foreign", |
| 1064 | "numa_interleave", |
| 1065 | "numa_local", |
| 1066 | "numa_other", |
| 1067 | #endif |
Konstantin Khlebnikov | 09316c0 | 2014-10-09 15:29:32 -0700 | [diff] [blame] | 1068 | |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1069 | /* Node-based counters */ |
| 1070 | "nr_inactive_anon", |
| 1071 | "nr_active_anon", |
| 1072 | "nr_inactive_file", |
| 1073 | "nr_active_file", |
| 1074 | "nr_unevictable", |
Johannes Weiner | 385386c | 2017-07-06 15:40:43 -0700 | [diff] [blame] | 1075 | "nr_slab_reclaimable", |
| 1076 | "nr_slab_unreclaimable", |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1077 | "nr_isolated_anon", |
| 1078 | "nr_isolated_file", |
Mel Gorman | 1e6b1085 | 2016-07-28 15:46:08 -0700 | [diff] [blame] | 1079 | "workingset_refault", |
| 1080 | "workingset_activate", |
| 1081 | "workingset_nodereclaim", |
Mel Gorman | 50658e2 | 2016-07-28 15:46:14 -0700 | [diff] [blame] | 1082 | "nr_anon_pages", |
| 1083 | "nr_mapped", |
Mel Gorman | 11fb998 | 2016-07-28 15:46:20 -0700 | [diff] [blame] | 1084 | "nr_file_pages", |
| 1085 | "nr_dirty", |
| 1086 | "nr_writeback", |
| 1087 | "nr_writeback_temp", |
| 1088 | "nr_shmem", |
| 1089 | "nr_shmem_hugepages", |
| 1090 | "nr_shmem_pmdmapped", |
| 1091 | "nr_anon_transparent_hugepages", |
| 1092 | "nr_unstable", |
Mel Gorman | c4a2563 | 2016-07-28 15:46:23 -0700 | [diff] [blame] | 1093 | "nr_vmscan_write", |
| 1094 | "nr_vmscan_immediate_reclaim", |
| 1095 | "nr_dirtied", |
| 1096 | "nr_written", |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1097 | |
Konstantin Khlebnikov | 09316c0 | 2014-10-09 15:29:32 -0700 | [diff] [blame] | 1098 | /* enum writeback_stat_item counters */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1099 | "nr_dirty_threshold", |
| 1100 | "nr_dirty_background_threshold", |
| 1101 | |
| 1102 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Konstantin Khlebnikov | 09316c0 | 2014-10-09 15:29:32 -0700 | [diff] [blame] | 1103 | /* enum vm_event_item counters */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1104 | "pgpgin", |
| 1105 | "pgpgout", |
| 1106 | "pswpin", |
| 1107 | "pswpout", |
| 1108 | |
| 1109 | TEXTS_FOR_ZONES("pgalloc") |
Mel Gorman | 7cc30fc | 2016-07-28 15:46:59 -0700 | [diff] [blame] | 1110 | TEXTS_FOR_ZONES("allocstall") |
| 1111 | TEXTS_FOR_ZONES("pgskip") |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1112 | |
| 1113 | "pgfree", |
| 1114 | "pgactivate", |
| 1115 | "pgdeactivate", |
Shaohua Li | f7ad2a6 | 2017-05-03 14:52:29 -0700 | [diff] [blame] | 1116 | "pglazyfree", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1117 | |
| 1118 | "pgfault", |
| 1119 | "pgmajfault", |
Minchan Kim | 854e9ed | 2016-01-15 16:54:53 -0800 | [diff] [blame] | 1120 | "pglazyfreed", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1121 | |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1122 | "pgrefill", |
| 1123 | "pgsteal_kswapd", |
| 1124 | "pgsteal_direct", |
| 1125 | "pgscan_kswapd", |
| 1126 | "pgscan_direct", |
Mel Gorman | 68243e7 | 2012-07-31 16:44:39 -0700 | [diff] [blame] | 1127 | "pgscan_direct_throttle", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1128 | |
| 1129 | #ifdef CONFIG_NUMA |
| 1130 | "zone_reclaim_failed", |
| 1131 | #endif |
| 1132 | "pginodesteal", |
| 1133 | "slabs_scanned", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1134 | "kswapd_inodesteal", |
| 1135 | "kswapd_low_wmark_hit_quickly", |
| 1136 | "kswapd_high_wmark_hit_quickly", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1137 | "pageoutrun", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1138 | |
| 1139 | "pgrotated", |
| 1140 | |
Dave Hansen | 5509a5d | 2014-04-03 14:48:19 -0700 | [diff] [blame] | 1141 | "drop_pagecache", |
| 1142 | "drop_slab", |
Konstantin Khlebnikov | 8e675f7 | 2017-07-06 15:40:28 -0700 | [diff] [blame] | 1143 | "oom_kill", |
Dave Hansen | 5509a5d | 2014-04-03 14:48:19 -0700 | [diff] [blame] | 1144 | |
Mel Gorman | 03c5a6e | 2012-11-02 14:52:48 +0000 | [diff] [blame] | 1145 | #ifdef CONFIG_NUMA_BALANCING |
| 1146 | "numa_pte_updates", |
Mel Gorman | 72403b4 | 2013-11-12 15:08:32 -0800 | [diff] [blame] | 1147 | "numa_huge_pte_updates", |
Mel Gorman | 03c5a6e | 2012-11-02 14:52:48 +0000 | [diff] [blame] | 1148 | "numa_hint_faults", |
| 1149 | "numa_hint_faults_local", |
| 1150 | "numa_pages_migrated", |
| 1151 | #endif |
Mel Gorman | 5647bc2 | 2012-10-19 10:46:20 +0100 | [diff] [blame] | 1152 | #ifdef CONFIG_MIGRATION |
| 1153 | "pgmigrate_success", |
| 1154 | "pgmigrate_fail", |
| 1155 | #endif |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1156 | #ifdef CONFIG_COMPACTION |
Mel Gorman | 397487d | 2012-10-19 12:00:10 +0100 | [diff] [blame] | 1157 | "compact_migrate_scanned", |
| 1158 | "compact_free_scanned", |
| 1159 | "compact_isolated", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1160 | "compact_stall", |
| 1161 | "compact_fail", |
| 1162 | "compact_success", |
Vlastimil Babka | 698b1b3 | 2016-03-17 14:18:08 -0700 | [diff] [blame] | 1163 | "compact_daemon_wake", |
David Rientjes | 7f354a5 | 2017-02-22 15:44:50 -0800 | [diff] [blame] | 1164 | "compact_daemon_migrate_scanned", |
| 1165 | "compact_daemon_free_scanned", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1166 | #endif |
| 1167 | |
| 1168 | #ifdef CONFIG_HUGETLB_PAGE |
| 1169 | "htlb_buddy_alloc_success", |
| 1170 | "htlb_buddy_alloc_fail", |
| 1171 | #endif |
| 1172 | "unevictable_pgs_culled", |
| 1173 | "unevictable_pgs_scanned", |
| 1174 | "unevictable_pgs_rescued", |
| 1175 | "unevictable_pgs_mlocked", |
| 1176 | "unevictable_pgs_munlocked", |
| 1177 | "unevictable_pgs_cleared", |
| 1178 | "unevictable_pgs_stranded", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1179 | |
| 1180 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
| 1181 | "thp_fault_alloc", |
| 1182 | "thp_fault_fallback", |
| 1183 | "thp_collapse_alloc", |
| 1184 | "thp_collapse_alloc_failed", |
Kirill A. Shutemov | 95ecedc | 2016-07-26 15:25:31 -0700 | [diff] [blame] | 1185 | "thp_file_alloc", |
| 1186 | "thp_file_mapped", |
Kirill A. Shutemov | 122afea | 2016-01-15 16:52:46 -0800 | [diff] [blame] | 1187 | "thp_split_page", |
| 1188 | "thp_split_page_failed", |
Kirill A. Shutemov | f9719a0 | 2016-03-17 14:18:45 -0700 | [diff] [blame] | 1189 | "thp_deferred_split_page", |
Kirill A. Shutemov | 122afea | 2016-01-15 16:52:46 -0800 | [diff] [blame] | 1190 | "thp_split_pmd", |
Yisheng Xie | ce9311c | 2017-03-09 16:17:00 -0800 | [diff] [blame] | 1191 | #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD |
| 1192 | "thp_split_pud", |
| 1193 | #endif |
Kirill A. Shutemov | d8a8e1f | 2012-12-12 13:51:09 -0800 | [diff] [blame] | 1194 | "thp_zero_page_alloc", |
| 1195 | "thp_zero_page_alloc_failed", |
Huang Ying | 225311a | 2017-09-06 16:22:30 -0700 | [diff] [blame] | 1196 | "thp_swpout", |
Huang Ying | fe490cc | 2017-09-06 16:22:52 -0700 | [diff] [blame] | 1197 | "thp_swpout_fallback", |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1198 | #endif |
Konstantin Khlebnikov | 09316c0 | 2014-10-09 15:29:32 -0700 | [diff] [blame] | 1199 | #ifdef CONFIG_MEMORY_BALLOON |
| 1200 | "balloon_inflate", |
| 1201 | "balloon_deflate", |
| 1202 | #ifdef CONFIG_BALLOON_COMPACTION |
| 1203 | "balloon_migrate", |
| 1204 | #endif |
| 1205 | #endif /* CONFIG_MEMORY_BALLOON */ |
Mel Gorman | ec65993 | 2014-01-21 14:33:16 -0800 | [diff] [blame] | 1206 | #ifdef CONFIG_DEBUG_TLBFLUSH |
Dave Hansen | 6df4686 | 2013-09-11 14:20:24 -0700 | [diff] [blame] | 1207 | #ifdef CONFIG_SMP |
Dave Hansen | 9824cf9 | 2013-09-11 14:20:23 -0700 | [diff] [blame] | 1208 | "nr_tlb_remote_flush", |
| 1209 | "nr_tlb_remote_flush_received", |
Mel Gorman | ec65993 | 2014-01-21 14:33:16 -0800 | [diff] [blame] | 1210 | #endif /* CONFIG_SMP */ |
Dave Hansen | 9824cf9 | 2013-09-11 14:20:23 -0700 | [diff] [blame] | 1211 | "nr_tlb_local_flush_all", |
| 1212 | "nr_tlb_local_flush_one", |
Mel Gorman | ec65993 | 2014-01-21 14:33:16 -0800 | [diff] [blame] | 1213 | #endif /* CONFIG_DEBUG_TLBFLUSH */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1214 | |
Davidlohr Bueso | 4f11514 | 2014-06-04 16:06:46 -0700 | [diff] [blame] | 1215 | #ifdef CONFIG_DEBUG_VM_VMACACHE |
| 1216 | "vmacache_find_calls", |
| 1217 | "vmacache_find_hits", |
Davidlohr Bueso | f5f302e | 2014-12-12 16:56:10 -0800 | [diff] [blame] | 1218 | "vmacache_full_flushes", |
Davidlohr Bueso | 4f11514 | 2014-06-04 16:06:46 -0700 | [diff] [blame] | 1219 | #endif |
Huang Ying | cbc65df | 2017-09-06 16:24:29 -0700 | [diff] [blame] | 1220 | #ifdef CONFIG_SWAP |
| 1221 | "swap_ra", |
| 1222 | "swap_ra_hit", |
| 1223 | #endif |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1224 | #endif /* CONFIG_VM_EVENTS_COUNTERS */ |
| 1225 | }; |
David Rientjes | 0d6617c | 2011-09-14 16:21:05 -0700 | [diff] [blame] | 1226 | #endif /* CONFIG_PROC_FS || CONFIG_SYSFS || CONFIG_NUMA */ |
KOSAKI Motohiro | fa25c50 | 2011-05-24 17:11:28 -0700 | [diff] [blame] | 1227 | |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1228 | #if (defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION)) || \ |
| 1229 | defined(CONFIG_PROC_FS) |
| 1230 | static void *frag_start(struct seq_file *m, loff_t *pos) |
| 1231 | { |
| 1232 | pg_data_t *pgdat; |
| 1233 | loff_t node = *pos; |
| 1234 | |
| 1235 | for (pgdat = first_online_pgdat(); |
| 1236 | pgdat && node; |
| 1237 | pgdat = next_online_pgdat(pgdat)) |
| 1238 | --node; |
| 1239 | |
| 1240 | return pgdat; |
| 1241 | } |
| 1242 | |
| 1243 | static void *frag_next(struct seq_file *m, void *arg, loff_t *pos) |
| 1244 | { |
| 1245 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 1246 | |
| 1247 | (*pos)++; |
| 1248 | return next_online_pgdat(pgdat); |
| 1249 | } |
| 1250 | |
| 1251 | static void frag_stop(struct seq_file *m, void *arg) |
| 1252 | { |
| 1253 | } |
| 1254 | |
David Rientjes | b2bd859 | 2017-05-03 14:52:59 -0700 | [diff] [blame] | 1255 | /* |
| 1256 | * Walk zones in a node and print using a callback. |
| 1257 | * If @assert_populated is true, only use callback for zones that are populated. |
| 1258 | */ |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1259 | static void walk_zones_in_node(struct seq_file *m, pg_data_t *pgdat, |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1260 | bool assert_populated, bool nolock, |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1261 | void (*print)(struct seq_file *m, pg_data_t *, struct zone *)) |
| 1262 | { |
| 1263 | struct zone *zone; |
| 1264 | struct zone *node_zones = pgdat->node_zones; |
| 1265 | unsigned long flags; |
| 1266 | |
| 1267 | for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { |
David Rientjes | b2bd859 | 2017-05-03 14:52:59 -0700 | [diff] [blame] | 1268 | if (assert_populated && !populated_zone(zone)) |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1269 | continue; |
| 1270 | |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1271 | if (!nolock) |
| 1272 | spin_lock_irqsave(&zone->lock, flags); |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1273 | print(m, pgdat, zone); |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1274 | if (!nolock) |
| 1275 | spin_unlock_irqrestore(&zone->lock, flags); |
Andrew Morton | 3c48687 | 2015-02-10 14:09:43 -0800 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | #endif |
| 1279 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 1280 | #ifdef CONFIG_PROC_FS |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1281 | static void frag_show_print(struct seq_file *m, pg_data_t *pgdat, |
| 1282 | struct zone *zone) |
| 1283 | { |
| 1284 | int order; |
| 1285 | |
| 1286 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); |
| 1287 | for (order = 0; order < MAX_ORDER; ++order) |
| 1288 | seq_printf(m, "%6lu ", zone->free_area[order].nr_free); |
| 1289 | seq_putc(m, '\n'); |
| 1290 | } |
| 1291 | |
| 1292 | /* |
| 1293 | * This walks the free areas for each zone. |
| 1294 | */ |
| 1295 | static int frag_show(struct seq_file *m, void *arg) |
| 1296 | { |
| 1297 | pg_data_t *pgdat = (pg_data_t *)arg; |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1298 | walk_zones_in_node(m, pgdat, true, false, frag_show_print); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | static void pagetypeinfo_showfree_print(struct seq_file *m, |
| 1303 | pg_data_t *pgdat, struct zone *zone) |
| 1304 | { |
| 1305 | int order, mtype; |
| 1306 | |
| 1307 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) { |
| 1308 | seq_printf(m, "Node %4d, zone %8s, type %12s ", |
| 1309 | pgdat->node_id, |
| 1310 | zone->name, |
| 1311 | migratetype_names[mtype]); |
| 1312 | for (order = 0; order < MAX_ORDER; ++order) { |
| 1313 | unsigned long freecount = 0; |
| 1314 | struct free_area *area; |
| 1315 | struct list_head *curr; |
| 1316 | |
| 1317 | area = &(zone->free_area[order]); |
| 1318 | |
| 1319 | list_for_each(curr, &area->free_list[mtype]) |
| 1320 | freecount++; |
| 1321 | seq_printf(m, "%6lu ", freecount); |
| 1322 | } |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1323 | seq_putc(m, '\n'); |
| 1324 | } |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | /* Print out the free pages at each order for each migatetype */ |
| 1328 | static int pagetypeinfo_showfree(struct seq_file *m, void *arg) |
| 1329 | { |
| 1330 | int order; |
| 1331 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 1332 | |
| 1333 | /* Print header */ |
| 1334 | seq_printf(m, "%-43s ", "Free pages count per migrate type at order"); |
| 1335 | for (order = 0; order < MAX_ORDER; ++order) |
| 1336 | seq_printf(m, "%6d ", order); |
| 1337 | seq_putc(m, '\n'); |
| 1338 | |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1339 | walk_zones_in_node(m, pgdat, true, false, pagetypeinfo_showfree_print); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | static void pagetypeinfo_showblockcount_print(struct seq_file *m, |
| 1345 | pg_data_t *pgdat, struct zone *zone) |
| 1346 | { |
| 1347 | int mtype; |
| 1348 | unsigned long pfn; |
| 1349 | unsigned long start_pfn = zone->zone_start_pfn; |
Cody P Schafer | 108bcc9 | 2013-02-22 16:35:23 -0800 | [diff] [blame] | 1350 | unsigned long end_pfn = zone_end_pfn(zone); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1351 | unsigned long count[MIGRATE_TYPES] = { 0, }; |
| 1352 | |
| 1353 | for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) { |
| 1354 | struct page *page; |
| 1355 | |
Michal Hocko | d336e94 | 2017-07-06 15:38:07 -0700 | [diff] [blame] | 1356 | page = pfn_to_online_page(pfn); |
| 1357 | if (!page) |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1358 | continue; |
| 1359 | |
Mel Gorman | eb33575 | 2009-05-13 17:34:48 +0100 | [diff] [blame] | 1360 | /* Watch for unexpected holes punched in the memmap */ |
| 1361 | if (!memmap_valid_within(pfn, page, zone)) |
Mel Gorman | e80d6a2 | 2008-08-14 11:10:14 +0100 | [diff] [blame] | 1362 | continue; |
Mel Gorman | eb33575 | 2009-05-13 17:34:48 +0100 | [diff] [blame] | 1363 | |
Joonsoo Kim | a91c43c | 2016-05-19 17:12:10 -0700 | [diff] [blame] | 1364 | if (page_zone(page) != zone) |
| 1365 | continue; |
| 1366 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1367 | mtype = get_pageblock_migratetype(page); |
| 1368 | |
Mel Gorman | e80d6a2 | 2008-08-14 11:10:14 +0100 | [diff] [blame] | 1369 | if (mtype < MIGRATE_TYPES) |
| 1370 | count[mtype]++; |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /* Print counts */ |
| 1374 | seq_printf(m, "Node %d, zone %8s ", pgdat->node_id, zone->name); |
| 1375 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) |
| 1376 | seq_printf(m, "%12lu ", count[mtype]); |
| 1377 | seq_putc(m, '\n'); |
| 1378 | } |
| 1379 | |
SeongJae Park | f113e64 | 2017-09-06 16:24:23 -0700 | [diff] [blame] | 1380 | /* Print out the number of pageblocks for each migratetype */ |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1381 | static int pagetypeinfo_showblockcount(struct seq_file *m, void *arg) |
| 1382 | { |
| 1383 | int mtype; |
| 1384 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 1385 | |
| 1386 | seq_printf(m, "\n%-23s", "Number of blocks type "); |
| 1387 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) |
| 1388 | seq_printf(m, "%12s ", migratetype_names[mtype]); |
| 1389 | seq_putc(m, '\n'); |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1390 | walk_zones_in_node(m, pgdat, true, false, |
| 1391 | pagetypeinfo_showblockcount_print); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1392 | |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
Joonsoo Kim | 48c96a3 | 2014-12-12 16:56:01 -0800 | [diff] [blame] | 1396 | /* |
| 1397 | * Print out the number of pageblocks for each migratetype that contain pages |
| 1398 | * of other types. This gives an indication of how well fallbacks are being |
| 1399 | * contained by rmqueue_fallback(). It requires information from PAGE_OWNER |
| 1400 | * to determine what is going on |
| 1401 | */ |
| 1402 | static void pagetypeinfo_showmixedcount(struct seq_file *m, pg_data_t *pgdat) |
| 1403 | { |
| 1404 | #ifdef CONFIG_PAGE_OWNER |
| 1405 | int mtype; |
| 1406 | |
Vlastimil Babka | 7dd80b8 | 2016-03-15 14:56:12 -0700 | [diff] [blame] | 1407 | if (!static_branch_unlikely(&page_owner_inited)) |
Joonsoo Kim | 48c96a3 | 2014-12-12 16:56:01 -0800 | [diff] [blame] | 1408 | return; |
| 1409 | |
| 1410 | drain_all_pages(NULL); |
| 1411 | |
| 1412 | seq_printf(m, "\n%-23s", "Number of mixed blocks "); |
| 1413 | for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) |
| 1414 | seq_printf(m, "%12s ", migratetype_names[mtype]); |
| 1415 | seq_putc(m, '\n'); |
| 1416 | |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1417 | walk_zones_in_node(m, pgdat, true, true, |
| 1418 | pagetypeinfo_showmixedcount_print); |
Joonsoo Kim | 48c96a3 | 2014-12-12 16:56:01 -0800 | [diff] [blame] | 1419 | #endif /* CONFIG_PAGE_OWNER */ |
| 1420 | } |
| 1421 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1422 | /* |
| 1423 | * This prints out statistics in relation to grouping pages by mobility. |
| 1424 | * It is expensive to collect so do not constantly read the file. |
| 1425 | */ |
| 1426 | static int pagetypeinfo_show(struct seq_file *m, void *arg) |
| 1427 | { |
| 1428 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 1429 | |
KOSAKI Motohiro | 41b25a3 | 2008-04-30 00:52:13 -0700 | [diff] [blame] | 1430 | /* check memoryless node */ |
Lai Jiangshan | a47b53c | 2012-12-12 13:51:37 -0800 | [diff] [blame] | 1431 | if (!node_state(pgdat->node_id, N_MEMORY)) |
KOSAKI Motohiro | 41b25a3 | 2008-04-30 00:52:13 -0700 | [diff] [blame] | 1432 | return 0; |
| 1433 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1434 | seq_printf(m, "Page block order: %d\n", pageblock_order); |
| 1435 | seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages); |
| 1436 | seq_putc(m, '\n'); |
| 1437 | pagetypeinfo_showfree(m, pgdat); |
| 1438 | pagetypeinfo_showblockcount(m, pgdat); |
Joonsoo Kim | 48c96a3 | 2014-12-12 16:56:01 -0800 | [diff] [blame] | 1439 | pagetypeinfo_showmixedcount(m, pgdat); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1440 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1441 | return 0; |
| 1442 | } |
| 1443 | |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1444 | static const struct seq_operations fragmentation_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1445 | .start = frag_start, |
| 1446 | .next = frag_next, |
| 1447 | .stop = frag_stop, |
| 1448 | .show = frag_show, |
| 1449 | }; |
| 1450 | |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1451 | static int fragmentation_open(struct inode *inode, struct file *file) |
| 1452 | { |
| 1453 | return seq_open(file, &fragmentation_op); |
| 1454 | } |
| 1455 | |
Anshuman Khandual | 9d85e15 | 2017-07-06 15:37:15 -0700 | [diff] [blame] | 1456 | static const struct file_operations buddyinfo_file_operations = { |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1457 | .open = fragmentation_open, |
| 1458 | .read = seq_read, |
| 1459 | .llseek = seq_lseek, |
| 1460 | .release = seq_release, |
| 1461 | }; |
| 1462 | |
Alexey Dobriyan | 74e2e8e | 2008-10-06 04:15:36 +0400 | [diff] [blame] | 1463 | static const struct seq_operations pagetypeinfo_op = { |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1464 | .start = frag_start, |
| 1465 | .next = frag_next, |
| 1466 | .stop = frag_stop, |
| 1467 | .show = pagetypeinfo_show, |
| 1468 | }; |
| 1469 | |
Alexey Dobriyan | 74e2e8e | 2008-10-06 04:15:36 +0400 | [diff] [blame] | 1470 | static int pagetypeinfo_open(struct inode *inode, struct file *file) |
| 1471 | { |
| 1472 | return seq_open(file, &pagetypeinfo_op); |
| 1473 | } |
| 1474 | |
Anshuman Khandual | 9d85e15 | 2017-07-06 15:37:15 -0700 | [diff] [blame] | 1475 | static const struct file_operations pagetypeinfo_file_operations = { |
Alexey Dobriyan | 74e2e8e | 2008-10-06 04:15:36 +0400 | [diff] [blame] | 1476 | .open = pagetypeinfo_open, |
| 1477 | .read = seq_read, |
| 1478 | .llseek = seq_lseek, |
| 1479 | .release = seq_release, |
| 1480 | }; |
| 1481 | |
Mel Gorman | e2ecc8a | 2016-07-28 15:47:02 -0700 | [diff] [blame] | 1482 | static bool is_zone_first_populated(pg_data_t *pgdat, struct zone *zone) |
| 1483 | { |
| 1484 | int zid; |
| 1485 | |
| 1486 | for (zid = 0; zid < MAX_NR_ZONES; zid++) { |
| 1487 | struct zone *compare = &pgdat->node_zones[zid]; |
| 1488 | |
| 1489 | if (populated_zone(compare)) |
| 1490 | return zone == compare; |
| 1491 | } |
| 1492 | |
Mel Gorman | e2ecc8a | 2016-07-28 15:47:02 -0700 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
| 1495 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1496 | static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat, |
| 1497 | struct zone *zone) |
| 1498 | { |
| 1499 | int i; |
| 1500 | seq_printf(m, "Node %d, zone %8s", pgdat->node_id, zone->name); |
Mel Gorman | e2ecc8a | 2016-07-28 15:47:02 -0700 | [diff] [blame] | 1501 | if (is_zone_first_populated(pgdat, zone)) { |
| 1502 | seq_printf(m, "\n per-node stats"); |
| 1503 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) { |
| 1504 | seq_printf(m, "\n %-12s %lu", |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1505 | vmstat_text[i + NR_VM_ZONE_STAT_ITEMS + |
| 1506 | NR_VM_NUMA_STAT_ITEMS], |
Mel Gorman | e2ecc8a | 2016-07-28 15:47:02 -0700 | [diff] [blame] | 1507 | node_page_state(pgdat, i)); |
| 1508 | } |
| 1509 | } |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1510 | seq_printf(m, |
| 1511 | "\n pages free %lu" |
| 1512 | "\n min %lu" |
| 1513 | "\n low %lu" |
| 1514 | "\n high %lu" |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1515 | "\n spanned %lu" |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 1516 | "\n present %lu" |
| 1517 | "\n managed %lu", |
Mel Gorman | 88f5acf | 2011-01-13 15:45:41 -0800 | [diff] [blame] | 1518 | zone_page_state(zone, NR_FREE_PAGES), |
Mel Gorman | 4185896 | 2009-06-16 15:32:12 -0700 | [diff] [blame] | 1519 | min_wmark_pages(zone), |
| 1520 | low_wmark_pages(zone), |
| 1521 | high_wmark_pages(zone), |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1522 | zone->spanned_pages, |
Jiang Liu | 9feedc9 | 2012-12-12 13:52:12 -0800 | [diff] [blame] | 1523 | zone->present_pages, |
| 1524 | zone->managed_pages); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1525 | |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1526 | seq_printf(m, |
Mel Gorman | 3484b2d | 2014-08-06 16:07:14 -0700 | [diff] [blame] | 1527 | "\n protection: (%ld", |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1528 | zone->lowmem_reserve[0]); |
| 1529 | for (i = 1; i < ARRAY_SIZE(zone->lowmem_reserve); i++) |
Mel Gorman | 3484b2d | 2014-08-06 16:07:14 -0700 | [diff] [blame] | 1530 | seq_printf(m, ", %ld", zone->lowmem_reserve[i]); |
David Rientjes | 7dfb8bf | 2017-05-03 14:53:02 -0700 | [diff] [blame] | 1531 | seq_putc(m, ')'); |
| 1532 | |
| 1533 | /* If unpopulated, no other information is useful */ |
| 1534 | if (!populated_zone(zone)) { |
| 1535 | seq_putc(m, '\n'); |
| 1536 | return; |
| 1537 | } |
| 1538 | |
| 1539 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
| 1540 | seq_printf(m, "\n %-12s %lu", vmstat_text[i], |
| 1541 | zone_page_state(zone, i)); |
| 1542 | |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1543 | #ifdef CONFIG_NUMA |
| 1544 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) |
| 1545 | seq_printf(m, "\n %-12s %lu", |
| 1546 | vmstat_text[i + NR_VM_ZONE_STAT_ITEMS], |
| 1547 | zone_numa_state(zone, i)); |
| 1548 | #endif |
| 1549 | |
David Rientjes | 7dfb8bf | 2017-05-03 14:53:02 -0700 | [diff] [blame] | 1550 | seq_printf(m, "\n pagesets"); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1551 | for_each_online_cpu(i) { |
| 1552 | struct per_cpu_pageset *pageset; |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1553 | |
Christoph Lameter | 99dcc3e | 2010-01-05 15:34:51 +0900 | [diff] [blame] | 1554 | pageset = per_cpu_ptr(zone->pageset, i); |
Christoph Lameter | 3dfa572 | 2008-02-04 22:29:19 -0800 | [diff] [blame] | 1555 | seq_printf(m, |
| 1556 | "\n cpu: %i" |
| 1557 | "\n count: %i" |
| 1558 | "\n high: %i" |
| 1559 | "\n batch: %i", |
| 1560 | i, |
| 1561 | pageset->pcp.count, |
| 1562 | pageset->pcp.high, |
| 1563 | pageset->pcp.batch); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1564 | #ifdef CONFIG_SMP |
| 1565 | seq_printf(m, "\n vm stats threshold: %d", |
| 1566 | pageset->stat_threshold); |
| 1567 | #endif |
| 1568 | } |
| 1569 | seq_printf(m, |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1570 | "\n node_unreclaimable: %u" |
| 1571 | "\n start_pfn: %lu" |
| 1572 | "\n node_inactive_ratio: %u", |
Johannes Weiner | c73322d | 2017-05-03 14:51:51 -0700 | [diff] [blame] | 1573 | pgdat->kswapd_failures >= MAX_RECLAIM_RETRIES, |
Rik van Riel | 556adec | 2008-10-18 20:26:34 -0700 | [diff] [blame] | 1574 | zone->zone_start_pfn, |
Mel Gorman | 599d0c9 | 2016-07-28 15:45:31 -0700 | [diff] [blame] | 1575 | zone->zone_pgdat->inactive_ratio); |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1576 | seq_putc(m, '\n'); |
| 1577 | } |
| 1578 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1579 | /* |
David Rientjes | b2bd859 | 2017-05-03 14:52:59 -0700 | [diff] [blame] | 1580 | * Output information about zones in @pgdat. All zones are printed regardless |
| 1581 | * of whether they are populated or not: lowmem_reserve_ratio operates on the |
| 1582 | * set of all zones and userspace would not be aware of such zones if they are |
| 1583 | * suppressed here (zoneinfo displays the effect of lowmem_reserve_ratio). |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1584 | */ |
| 1585 | static int zoneinfo_show(struct seq_file *m, void *arg) |
| 1586 | { |
Mel Gorman | 467c996 | 2007-10-16 01:26:02 -0700 | [diff] [blame] | 1587 | pg_data_t *pgdat = (pg_data_t *)arg; |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 1588 | walk_zones_in_node(m, pgdat, false, false, zoneinfo_show_print); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1589 | return 0; |
| 1590 | } |
| 1591 | |
Alexey Dobriyan | 5c9fe62 | 2008-10-06 04:19:42 +0400 | [diff] [blame] | 1592 | static const struct seq_operations zoneinfo_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1593 | .start = frag_start, /* iterate over all zones. The same as in |
| 1594 | * fragmentation. */ |
| 1595 | .next = frag_next, |
| 1596 | .stop = frag_stop, |
| 1597 | .show = zoneinfo_show, |
| 1598 | }; |
| 1599 | |
Alexey Dobriyan | 5c9fe62 | 2008-10-06 04:19:42 +0400 | [diff] [blame] | 1600 | static int zoneinfo_open(struct inode *inode, struct file *file) |
| 1601 | { |
| 1602 | return seq_open(file, &zoneinfo_op); |
| 1603 | } |
| 1604 | |
Anshuman Khandual | 9d85e15 | 2017-07-06 15:37:15 -0700 | [diff] [blame] | 1605 | static const struct file_operations zoneinfo_file_operations = { |
Alexey Dobriyan | 5c9fe62 | 2008-10-06 04:19:42 +0400 | [diff] [blame] | 1606 | .open = zoneinfo_open, |
| 1607 | .read = seq_read, |
| 1608 | .llseek = seq_lseek, |
| 1609 | .release = seq_release, |
| 1610 | }; |
| 1611 | |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1612 | enum writeback_stat_item { |
| 1613 | NR_DIRTY_THRESHOLD, |
| 1614 | NR_DIRTY_BG_THRESHOLD, |
| 1615 | NR_VM_WRITEBACK_STAT_ITEMS, |
| 1616 | }; |
| 1617 | |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1618 | static void *vmstat_start(struct seq_file *m, loff_t *pos) |
| 1619 | { |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 1620 | unsigned long *v; |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1621 | int i, stat_items_size; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1622 | |
| 1623 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 1624 | return NULL; |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1625 | stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) + |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1626 | NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) + |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 1627 | NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) + |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1628 | NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1629 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 1630 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1631 | stat_items_size += sizeof(struct vm_event_state); |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 1632 | #endif |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1633 | |
| 1634 | v = kmalloc(stat_items_size, GFP_KERNEL); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 1635 | m->private = v; |
| 1636 | if (!v) |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1637 | return ERR_PTR(-ENOMEM); |
Christoph Lameter | 2244b95 | 2006-06-30 01:55:33 -0700 | [diff] [blame] | 1638 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) |
Michal Hocko | c41f012 | 2017-09-06 16:23:36 -0700 | [diff] [blame] | 1639 | v[i] = global_zone_page_state(i); |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1640 | v += NR_VM_ZONE_STAT_ITEMS; |
| 1641 | |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1642 | #ifdef CONFIG_NUMA |
| 1643 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) |
| 1644 | v[i] = global_numa_state(i); |
| 1645 | v += NR_VM_NUMA_STAT_ITEMS; |
| 1646 | #endif |
| 1647 | |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 1648 | for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++) |
| 1649 | v[i] = global_node_page_state(i); |
| 1650 | v += NR_VM_NODE_STAT_ITEMS; |
| 1651 | |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1652 | global_dirty_limits(v + NR_DIRTY_BG_THRESHOLD, |
| 1653 | v + NR_DIRTY_THRESHOLD); |
| 1654 | v += NR_VM_WRITEBACK_STAT_ITEMS; |
| 1655 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 1656 | #ifdef CONFIG_VM_EVENT_COUNTERS |
Michael Rubin | 79da826 | 2010-10-26 14:21:36 -0700 | [diff] [blame] | 1657 | all_vm_events(v); |
| 1658 | v[PGPGIN] /= 2; /* sectors -> kbytes */ |
| 1659 | v[PGPGOUT] /= 2; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 1660 | #endif |
Wu Fengguang | ff8b16d | 2010-11-04 01:56:49 +0800 | [diff] [blame] | 1661 | return (unsigned long *)m->private + *pos; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) |
| 1665 | { |
| 1666 | (*pos)++; |
| 1667 | if (*pos >= ARRAY_SIZE(vmstat_text)) |
| 1668 | return NULL; |
| 1669 | return (unsigned long *)m->private + *pos; |
| 1670 | } |
| 1671 | |
| 1672 | static int vmstat_show(struct seq_file *m, void *arg) |
| 1673 | { |
| 1674 | unsigned long *l = arg; |
| 1675 | unsigned long off = l - (unsigned long *)m->private; |
Alexey Dobriyan | 68ba032 | 2016-10-07 17:02:14 -0700 | [diff] [blame] | 1676 | |
| 1677 | seq_puts(m, vmstat_text[off]); |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 1678 | seq_put_decimal_ull(m, " ", *l); |
Alexey Dobriyan | 68ba032 | 2016-10-07 17:02:14 -0700 | [diff] [blame] | 1679 | seq_putc(m, '\n'); |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1680 | return 0; |
| 1681 | } |
| 1682 | |
| 1683 | static void vmstat_stop(struct seq_file *m, void *arg) |
| 1684 | { |
| 1685 | kfree(m->private); |
| 1686 | m->private = NULL; |
| 1687 | } |
| 1688 | |
Alexey Dobriyan | b6aa44a | 2008-10-06 04:17:48 +0400 | [diff] [blame] | 1689 | static const struct seq_operations vmstat_op = { |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1690 | .start = vmstat_start, |
| 1691 | .next = vmstat_next, |
| 1692 | .stop = vmstat_stop, |
| 1693 | .show = vmstat_show, |
| 1694 | }; |
| 1695 | |
Alexey Dobriyan | b6aa44a | 2008-10-06 04:17:48 +0400 | [diff] [blame] | 1696 | static int vmstat_open(struct inode *inode, struct file *file) |
| 1697 | { |
| 1698 | return seq_open(file, &vmstat_op); |
| 1699 | } |
| 1700 | |
Anshuman Khandual | 9d85e15 | 2017-07-06 15:37:15 -0700 | [diff] [blame] | 1701 | static const struct file_operations vmstat_file_operations = { |
Alexey Dobriyan | b6aa44a | 2008-10-06 04:17:48 +0400 | [diff] [blame] | 1702 | .open = vmstat_open, |
| 1703 | .read = seq_read, |
| 1704 | .llseek = seq_lseek, |
| 1705 | .release = seq_release, |
| 1706 | }; |
Christoph Lameter | f6ac235 | 2006-06-30 01:55:32 -0700 | [diff] [blame] | 1707 | #endif /* CONFIG_PROC_FS */ |
| 1708 | |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 1709 | #ifdef CONFIG_SMP |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1710 | static DEFINE_PER_CPU(struct delayed_work, vmstat_work); |
Christoph Lameter | 77461ab | 2007-05-09 02:35:13 -0700 | [diff] [blame] | 1711 | int sysctl_stat_interval __read_mostly = HZ; |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1712 | |
Hugh Dickins | 52b6f46 | 2016-05-19 17:12:50 -0700 | [diff] [blame] | 1713 | #ifdef CONFIG_PROC_FS |
| 1714 | static void refresh_vm_stats(struct work_struct *work) |
| 1715 | { |
| 1716 | refresh_cpu_vm_stats(true); |
| 1717 | } |
| 1718 | |
| 1719 | int vmstat_refresh(struct ctl_table *table, int write, |
| 1720 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 1721 | { |
| 1722 | long val; |
| 1723 | int err; |
| 1724 | int i; |
| 1725 | |
| 1726 | /* |
| 1727 | * The regular update, every sysctl_stat_interval, may come later |
| 1728 | * than expected: leaving a significant amount in per_cpu buckets. |
| 1729 | * This is particularly misleading when checking a quantity of HUGE |
| 1730 | * pages, immediately after running a test. /proc/sys/vm/stat_refresh, |
| 1731 | * which can equally be echo'ed to or cat'ted from (by root), |
| 1732 | * can be used to update the stats just before reading them. |
| 1733 | * |
Michal Hocko | c41f012 | 2017-09-06 16:23:36 -0700 | [diff] [blame] | 1734 | * Oh, and since global_zone_page_state() etc. are so careful to hide |
Hugh Dickins | 52b6f46 | 2016-05-19 17:12:50 -0700 | [diff] [blame] | 1735 | * transiently negative values, report an error here if any of |
| 1736 | * the stats is negative, so we know to go looking for imbalance. |
| 1737 | */ |
| 1738 | err = schedule_on_each_cpu(refresh_vm_stats); |
| 1739 | if (err) |
| 1740 | return err; |
| 1741 | for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) { |
Mel Gorman | 75ef718 | 2016-07-28 15:45:24 -0700 | [diff] [blame] | 1742 | val = atomic_long_read(&vm_zone_stat[i]); |
Hugh Dickins | 52b6f46 | 2016-05-19 17:12:50 -0700 | [diff] [blame] | 1743 | if (val < 0) { |
Johannes Weiner | c822f62 | 2017-05-03 14:52:10 -0700 | [diff] [blame] | 1744 | pr_warn("%s: %s %ld\n", |
| 1745 | __func__, vmstat_text[i], val); |
| 1746 | err = -EINVAL; |
Hugh Dickins | 52b6f46 | 2016-05-19 17:12:50 -0700 | [diff] [blame] | 1747 | } |
| 1748 | } |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1749 | #ifdef CONFIG_NUMA |
| 1750 | for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++) { |
| 1751 | val = atomic_long_read(&vm_numa_stat[i]); |
| 1752 | if (val < 0) { |
| 1753 | pr_warn("%s: %s %ld\n", |
| 1754 | __func__, vmstat_text[i + NR_VM_ZONE_STAT_ITEMS], val); |
| 1755 | err = -EINVAL; |
| 1756 | } |
| 1757 | } |
| 1758 | #endif |
Hugh Dickins | 52b6f46 | 2016-05-19 17:12:50 -0700 | [diff] [blame] | 1759 | if (err) |
| 1760 | return err; |
| 1761 | if (write) |
| 1762 | *ppos += *lenp; |
| 1763 | else |
| 1764 | *lenp = 0; |
| 1765 | return 0; |
| 1766 | } |
| 1767 | #endif /* CONFIG_PROC_FS */ |
| 1768 | |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1769 | static void vmstat_update(struct work_struct *w) |
| 1770 | { |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 1771 | if (refresh_cpu_vm_stats(true)) { |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1772 | /* |
| 1773 | * Counters were updated so we expect more updates |
| 1774 | * to occur in the future. Keep on running the |
| 1775 | * update worker thread. |
| 1776 | */ |
Michal Hocko | ce61287 | 2017-04-07 16:05:05 -0700 | [diff] [blame] | 1777 | queue_delayed_work_on(smp_processor_id(), mm_percpu_wq, |
Michal Hocko | f01f17d | 2016-02-05 15:36:24 -0800 | [diff] [blame] | 1778 | this_cpu_ptr(&vmstat_work), |
| 1779 | round_jiffies_relative(sysctl_stat_interval)); |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1780 | } |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1783 | /* |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 1784 | * Switch off vmstat processing and then fold all the remaining differentials |
| 1785 | * until the diffs stay at zero. The function is used by NOHZ and can only be |
| 1786 | * invoked when tick processing is not active. |
| 1787 | */ |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 1788 | /* |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1789 | * Check if the diffs for a certain cpu indicate that |
| 1790 | * an update is needed. |
| 1791 | */ |
| 1792 | static bool need_update(int cpu) |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1793 | { |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1794 | struct zone *zone; |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1795 | |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1796 | for_each_populated_zone(zone) { |
| 1797 | struct per_cpu_pageset *p = per_cpu_ptr(zone->pageset, cpu); |
| 1798 | |
| 1799 | BUILD_BUG_ON(sizeof(p->vm_stat_diff[0]) != 1); |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1800 | #ifdef CONFIG_NUMA |
| 1801 | BUILD_BUG_ON(sizeof(p->vm_numa_stat_diff[0]) != 1); |
| 1802 | #endif |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1803 | /* |
| 1804 | * The fast way of checking if there are any vmstat diffs. |
| 1805 | * This works because the diffs are byte sized items. |
| 1806 | */ |
| 1807 | if (memchr_inv(p->vm_stat_diff, 0, NR_VM_ZONE_STAT_ITEMS)) |
| 1808 | return true; |
Kemi Wang | 3a321d2 | 2017-09-08 16:12:48 -0700 | [diff] [blame^] | 1809 | #ifdef CONFIG_NUMA |
| 1810 | if (memchr_inv(p->vm_numa_stat_diff, 0, NR_VM_NUMA_STAT_ITEMS)) |
| 1811 | return true; |
| 1812 | #endif |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1813 | } |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
Christoph Lameter | 7b8da4c | 2016-05-20 16:58:21 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * Switch off vmstat processing and then fold all the remaining differentials |
| 1819 | * until the diffs stay at zero. The function is used by NOHZ and can only be |
| 1820 | * invoked when tick processing is not active. |
| 1821 | */ |
Michal Hocko | f01f17d | 2016-02-05 15:36:24 -0800 | [diff] [blame] | 1822 | void quiet_vmstat(void) |
| 1823 | { |
| 1824 | if (system_state != SYSTEM_RUNNING) |
| 1825 | return; |
| 1826 | |
Christoph Lameter | 7b8da4c | 2016-05-20 16:58:21 -0700 | [diff] [blame] | 1827 | if (!delayed_work_pending(this_cpu_ptr(&vmstat_work))) |
Michal Hocko | f01f17d | 2016-02-05 15:36:24 -0800 | [diff] [blame] | 1828 | return; |
| 1829 | |
| 1830 | if (!need_update(smp_processor_id())) |
| 1831 | return; |
| 1832 | |
| 1833 | /* |
| 1834 | * Just refresh counters and do not care about the pending delayed |
| 1835 | * vmstat_update. It doesn't fire that often to matter and canceling |
| 1836 | * it would be too expensive from this path. |
| 1837 | * vmstat_shepherd will take care about that for us. |
| 1838 | */ |
| 1839 | refresh_cpu_vm_stats(false); |
| 1840 | } |
| 1841 | |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1842 | /* |
| 1843 | * Shepherd worker thread that checks the |
| 1844 | * differentials of processors that have their worker |
| 1845 | * threads for vm statistics updates disabled because of |
| 1846 | * inactivity. |
| 1847 | */ |
| 1848 | static void vmstat_shepherd(struct work_struct *w); |
| 1849 | |
Christoph Lameter | 0eb77e9 | 2016-01-14 15:21:40 -0800 | [diff] [blame] | 1850 | static DECLARE_DEFERRABLE_WORK(shepherd, vmstat_shepherd); |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1851 | |
| 1852 | static void vmstat_shepherd(struct work_struct *w) |
| 1853 | { |
| 1854 | int cpu; |
| 1855 | |
| 1856 | get_online_cpus(); |
| 1857 | /* Check processors whose vmstat worker threads have been disabled */ |
Christoph Lameter | 7b8da4c | 2016-05-20 16:58:21 -0700 | [diff] [blame] | 1858 | for_each_online_cpu(cpu) { |
Michal Hocko | f01f17d | 2016-02-05 15:36:24 -0800 | [diff] [blame] | 1859 | struct delayed_work *dw = &per_cpu(vmstat_work, cpu); |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1860 | |
Christoph Lameter | 7b8da4c | 2016-05-20 16:58:21 -0700 | [diff] [blame] | 1861 | if (!delayed_work_pending(dw) && need_update(cpu)) |
Michal Hocko | ce61287 | 2017-04-07 16:05:05 -0700 | [diff] [blame] | 1862 | queue_delayed_work_on(cpu, mm_percpu_wq, dw, 0); |
Michal Hocko | f01f17d | 2016-02-05 15:36:24 -0800 | [diff] [blame] | 1863 | } |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1864 | put_online_cpus(); |
| 1865 | |
| 1866 | schedule_delayed_work(&shepherd, |
| 1867 | round_jiffies_relative(sysctl_stat_interval)); |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | static void __init start_shepherd_timer(void) |
| 1871 | { |
| 1872 | int cpu; |
| 1873 | |
| 1874 | for_each_possible_cpu(cpu) |
Michal Hocko | ccde8bd | 2016-02-05 15:36:27 -0800 | [diff] [blame] | 1875 | INIT_DEFERRABLE_WORK(per_cpu_ptr(&vmstat_work, cpu), |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1876 | vmstat_update); |
| 1877 | |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1878 | schedule_delayed_work(&shepherd, |
| 1879 | round_jiffies_relative(sysctl_stat_interval)); |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Tim Chen | 03e86db | 2016-10-07 17:00:02 -0700 | [diff] [blame] | 1882 | static void __init init_cpu_node_state(void) |
| 1883 | { |
Sebastian Andrzej Siewior | 4c50132 | 2016-11-29 15:51:14 +0100 | [diff] [blame] | 1884 | int node; |
Tim Chen | 03e86db | 2016-10-07 17:00:02 -0700 | [diff] [blame] | 1885 | |
Sebastian Andrzej Siewior | 4c50132 | 2016-11-29 15:51:14 +0100 | [diff] [blame] | 1886 | for_each_online_node(node) { |
| 1887 | if (cpumask_weight(cpumask_of_node(node)) > 0) |
| 1888 | node_set_state(node, N_CPU); |
| 1889 | } |
Tim Chen | 03e86db | 2016-10-07 17:00:02 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1892 | static int vmstat_cpu_online(unsigned int cpu) |
| 1893 | { |
| 1894 | refresh_zone_stat_thresholds(); |
| 1895 | node_set_state(cpu_to_node(cpu), N_CPU); |
| 1896 | return 0; |
| 1897 | } |
| 1898 | |
| 1899 | static int vmstat_cpu_down_prep(unsigned int cpu) |
| 1900 | { |
| 1901 | cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu)); |
| 1902 | return 0; |
| 1903 | } |
| 1904 | |
| 1905 | static int vmstat_cpu_dead(unsigned int cpu) |
Toshi Kani | 807a1bd | 2013-11-12 15:08:13 -0800 | [diff] [blame] | 1906 | { |
Sebastian Andrzej Siewior | 4c50132 | 2016-11-29 15:51:14 +0100 | [diff] [blame] | 1907 | const struct cpumask *node_cpus; |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1908 | int node; |
Toshi Kani | 807a1bd | 2013-11-12 15:08:13 -0800 | [diff] [blame] | 1909 | |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1910 | node = cpu_to_node(cpu); |
| 1911 | |
| 1912 | refresh_zone_stat_thresholds(); |
Sebastian Andrzej Siewior | 4c50132 | 2016-11-29 15:51:14 +0100 | [diff] [blame] | 1913 | node_cpus = cpumask_of_node(node); |
| 1914 | if (cpumask_weight(node_cpus) > 0) |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1915 | return 0; |
Toshi Kani | 807a1bd | 2013-11-12 15:08:13 -0800 | [diff] [blame] | 1916 | |
| 1917 | node_clear_state(node, N_CPU); |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1918 | return 0; |
Toshi Kani | 807a1bd | 2013-11-12 15:08:13 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1921 | #endif |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 1922 | |
Michal Hocko | ce61287 | 2017-04-07 16:05:05 -0700 | [diff] [blame] | 1923 | struct workqueue_struct *mm_percpu_wq; |
| 1924 | |
Michal Hocko | 597b730 | 2017-03-31 15:11:47 -0700 | [diff] [blame] | 1925 | void __init init_mm_internals(void) |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 1926 | { |
Michal Hocko | ce61287 | 2017-04-07 16:05:05 -0700 | [diff] [blame] | 1927 | int ret __maybe_unused; |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1928 | |
Michal Hocko | 80d136e | 2017-04-19 09:52:46 +0200 | [diff] [blame] | 1929 | mm_percpu_wq = alloc_workqueue("mm_percpu_wq", WQ_MEM_RECLAIM, 0); |
Michal Hocko | ce61287 | 2017-04-07 16:05:05 -0700 | [diff] [blame] | 1930 | |
| 1931 | #ifdef CONFIG_SMP |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1932 | ret = cpuhp_setup_state_nocalls(CPUHP_MM_VMSTAT_DEAD, "mm/vmstat:dead", |
| 1933 | NULL, vmstat_cpu_dead); |
| 1934 | if (ret < 0) |
| 1935 | pr_err("vmstat: failed to register 'dead' hotplug state\n"); |
| 1936 | |
| 1937 | ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "mm/vmstat:online", |
| 1938 | vmstat_cpu_online, |
| 1939 | vmstat_cpu_down_prep); |
| 1940 | if (ret < 0) |
| 1941 | pr_err("vmstat: failed to register 'online' hotplug state\n"); |
| 1942 | |
| 1943 | get_online_cpus(); |
Tim Chen | 03e86db | 2016-10-07 17:00:02 -0700 | [diff] [blame] | 1944 | init_cpu_node_state(); |
Sebastian Andrzej Siewior | 5438da9 | 2016-11-29 15:52:21 +0100 | [diff] [blame] | 1945 | put_online_cpus(); |
Christoph Lameter | d1187ed | 2007-05-09 02:35:12 -0700 | [diff] [blame] | 1946 | |
Christoph Lameter | 7cc36bb | 2014-10-09 15:29:43 -0700 | [diff] [blame] | 1947 | start_shepherd_timer(); |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1948 | #endif |
| 1949 | #ifdef CONFIG_PROC_FS |
Anshuman Khandual | 9d85e15 | 2017-07-06 15:37:15 -0700 | [diff] [blame] | 1950 | proc_create("buddyinfo", 0444, NULL, &buddyinfo_file_operations); |
| 1951 | proc_create("pagetypeinfo", 0444, NULL, &pagetypeinfo_file_operations); |
| 1952 | proc_create("vmstat", 0444, NULL, &vmstat_file_operations); |
| 1953 | proc_create("zoneinfo", 0444, NULL, &zoneinfo_file_operations); |
Alexey Dobriyan | 8f32f7e | 2008-10-06 04:13:52 +0400 | [diff] [blame] | 1954 | #endif |
Christoph Lameter | df9ecab | 2006-08-31 21:27:35 -0700 | [diff] [blame] | 1955 | } |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 1956 | |
| 1957 | #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_COMPACTION) |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 1958 | |
| 1959 | /* |
| 1960 | * Return an index indicating how much of the available free memory is |
| 1961 | * unusable for an allocation of the requested size. |
| 1962 | */ |
| 1963 | static int unusable_free_index(unsigned int order, |
| 1964 | struct contig_page_info *info) |
| 1965 | { |
| 1966 | /* No free memory is interpreted as all free memory is unusable */ |
| 1967 | if (info->free_pages == 0) |
| 1968 | return 1000; |
| 1969 | |
| 1970 | /* |
| 1971 | * Index should be a value between 0 and 1. Return a value to 3 |
| 1972 | * decimal places. |
| 1973 | * |
| 1974 | * 0 => no fragmentation |
| 1975 | * 1 => high fragmentation |
| 1976 | */ |
| 1977 | return div_u64((info->free_pages - (info->free_blocks_suitable << order)) * 1000ULL, info->free_pages); |
| 1978 | |
| 1979 | } |
| 1980 | |
| 1981 | static void unusable_show_print(struct seq_file *m, |
| 1982 | pg_data_t *pgdat, struct zone *zone) |
| 1983 | { |
| 1984 | unsigned int order; |
| 1985 | int index; |
| 1986 | struct contig_page_info info; |
| 1987 | |
| 1988 | seq_printf(m, "Node %d, zone %8s ", |
| 1989 | pgdat->node_id, |
| 1990 | zone->name); |
| 1991 | for (order = 0; order < MAX_ORDER; ++order) { |
| 1992 | fill_contig_page_info(zone, order, &info); |
| 1993 | index = unusable_free_index(order, &info); |
| 1994 | seq_printf(m, "%d.%03d ", index / 1000, index % 1000); |
| 1995 | } |
| 1996 | |
| 1997 | seq_putc(m, '\n'); |
| 1998 | } |
| 1999 | |
| 2000 | /* |
| 2001 | * Display unusable free space index |
| 2002 | * |
| 2003 | * The unusable free space index measures how much of the available free |
| 2004 | * memory cannot be used to satisfy an allocation of a given size and is a |
| 2005 | * value between 0 and 1. The higher the value, the more of free memory is |
| 2006 | * unusable and by implication, the worse the external fragmentation is. This |
| 2007 | * can be expressed as a percentage by multiplying by 100. |
| 2008 | */ |
| 2009 | static int unusable_show(struct seq_file *m, void *arg) |
| 2010 | { |
| 2011 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 2012 | |
| 2013 | /* check memoryless node */ |
Lai Jiangshan | a47b53c | 2012-12-12 13:51:37 -0800 | [diff] [blame] | 2014 | if (!node_state(pgdat->node_id, N_MEMORY)) |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2015 | return 0; |
| 2016 | |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 2017 | walk_zones_in_node(m, pgdat, true, false, unusable_show_print); |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2018 | |
| 2019 | return 0; |
| 2020 | } |
| 2021 | |
| 2022 | static const struct seq_operations unusable_op = { |
| 2023 | .start = frag_start, |
| 2024 | .next = frag_next, |
| 2025 | .stop = frag_stop, |
| 2026 | .show = unusable_show, |
| 2027 | }; |
| 2028 | |
| 2029 | static int unusable_open(struct inode *inode, struct file *file) |
| 2030 | { |
| 2031 | return seq_open(file, &unusable_op); |
| 2032 | } |
| 2033 | |
| 2034 | static const struct file_operations unusable_file_ops = { |
| 2035 | .open = unusable_open, |
| 2036 | .read = seq_read, |
| 2037 | .llseek = seq_lseek, |
| 2038 | .release = seq_release, |
| 2039 | }; |
| 2040 | |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 2041 | static void extfrag_show_print(struct seq_file *m, |
| 2042 | pg_data_t *pgdat, struct zone *zone) |
| 2043 | { |
| 2044 | unsigned int order; |
| 2045 | int index; |
| 2046 | |
| 2047 | /* Alloc on stack as interrupts are disabled for zone walk */ |
| 2048 | struct contig_page_info info; |
| 2049 | |
| 2050 | seq_printf(m, "Node %d, zone %8s ", |
| 2051 | pgdat->node_id, |
| 2052 | zone->name); |
| 2053 | for (order = 0; order < MAX_ORDER; ++order) { |
| 2054 | fill_contig_page_info(zone, order, &info); |
Mel Gorman | 56de726 | 2010-05-24 14:32:30 -0700 | [diff] [blame] | 2055 | index = __fragmentation_index(order, &info); |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 2056 | seq_printf(m, "%d.%03d ", index / 1000, index % 1000); |
| 2057 | } |
| 2058 | |
| 2059 | seq_putc(m, '\n'); |
| 2060 | } |
| 2061 | |
| 2062 | /* |
| 2063 | * Display fragmentation index for orders that allocations would fail for |
| 2064 | */ |
| 2065 | static int extfrag_show(struct seq_file *m, void *arg) |
| 2066 | { |
| 2067 | pg_data_t *pgdat = (pg_data_t *)arg; |
| 2068 | |
Vinayak Menon | 727c080 | 2017-07-10 15:49:17 -0700 | [diff] [blame] | 2069 | walk_zones_in_node(m, pgdat, true, false, extfrag_show_print); |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 2070 | |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
| 2074 | static const struct seq_operations extfrag_op = { |
| 2075 | .start = frag_start, |
| 2076 | .next = frag_next, |
| 2077 | .stop = frag_stop, |
| 2078 | .show = extfrag_show, |
| 2079 | }; |
| 2080 | |
| 2081 | static int extfrag_open(struct inode *inode, struct file *file) |
| 2082 | { |
| 2083 | return seq_open(file, &extfrag_op); |
| 2084 | } |
| 2085 | |
| 2086 | static const struct file_operations extfrag_file_ops = { |
| 2087 | .open = extfrag_open, |
| 2088 | .read = seq_read, |
| 2089 | .llseek = seq_lseek, |
| 2090 | .release = seq_release, |
| 2091 | }; |
| 2092 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2093 | static int __init extfrag_debug_init(void) |
| 2094 | { |
Sasikantha babu | bde8bd8 | 2012-05-29 15:06:22 -0700 | [diff] [blame] | 2095 | struct dentry *extfrag_debug_root; |
| 2096 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2097 | extfrag_debug_root = debugfs_create_dir("extfrag", NULL); |
| 2098 | if (!extfrag_debug_root) |
| 2099 | return -ENOMEM; |
| 2100 | |
| 2101 | if (!debugfs_create_file("unusable_index", 0444, |
| 2102 | extfrag_debug_root, NULL, &unusable_file_ops)) |
Sasikantha babu | bde8bd8 | 2012-05-29 15:06:22 -0700 | [diff] [blame] | 2103 | goto fail; |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2104 | |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 2105 | if (!debugfs_create_file("extfrag_index", 0444, |
| 2106 | extfrag_debug_root, NULL, &extfrag_file_ops)) |
Sasikantha babu | bde8bd8 | 2012-05-29 15:06:22 -0700 | [diff] [blame] | 2107 | goto fail; |
Mel Gorman | f1a5ab1 | 2010-05-24 14:32:26 -0700 | [diff] [blame] | 2108 | |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2109 | return 0; |
Sasikantha babu | bde8bd8 | 2012-05-29 15:06:22 -0700 | [diff] [blame] | 2110 | fail: |
| 2111 | debugfs_remove_recursive(extfrag_debug_root); |
| 2112 | return -ENOMEM; |
Mel Gorman | d7a5752 | 2010-05-24 14:32:25 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | module_init(extfrag_debug_init); |
| 2116 | #endif |