Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * page-types: Tool for querying page flags |
| 3 | * |
Wu Fengguang | 0e9052e | 2009-12-16 12:19:57 +0100 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the Free |
| 6 | * Software Foundation; version 2. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should find a copy of v2 of the GNU General Public License somewhere on |
| 14 | * your Linux system; if not, write to the Free Software Foundation, Inc., 59 |
| 15 | * Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 16 | * |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 17 | * Copyright (C) 2009 Intel corporation |
Wu Fengguang | 0c57eff | 2009-10-07 16:32:28 -0700 | [diff] [blame] | 18 | * |
| 19 | * Authors: Wu Fengguang <fengguang.wu@intel.com> |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 22 | #define _FILE_OFFSET_BITS 64 |
| 23 | #define _GNU_SOURCE |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <unistd.h> |
| 27 | #include <stdint.h> |
| 28 | #include <stdarg.h> |
| 29 | #include <string.h> |
| 30 | #include <getopt.h> |
| 31 | #include <limits.h> |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 32 | #include <assert.h> |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 33 | #include <ftw.h> |
| 34 | #include <time.h> |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 35 | #include <sys/types.h> |
| 36 | #include <sys/errno.h> |
| 37 | #include <sys/fcntl.h> |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 38 | #include <sys/mount.h> |
| 39 | #include <sys/statfs.h> |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 40 | #include <sys/mman.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 41 | #include "../../include/uapi/linux/magic.h" |
David Howells | 59ce876 | 2012-10-25 13:37:57 -0700 | [diff] [blame] | 42 | #include "../../include/uapi/linux/kernel-page-flags.h" |
Borislav Petkov | 553873e | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 43 | #include <api/fs/debugfs.h> |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 44 | |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 45 | #ifndef MAX_PATH |
| 46 | # define MAX_PATH 256 |
| 47 | #endif |
| 48 | |
| 49 | #ifndef STR |
| 50 | # define _STR(x) #x |
| 51 | # define STR(x) _STR(x) |
| 52 | #endif |
| 53 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 54 | /* |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 55 | * pagemap kernel ABI bits |
| 56 | */ |
| 57 | |
| 58 | #define PM_ENTRY_BYTES sizeof(uint64_t) |
| 59 | #define PM_STATUS_BITS 3 |
| 60 | #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS) |
| 61 | #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET) |
| 62 | #define PM_STATUS(nr) (((nr) << PM_STATUS_OFFSET) & PM_STATUS_MASK) |
| 63 | #define PM_PSHIFT_BITS 6 |
| 64 | #define PM_PSHIFT_OFFSET (PM_STATUS_OFFSET - PM_PSHIFT_BITS) |
| 65 | #define PM_PSHIFT_MASK (((1LL << PM_PSHIFT_BITS) - 1) << PM_PSHIFT_OFFSET) |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 66 | #define __PM_PSHIFT(x) (((uint64_t) (x) << PM_PSHIFT_OFFSET) & PM_PSHIFT_MASK) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 67 | #define PM_PFRAME_MASK ((1LL << PM_PSHIFT_OFFSET) - 1) |
| 68 | #define PM_PFRAME(x) ((x) & PM_PFRAME_MASK) |
| 69 | |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 70 | #define __PM_SOFT_DIRTY (1LL) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 71 | #define PM_PRESENT PM_STATUS(4LL) |
| 72 | #define PM_SWAP PM_STATUS(2LL) |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 73 | #define PM_SOFT_DIRTY __PM_PSHIFT(__PM_SOFT_DIRTY) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 74 | |
| 75 | |
| 76 | /* |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 77 | * kernel page flags |
| 78 | */ |
| 79 | |
| 80 | #define KPF_BYTES 8 |
| 81 | #define PROC_KPAGEFLAGS "/proc/kpageflags" |
| 82 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 83 | /* [32-] kernel hacking assistances */ |
| 84 | #define KPF_RESERVED 32 |
| 85 | #define KPF_MLOCKED 33 |
| 86 | #define KPF_MAPPEDTODISK 34 |
| 87 | #define KPF_PRIVATE 35 |
| 88 | #define KPF_PRIVATE_2 36 |
| 89 | #define KPF_OWNER_PRIVATE 37 |
| 90 | #define KPF_ARCH 38 |
| 91 | #define KPF_UNCACHED 39 |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 92 | #define KPF_SOFTDIRTY 40 |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 93 | |
| 94 | /* [48-] take some arbitrary free slots for expanding overloaded flags |
| 95 | * not part of kernel API |
| 96 | */ |
| 97 | #define KPF_READAHEAD 48 |
| 98 | #define KPF_SLOB_FREE 49 |
| 99 | #define KPF_SLUB_FROZEN 50 |
| 100 | #define KPF_SLUB_DEBUG 51 |
| 101 | |
| 102 | #define KPF_ALL_BITS ((uint64_t)~0ULL) |
| 103 | #define KPF_HACKERS_BITS (0xffffULL << 32) |
| 104 | #define KPF_OVERLOADED_BITS (0xffffULL << 48) |
| 105 | #define BIT(name) (1ULL << KPF_##name) |
| 106 | #define BITS_COMPOUND (BIT(COMPOUND_HEAD) | BIT(COMPOUND_TAIL)) |
| 107 | |
Dave Young | c6dd897 | 2012-03-28 14:42:55 -0700 | [diff] [blame] | 108 | static const char * const page_flag_names[] = { |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 109 | [KPF_LOCKED] = "L:locked", |
| 110 | [KPF_ERROR] = "E:error", |
| 111 | [KPF_REFERENCED] = "R:referenced", |
| 112 | [KPF_UPTODATE] = "U:uptodate", |
| 113 | [KPF_DIRTY] = "D:dirty", |
| 114 | [KPF_LRU] = "l:lru", |
| 115 | [KPF_ACTIVE] = "A:active", |
| 116 | [KPF_SLAB] = "S:slab", |
| 117 | [KPF_WRITEBACK] = "W:writeback", |
| 118 | [KPF_RECLAIM] = "I:reclaim", |
| 119 | [KPF_BUDDY] = "B:buddy", |
| 120 | |
| 121 | [KPF_MMAP] = "M:mmap", |
| 122 | [KPF_ANON] = "a:anonymous", |
| 123 | [KPF_SWAPCACHE] = "s:swapcache", |
| 124 | [KPF_SWAPBACKED] = "b:swapbacked", |
| 125 | [KPF_COMPOUND_HEAD] = "H:compound_head", |
| 126 | [KPF_COMPOUND_TAIL] = "T:compound_tail", |
| 127 | [KPF_HUGE] = "G:huge", |
| 128 | [KPF_UNEVICTABLE] = "u:unevictable", |
Wu Fengguang | 253fb02 | 2009-10-07 16:32:27 -0700 | [diff] [blame] | 129 | [KPF_HWPOISON] = "X:hwpoison", |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 130 | [KPF_NOPAGE] = "n:nopage", |
Wu Fengguang | a1bbb5e | 2009-10-07 16:32:28 -0700 | [diff] [blame] | 131 | [KPF_KSM] = "x:ksm", |
Naoya Horiguchi | 807f0cc | 2012-03-21 16:33:58 -0700 | [diff] [blame] | 132 | [KPF_THP] = "t:thp", |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 133 | |
| 134 | [KPF_RESERVED] = "r:reserved", |
| 135 | [KPF_MLOCKED] = "m:mlocked", |
| 136 | [KPF_MAPPEDTODISK] = "d:mappedtodisk", |
| 137 | [KPF_PRIVATE] = "P:private", |
| 138 | [KPF_PRIVATE_2] = "p:private_2", |
| 139 | [KPF_OWNER_PRIVATE] = "O:owner_private", |
| 140 | [KPF_ARCH] = "h:arch", |
| 141 | [KPF_UNCACHED] = "c:uncached", |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 142 | [KPF_SOFTDIRTY] = "f:softdirty", |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 143 | |
| 144 | [KPF_READAHEAD] = "I:readahead", |
| 145 | [KPF_SLOB_FREE] = "P:slob_free", |
| 146 | [KPF_SLUB_FROZEN] = "A:slub_frozen", |
| 147 | [KPF_SLUB_DEBUG] = "E:slub_debug", |
| 148 | }; |
| 149 | |
| 150 | |
Dave Young | c6dd897 | 2012-03-28 14:42:55 -0700 | [diff] [blame] | 151 | static const char * const debugfs_known_mountpoints[] = { |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 152 | "/sys/kernel/debug", |
| 153 | "/debug", |
| 154 | 0, |
| 155 | }; |
| 156 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 157 | /* |
| 158 | * data structures |
| 159 | */ |
| 160 | |
| 161 | static int opt_raw; /* for kernel developers */ |
| 162 | static int opt_list; /* list pages (in ranges) */ |
| 163 | static int opt_no_summary; /* don't show summary */ |
| 164 | static pid_t opt_pid; /* process to walk */ |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 165 | const char * opt_file; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 166 | |
| 167 | #define MAX_ADDR_RANGES 1024 |
| 168 | static int nr_addr_ranges; |
| 169 | static unsigned long opt_offset[MAX_ADDR_RANGES]; |
| 170 | static unsigned long opt_size[MAX_ADDR_RANGES]; |
| 171 | |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 172 | #define MAX_VMAS 10240 |
| 173 | static int nr_vmas; |
| 174 | static unsigned long pg_start[MAX_VMAS]; |
| 175 | static unsigned long pg_end[MAX_VMAS]; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 176 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 177 | #define MAX_BIT_FILTERS 64 |
| 178 | static int nr_bit_filters; |
| 179 | static uint64_t opt_mask[MAX_BIT_FILTERS]; |
| 180 | static uint64_t opt_bits[MAX_BIT_FILTERS]; |
| 181 | |
| 182 | static int page_size; |
| 183 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 184 | static int pagemap_fd; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 185 | static int kpageflags_fd; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 186 | |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 187 | static int opt_hwpoison; |
| 188 | static int opt_unpoison; |
| 189 | |
Borislav Petkov | 5a43964 | 2013-02-20 16:32:33 +0100 | [diff] [blame] | 190 | static char *hwpoison_debug_fs; |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 191 | static int hwpoison_inject_fd; |
| 192 | static int hwpoison_forget_fd; |
| 193 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 194 | #define HASH_SHIFT 13 |
| 195 | #define HASH_SIZE (1 << HASH_SHIFT) |
| 196 | #define HASH_MASK (HASH_SIZE - 1) |
| 197 | #define HASH_KEY(flags) (flags & HASH_MASK) |
| 198 | |
| 199 | static unsigned long total_pages; |
| 200 | static unsigned long nr_pages[HASH_SIZE]; |
Dave Young | c6dd897 | 2012-03-28 14:42:55 -0700 | [diff] [blame] | 201 | static uint64_t page_flags[HASH_SIZE]; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 202 | |
| 203 | |
| 204 | /* |
| 205 | * helper functions |
| 206 | */ |
| 207 | |
| 208 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 209 | |
| 210 | #define min_t(type, x, y) ({ \ |
| 211 | type __min1 = (x); \ |
| 212 | type __min2 = (y); \ |
| 213 | __min1 < __min2 ? __min1 : __min2; }) |
| 214 | |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 215 | #define max_t(type, x, y) ({ \ |
| 216 | type __max1 = (x); \ |
| 217 | type __max2 = (y); \ |
| 218 | __max1 > __max2 ? __max1 : __max2; }) |
| 219 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 220 | static unsigned long pages2mb(unsigned long pages) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 221 | { |
| 222 | return (pages * page_size) >> 20; |
| 223 | } |
| 224 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 225 | static void fatal(const char *x, ...) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 226 | { |
| 227 | va_list ap; |
| 228 | |
| 229 | va_start(ap, x); |
| 230 | vfprintf(stderr, x, ap); |
| 231 | va_end(ap); |
| 232 | exit(EXIT_FAILURE); |
| 233 | } |
| 234 | |
Josh Triplett | 1b98c00 | 2009-10-16 14:06:13 -0700 | [diff] [blame] | 235 | static int checked_open(const char *pathname, int flags) |
Wu Fengguang | 31bbf66 | 2009-10-07 16:32:29 -0700 | [diff] [blame] | 236 | { |
| 237 | int fd = open(pathname, flags); |
| 238 | |
| 239 | if (fd < 0) { |
| 240 | perror(pathname); |
| 241 | exit(EXIT_FAILURE); |
| 242 | } |
| 243 | |
| 244 | return fd; |
| 245 | } |
| 246 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 247 | /* |
| 248 | * pagemap/kpageflags routines |
| 249 | */ |
| 250 | |
| 251 | static unsigned long do_u64_read(int fd, char *name, |
| 252 | uint64_t *buf, |
| 253 | unsigned long index, |
| 254 | unsigned long count) |
| 255 | { |
| 256 | long bytes; |
| 257 | |
| 258 | if (index > ULONG_MAX / 8) |
| 259 | fatal("index overflow: %lu\n", index); |
| 260 | |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 261 | bytes = pread(fd, buf, count * 8, (off_t)index * 8); |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 262 | if (bytes < 0) { |
| 263 | perror(name); |
| 264 | exit(EXIT_FAILURE); |
| 265 | } |
| 266 | if (bytes % 8) |
| 267 | fatal("partial read: %lu bytes\n", bytes); |
| 268 | |
| 269 | return bytes / 8; |
| 270 | } |
| 271 | |
| 272 | static unsigned long kpageflags_read(uint64_t *buf, |
| 273 | unsigned long index, |
| 274 | unsigned long pages) |
| 275 | { |
| 276 | return do_u64_read(kpageflags_fd, PROC_KPAGEFLAGS, buf, index, pages); |
| 277 | } |
| 278 | |
| 279 | static unsigned long pagemap_read(uint64_t *buf, |
| 280 | unsigned long index, |
| 281 | unsigned long pages) |
| 282 | { |
| 283 | return do_u64_read(pagemap_fd, "/proc/pid/pagemap", buf, index, pages); |
| 284 | } |
| 285 | |
| 286 | static unsigned long pagemap_pfn(uint64_t val) |
| 287 | { |
| 288 | unsigned long pfn; |
| 289 | |
| 290 | if (val & PM_PRESENT) |
| 291 | pfn = PM_PFRAME(val); |
| 292 | else |
| 293 | pfn = 0; |
| 294 | |
| 295 | return pfn; |
| 296 | } |
| 297 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 298 | |
| 299 | /* |
| 300 | * page flag names |
| 301 | */ |
| 302 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 303 | static char *page_flag_name(uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 304 | { |
| 305 | static char buf[65]; |
| 306 | int present; |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 307 | size_t i, j; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 308 | |
| 309 | for (i = 0, j = 0; i < ARRAY_SIZE(page_flag_names); i++) { |
| 310 | present = (flags >> i) & 1; |
| 311 | if (!page_flag_names[i]) { |
| 312 | if (present) |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 313 | fatal("unknown flag bit %d\n", i); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 314 | continue; |
| 315 | } |
| 316 | buf[j++] = present ? page_flag_names[i][0] : '_'; |
| 317 | } |
| 318 | |
| 319 | return buf; |
| 320 | } |
| 321 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 322 | static char *page_flag_longname(uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 323 | { |
| 324 | static char buf[1024]; |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 325 | size_t i, n; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 326 | |
| 327 | for (i = 0, n = 0; i < ARRAY_SIZE(page_flag_names); i++) { |
| 328 | if (!page_flag_names[i]) |
| 329 | continue; |
| 330 | if ((flags >> i) & 1) |
| 331 | n += snprintf(buf + n, sizeof(buf) - n, "%s,", |
| 332 | page_flag_names[i] + 2); |
| 333 | } |
| 334 | if (n) |
| 335 | n--; |
| 336 | buf[n] = '\0'; |
| 337 | |
| 338 | return buf; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /* |
| 343 | * page list and summary |
| 344 | */ |
| 345 | |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 346 | static void show_page_range(unsigned long voffset, unsigned long offset, |
| 347 | unsigned long size, uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 348 | { |
| 349 | static uint64_t flags0; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 350 | static unsigned long voff; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 351 | static unsigned long index; |
| 352 | static unsigned long count; |
| 353 | |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 354 | if (flags == flags0 && offset == index + count && |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 355 | size && voffset == voff + count) { |
| 356 | count += size; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 357 | return; |
| 358 | } |
| 359 | |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 360 | if (count) { |
| 361 | if (opt_pid) |
| 362 | printf("%lx\t", voff); |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 363 | if (opt_file) |
| 364 | printf("%lu\t", voff); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 365 | printf("%lx\t%lx\t%s\n", |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 366 | index, count, page_flag_name(flags0)); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 367 | } |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 368 | |
| 369 | flags0 = flags; |
| 370 | index = offset; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 371 | voff = voffset; |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 372 | count = size; |
| 373 | } |
| 374 | |
| 375 | static void flush_page_range(void) |
| 376 | { |
| 377 | show_page_range(0, 0, 0, 0); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 380 | static void show_page(unsigned long voffset, |
| 381 | unsigned long offset, uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 382 | { |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 383 | if (opt_pid) |
| 384 | printf("%lx\t", voffset); |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 385 | if (opt_file) |
| 386 | printf("%lu\t", voffset); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 387 | printf("%lx\t%s\n", offset, page_flag_name(flags)); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 390 | static void show_summary(void) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 391 | { |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 392 | size_t i; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 393 | |
| 394 | printf(" flags\tpage-count MB" |
| 395 | " symbolic-flags\t\t\tlong-symbolic-flags\n"); |
| 396 | |
| 397 | for (i = 0; i < ARRAY_SIZE(nr_pages); i++) { |
| 398 | if (nr_pages[i]) |
| 399 | printf("0x%016llx\t%10lu %8lu %s\t%s\n", |
| 400 | (unsigned long long)page_flags[i], |
| 401 | nr_pages[i], |
| 402 | pages2mb(nr_pages[i]), |
| 403 | page_flag_name(page_flags[i]), |
| 404 | page_flag_longname(page_flags[i])); |
| 405 | } |
| 406 | |
| 407 | printf(" total\t%10lu %8lu\n", |
| 408 | total_pages, pages2mb(total_pages)); |
| 409 | } |
| 410 | |
| 411 | |
| 412 | /* |
| 413 | * page flag filters |
| 414 | */ |
| 415 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 416 | static int bit_mask_ok(uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 417 | { |
| 418 | int i; |
| 419 | |
| 420 | for (i = 0; i < nr_bit_filters; i++) { |
| 421 | if (opt_bits[i] == KPF_ALL_BITS) { |
| 422 | if ((flags & opt_mask[i]) == 0) |
| 423 | return 0; |
| 424 | } else { |
| 425 | if ((flags & opt_mask[i]) != opt_bits[i]) |
| 426 | return 0; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return 1; |
| 431 | } |
| 432 | |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 433 | static uint64_t expand_overloaded_flags(uint64_t flags, uint64_t pme) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 434 | { |
| 435 | /* SLOB/SLUB overload several page flags */ |
| 436 | if (flags & BIT(SLAB)) { |
| 437 | if (flags & BIT(PRIVATE)) |
| 438 | flags ^= BIT(PRIVATE) | BIT(SLOB_FREE); |
| 439 | if (flags & BIT(ACTIVE)) |
| 440 | flags ^= BIT(ACTIVE) | BIT(SLUB_FROZEN); |
| 441 | if (flags & BIT(ERROR)) |
| 442 | flags ^= BIT(ERROR) | BIT(SLUB_DEBUG); |
| 443 | } |
| 444 | |
| 445 | /* PG_reclaim is overloaded as PG_readahead in the read path */ |
| 446 | if ((flags & (BIT(RECLAIM) | BIT(WRITEBACK))) == BIT(RECLAIM)) |
| 447 | flags ^= BIT(RECLAIM) | BIT(READAHEAD); |
| 448 | |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 449 | if (pme & PM_SOFT_DIRTY) |
| 450 | flags |= BIT(SOFTDIRTY); |
| 451 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 452 | return flags; |
| 453 | } |
| 454 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 455 | static uint64_t well_known_flags(uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 456 | { |
| 457 | /* hide flags intended only for kernel hacker */ |
| 458 | flags &= ~KPF_HACKERS_BITS; |
| 459 | |
| 460 | /* hide non-hugeTLB compound pages */ |
| 461 | if ((flags & BITS_COMPOUND) && !(flags & BIT(HUGE))) |
| 462 | flags &= ~BITS_COMPOUND; |
| 463 | |
| 464 | return flags; |
| 465 | } |
| 466 | |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 467 | static uint64_t kpageflags_flags(uint64_t flags, uint64_t pme) |
Wu Fengguang | 48640d6 | 2009-10-07 16:32:31 -0700 | [diff] [blame] | 468 | { |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 469 | if (opt_raw) |
| 470 | flags = expand_overloaded_flags(flags, pme); |
| 471 | else |
Wu Fengguang | 48640d6 | 2009-10-07 16:32:31 -0700 | [diff] [blame] | 472 | flags = well_known_flags(flags); |
| 473 | |
| 474 | return flags; |
| 475 | } |
| 476 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 477 | /* |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 478 | * page actions |
| 479 | */ |
| 480 | |
| 481 | static void prepare_hwpoison_fd(void) |
| 482 | { |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 483 | char buf[MAX_PATH + 1]; |
| 484 | |
Borislav Petkov | 5a43964 | 2013-02-20 16:32:33 +0100 | [diff] [blame] | 485 | hwpoison_debug_fs = debugfs_mount(NULL); |
| 486 | if (!hwpoison_debug_fs) { |
| 487 | perror("mount debugfs"); |
| 488 | exit(EXIT_FAILURE); |
| 489 | } |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 490 | |
| 491 | if (opt_hwpoison && !hwpoison_inject_fd) { |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 492 | snprintf(buf, MAX_PATH, "%s/hwpoison/corrupt-pfn", |
| 493 | hwpoison_debug_fs); |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 494 | hwpoison_inject_fd = checked_open(buf, O_WRONLY); |
| 495 | } |
| 496 | |
| 497 | if (opt_unpoison && !hwpoison_forget_fd) { |
Chen Gong | 12da58b | 2011-03-22 16:35:03 -0700 | [diff] [blame] | 498 | snprintf(buf, MAX_PATH, "%s/hwpoison/unpoison-pfn", |
| 499 | hwpoison_debug_fs); |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 500 | hwpoison_forget_fd = checked_open(buf, O_WRONLY); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static int hwpoison_page(unsigned long offset) |
| 505 | { |
| 506 | char buf[100]; |
| 507 | int len; |
| 508 | |
| 509 | len = sprintf(buf, "0x%lx\n", offset); |
| 510 | len = write(hwpoison_inject_fd, buf, len); |
| 511 | if (len < 0) { |
| 512 | perror("hwpoison inject"); |
| 513 | return len; |
| 514 | } |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int unpoison_page(unsigned long offset) |
| 519 | { |
| 520 | char buf[100]; |
| 521 | int len; |
| 522 | |
| 523 | len = sprintf(buf, "0x%lx\n", offset); |
| 524 | len = write(hwpoison_forget_fd, buf, len); |
| 525 | if (len < 0) { |
| 526 | perror("hwpoison forget"); |
| 527 | return len; |
| 528 | } |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | /* |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 533 | * page frame walker |
| 534 | */ |
| 535 | |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 536 | static size_t hash_slot(uint64_t flags) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 537 | { |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 538 | size_t k = HASH_KEY(flags); |
| 539 | size_t i; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 540 | |
| 541 | /* Explicitly reserve slot 0 for flags 0: the following logic |
| 542 | * cannot distinguish an unoccupied slot from slot (flags==0). |
| 543 | */ |
| 544 | if (flags == 0) |
| 545 | return 0; |
| 546 | |
| 547 | /* search through the remaining (HASH_SIZE-1) slots */ |
| 548 | for (i = 1; i < ARRAY_SIZE(page_flags); i++, k++) { |
| 549 | if (!k || k >= ARRAY_SIZE(page_flags)) |
| 550 | k = 1; |
| 551 | if (page_flags[k] == 0) { |
| 552 | page_flags[k] = flags; |
| 553 | return k; |
| 554 | } |
| 555 | if (page_flags[k] == flags) |
| 556 | return k; |
| 557 | } |
| 558 | |
| 559 | fatal("hash table full: bump up HASH_SHIFT?\n"); |
| 560 | exit(EXIT_FAILURE); |
| 561 | } |
| 562 | |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 563 | static void add_page(unsigned long voffset, |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 564 | unsigned long offset, uint64_t flags, uint64_t pme) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 565 | { |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 566 | flags = kpageflags_flags(flags, pme); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 567 | |
| 568 | if (!bit_mask_ok(flags)) |
| 569 | return; |
| 570 | |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 571 | if (opt_hwpoison) |
| 572 | hwpoison_page(offset); |
| 573 | if (opt_unpoison) |
| 574 | unpoison_page(offset); |
| 575 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 576 | if (opt_list == 1) |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 577 | show_page_range(voffset, offset, 1, flags); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 578 | else if (opt_list == 2) |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 579 | show_page(voffset, offset, flags); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 580 | |
| 581 | nr_pages[hash_slot(flags)]++; |
| 582 | total_pages++; |
| 583 | } |
| 584 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 585 | #define KPAGEFLAGS_BATCH (64 << 10) /* 64k pages */ |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 586 | static void walk_pfn(unsigned long voffset, |
| 587 | unsigned long index, |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 588 | unsigned long count, |
| 589 | uint64_t pme) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 590 | { |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 591 | uint64_t buf[KPAGEFLAGS_BATCH]; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 592 | unsigned long batch; |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 593 | unsigned long pages; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 594 | unsigned long i; |
| 595 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 596 | while (count) { |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 597 | batch = min_t(unsigned long, count, KPAGEFLAGS_BATCH); |
| 598 | pages = kpageflags_read(buf, index, batch); |
| 599 | if (pages == 0) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 600 | break; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 601 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 602 | for (i = 0; i < pages; i++) |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 603 | add_page(voffset + i, index + i, buf[i], pme); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 604 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 605 | index += pages; |
| 606 | count -= pages; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 610 | #define PAGEMAP_BATCH (64 << 10) |
| 611 | static void walk_vma(unsigned long index, unsigned long count) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 612 | { |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 613 | uint64_t buf[PAGEMAP_BATCH]; |
| 614 | unsigned long batch; |
| 615 | unsigned long pages; |
| 616 | unsigned long pfn; |
| 617 | unsigned long i; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 618 | |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 619 | while (count) { |
| 620 | batch = min_t(unsigned long, count, PAGEMAP_BATCH); |
| 621 | pages = pagemap_read(buf, index, batch); |
| 622 | if (pages == 0) |
| 623 | break; |
| 624 | |
| 625 | for (i = 0; i < pages; i++) { |
| 626 | pfn = pagemap_pfn(buf[i]); |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 627 | if (pfn) |
Naoya Horiguchi | 46c77e2 | 2013-11-12 15:07:50 -0800 | [diff] [blame] | 628 | walk_pfn(index + i, pfn, 1, buf[i]); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 629 | } |
Wu Fengguang | 4a1b672 | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 630 | |
| 631 | index += pages; |
| 632 | count -= pages; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 633 | } |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void walk_task(unsigned long index, unsigned long count) |
| 637 | { |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 638 | const unsigned long end = index + count; |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 639 | unsigned long start; |
| 640 | int i = 0; |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 641 | |
| 642 | while (index < end) { |
| 643 | |
| 644 | while (pg_end[i] <= index) |
| 645 | if (++i >= nr_vmas) |
| 646 | return; |
| 647 | if (pg_start[i] >= end) |
| 648 | return; |
| 649 | |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 650 | start = max_t(unsigned long, pg_start[i], index); |
| 651 | index = min_t(unsigned long, pg_end[i], end); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 652 | |
Wu Fengguang | e577ebd | 2009-10-07 16:32:30 -0700 | [diff] [blame] | 653 | assert(start < index); |
| 654 | walk_vma(start, index - start); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | static void add_addr_range(unsigned long offset, unsigned long size) |
| 659 | { |
| 660 | if (nr_addr_ranges >= MAX_ADDR_RANGES) |
| 661 | fatal("too many addr ranges\n"); |
| 662 | |
| 663 | opt_offset[nr_addr_ranges] = offset; |
| 664 | opt_size[nr_addr_ranges] = min_t(unsigned long, size, ULONG_MAX-offset); |
| 665 | nr_addr_ranges++; |
| 666 | } |
| 667 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 668 | static void walk_addr_ranges(void) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 669 | { |
| 670 | int i; |
| 671 | |
Wu Fengguang | 31bbf66 | 2009-10-07 16:32:29 -0700 | [diff] [blame] | 672 | kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 673 | |
| 674 | if (!nr_addr_ranges) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 675 | add_addr_range(0, ULONG_MAX); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 676 | |
| 677 | for (i = 0; i < nr_addr_ranges; i++) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 678 | if (!opt_pid) |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 679 | walk_pfn(opt_offset[i], opt_offset[i], opt_size[i], 0); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 680 | else |
| 681 | walk_task(opt_offset[i], opt_size[i]); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 682 | |
| 683 | close(kpageflags_fd); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | /* |
| 688 | * user interface |
| 689 | */ |
| 690 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 691 | static const char *page_flag_type(uint64_t flag) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 692 | { |
| 693 | if (flag & KPF_HACKERS_BITS) |
| 694 | return "(r)"; |
| 695 | if (flag & KPF_OVERLOADED_BITS) |
| 696 | return "(o)"; |
| 697 | return " "; |
| 698 | } |
| 699 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 700 | static void usage(void) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 701 | { |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 702 | size_t i, j; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 703 | |
| 704 | printf( |
| 705 | "page-types [options]\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 706 | " -r|--raw Raw mode, for kernel developers\n" |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 707 | " -d|--describe flags Describe flags\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 708 | " -a|--addr addr-spec Walk a range of pages\n" |
| 709 | " -b|--bits bits-spec Walk pages with specified bits\n" |
| 710 | " -p|--pid pid Walk process address space\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 711 | " -f|--file filename Walk file address space\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 712 | " -l|--list Show page details in ranges\n" |
| 713 | " -L|--list-each Show page details one by one\n" |
Tommi Rantala | c7825cf | 2010-08-05 11:23:11 -0700 | [diff] [blame] | 714 | " -N|--no-summary Don't show summary info\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 715 | " -X|--hwpoison hwpoison pages\n" |
| 716 | " -x|--unpoison unpoison pages\n" |
| 717 | " -h|--help Show this usage message\n" |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 718 | "flags:\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 719 | " 0x10 bitfield format, e.g.\n" |
| 720 | " anon bit-name, e.g.\n" |
| 721 | " 0x10,anon comma-separated list, e.g.\n" |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 722 | "addr-spec:\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 723 | " N one page at offset N (unit: pages)\n" |
| 724 | " N+M pages range from N to N+M-1\n" |
| 725 | " N,M pages range from N to M-1\n" |
| 726 | " N, pages range from N to end\n" |
| 727 | " ,M pages range from 0 to M-1\n" |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 728 | "bits-spec:\n" |
Alex Chiang | 9fdcd88 | 2009-12-14 17:57:53 -0800 | [diff] [blame] | 729 | " bit1,bit2 (flags & (bit1|bit2)) != 0\n" |
| 730 | " bit1,bit2=bit1 (flags & (bit1|bit2)) == bit1\n" |
| 731 | " bit1,~bit2 (flags & (bit1|bit2)) == bit1\n" |
| 732 | " =bit1,bit2 flags == (bit1|bit2)\n" |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 733 | "bit-names:\n" |
| 734 | ); |
| 735 | |
| 736 | for (i = 0, j = 0; i < ARRAY_SIZE(page_flag_names); i++) { |
| 737 | if (!page_flag_names[i]) |
| 738 | continue; |
| 739 | printf("%16s%s", page_flag_names[i] + 2, |
| 740 | page_flag_type(1ULL << i)); |
| 741 | if (++j > 3) { |
| 742 | j = 0; |
| 743 | putchar('\n'); |
| 744 | } |
| 745 | } |
| 746 | printf("\n " |
| 747 | "(r) raw mode bits (o) overloaded bits\n"); |
| 748 | } |
| 749 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 750 | static unsigned long long parse_number(const char *str) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 751 | { |
| 752 | unsigned long long n; |
| 753 | |
| 754 | n = strtoll(str, NULL, 0); |
| 755 | |
| 756 | if (n == 0 && str[0] != '0') |
| 757 | fatal("invalid name or number: %s\n", str); |
| 758 | |
| 759 | return n; |
| 760 | } |
| 761 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 762 | static void parse_pid(const char *str) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 763 | { |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 764 | FILE *file; |
| 765 | char buf[5000]; |
| 766 | |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 767 | opt_pid = parse_number(str); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 768 | |
| 769 | sprintf(buf, "/proc/%d/pagemap", opt_pid); |
Wu Fengguang | 31bbf66 | 2009-10-07 16:32:29 -0700 | [diff] [blame] | 770 | pagemap_fd = checked_open(buf, O_RDONLY); |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 771 | |
| 772 | sprintf(buf, "/proc/%d/maps", opt_pid); |
| 773 | file = fopen(buf, "r"); |
| 774 | if (!file) { |
| 775 | perror(buf); |
| 776 | exit(EXIT_FAILURE); |
| 777 | } |
| 778 | |
| 779 | while (fgets(buf, sizeof(buf), file) != NULL) { |
| 780 | unsigned long vm_start; |
| 781 | unsigned long vm_end; |
| 782 | unsigned long long pgoff; |
| 783 | int major, minor; |
| 784 | char r, w, x, s; |
| 785 | unsigned long ino; |
| 786 | int n; |
| 787 | |
| 788 | n = sscanf(buf, "%lx-%lx %c%c%c%c %llx %x:%x %lu", |
| 789 | &vm_start, |
| 790 | &vm_end, |
| 791 | &r, &w, &x, &s, |
| 792 | &pgoff, |
| 793 | &major, &minor, |
| 794 | &ino); |
| 795 | if (n < 10) { |
| 796 | fprintf(stderr, "unexpected line: %s\n", buf); |
| 797 | continue; |
| 798 | } |
| 799 | pg_start[nr_vmas] = vm_start / page_size; |
| 800 | pg_end[nr_vmas] = vm_end / page_size; |
| 801 | if (++nr_vmas >= MAX_VMAS) { |
| 802 | fprintf(stderr, "too many VMAs\n"); |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | fclose(file); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 809 | static void show_file(const char *name, const struct stat *st) |
| 810 | { |
| 811 | unsigned long long size = st->st_size; |
| 812 | char atime[64], mtime[64]; |
| 813 | long now = time(NULL); |
| 814 | |
| 815 | printf("%s\tInode: %u\tSize: %llu (%llu pages)\n", |
| 816 | name, (unsigned)st->st_ino, |
| 817 | size, (size + page_size - 1) / page_size); |
| 818 | |
| 819 | strftime(atime, sizeof(atime), "%c", localtime(&st->st_atime)); |
| 820 | strftime(mtime, sizeof(mtime), "%c", localtime(&st->st_mtime)); |
| 821 | |
| 822 | printf("Modify: %s (%ld seconds ago)\nAccess: %s (%ld seconds ago)\n", |
| 823 | mtime, now - st->st_mtime, |
| 824 | atime, now - st->st_atime); |
| 825 | } |
| 826 | |
| 827 | static void walk_file(const char *name, const struct stat *st) |
| 828 | { |
| 829 | uint8_t vec[PAGEMAP_BATCH]; |
| 830 | uint64_t buf[PAGEMAP_BATCH], flags; |
| 831 | unsigned long nr_pages, pfn, i; |
| 832 | int fd; |
| 833 | off_t off; |
| 834 | ssize_t len; |
| 835 | void *ptr; |
| 836 | int first = 1; |
| 837 | |
| 838 | fd = checked_open(name, O_RDONLY|O_NOATIME|O_NOFOLLOW); |
| 839 | |
| 840 | for (off = 0; off < st->st_size; off += len) { |
| 841 | nr_pages = (st->st_size - off + page_size - 1) / page_size; |
| 842 | if (nr_pages > PAGEMAP_BATCH) |
| 843 | nr_pages = PAGEMAP_BATCH; |
| 844 | len = nr_pages * page_size; |
| 845 | |
| 846 | ptr = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, off); |
| 847 | if (ptr == MAP_FAILED) |
| 848 | fatal("mmap failed: %s", name); |
| 849 | |
| 850 | /* determine cached pages */ |
| 851 | if (mincore(ptr, len, vec)) |
| 852 | fatal("mincore failed: %s", name); |
| 853 | |
| 854 | /* turn off readahead */ |
| 855 | if (madvise(ptr, len, MADV_RANDOM)) |
| 856 | fatal("madvice failed: %s", name); |
| 857 | |
| 858 | /* populate ptes */ |
| 859 | for (i = 0; i < nr_pages ; i++) { |
| 860 | if (vec[i] & 1) |
| 861 | (void)*(volatile int *)(ptr + i * page_size); |
| 862 | } |
| 863 | |
| 864 | /* turn off harvesting reference bits */ |
| 865 | if (madvise(ptr, len, MADV_SEQUENTIAL)) |
| 866 | fatal("madvice failed: %s", name); |
| 867 | |
| 868 | if (pagemap_read(buf, (unsigned long)ptr / page_size, |
| 869 | nr_pages) != nr_pages) |
| 870 | fatal("cannot read pagemap"); |
| 871 | |
| 872 | munmap(ptr, len); |
| 873 | |
| 874 | for (i = 0; i < nr_pages; i++) { |
| 875 | pfn = pagemap_pfn(buf[i]); |
| 876 | if (!pfn) |
| 877 | continue; |
| 878 | if (!kpageflags_read(&flags, pfn, 1)) |
| 879 | continue; |
| 880 | if (first && opt_list) { |
| 881 | first = 0; |
| 882 | flush_page_range(); |
| 883 | show_file(name, st); |
| 884 | } |
| 885 | add_page(off / page_size + i, pfn, flags, buf[i]); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | close(fd); |
| 890 | } |
| 891 | |
| 892 | int walk_tree(const char *name, const struct stat *st, int type, struct FTW *f) |
| 893 | { |
| 894 | (void)f; |
| 895 | switch (type) { |
| 896 | case FTW_F: |
| 897 | if (S_ISREG(st->st_mode)) |
| 898 | walk_file(name, st); |
| 899 | break; |
| 900 | case FTW_DNR: |
| 901 | fprintf(stderr, "cannot read dir: %s\n", name); |
| 902 | break; |
| 903 | } |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static void walk_page_cache(void) |
| 908 | { |
| 909 | struct stat st; |
| 910 | |
| 911 | kpageflags_fd = checked_open(PROC_KPAGEFLAGS, O_RDONLY); |
| 912 | pagemap_fd = checked_open("/proc/self/pagemap", O_RDONLY); |
| 913 | |
| 914 | if (stat(opt_file, &st)) |
| 915 | fatal("stat failed: %s\n", opt_file); |
| 916 | |
| 917 | if (S_ISREG(st.st_mode)) { |
| 918 | walk_file(opt_file, &st); |
| 919 | } else if (S_ISDIR(st.st_mode)) { |
| 920 | /* do not follow symlinks and mountpoints */ |
| 921 | if (nftw(opt_file, walk_tree, 64, FTW_MOUNT | FTW_PHYS) < 0) |
| 922 | fatal("nftw failed: %s\n", opt_file); |
| 923 | } else |
| 924 | fatal("unhandled file type: %s\n", opt_file); |
| 925 | |
| 926 | close(kpageflags_fd); |
| 927 | close(pagemap_fd); |
| 928 | } |
| 929 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 930 | static void parse_file(const char *name) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 931 | { |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 932 | opt_file = name; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 935 | static void parse_addr_range(const char *optarg) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 936 | { |
| 937 | unsigned long offset; |
| 938 | unsigned long size; |
| 939 | char *p; |
| 940 | |
| 941 | p = strchr(optarg, ','); |
| 942 | if (!p) |
| 943 | p = strchr(optarg, '+'); |
| 944 | |
| 945 | if (p == optarg) { |
| 946 | offset = 0; |
| 947 | size = parse_number(p + 1); |
| 948 | } else if (p) { |
| 949 | offset = parse_number(optarg); |
| 950 | if (p[1] == '\0') |
| 951 | size = ULONG_MAX; |
| 952 | else { |
| 953 | size = parse_number(p + 1); |
| 954 | if (*p == ',') { |
| 955 | if (size < offset) |
| 956 | fatal("invalid range: %lu,%lu\n", |
| 957 | offset, size); |
| 958 | size -= offset; |
| 959 | } |
| 960 | } |
| 961 | } else { |
| 962 | offset = parse_number(optarg); |
| 963 | size = 1; |
| 964 | } |
| 965 | |
| 966 | add_addr_range(offset, size); |
| 967 | } |
| 968 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 969 | static void add_bits_filter(uint64_t mask, uint64_t bits) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 970 | { |
| 971 | if (nr_bit_filters >= MAX_BIT_FILTERS) |
| 972 | fatal("too much bit filters\n"); |
| 973 | |
| 974 | opt_mask[nr_bit_filters] = mask; |
| 975 | opt_bits[nr_bit_filters] = bits; |
| 976 | nr_bit_filters++; |
| 977 | } |
| 978 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 979 | static uint64_t parse_flag_name(const char *str, int len) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 980 | { |
Ulrich Drepper | e30d539 | 2012-05-29 15:06:30 -0700 | [diff] [blame] | 981 | size_t i; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 982 | |
| 983 | if (!*str || !len) |
| 984 | return 0; |
| 985 | |
| 986 | if (len <= 8 && !strncmp(str, "compound", len)) |
| 987 | return BITS_COMPOUND; |
| 988 | |
| 989 | for (i = 0; i < ARRAY_SIZE(page_flag_names); i++) { |
| 990 | if (!page_flag_names[i]) |
| 991 | continue; |
| 992 | if (!strncmp(str, page_flag_names[i] + 2, len)) |
| 993 | return 1ULL << i; |
| 994 | } |
| 995 | |
| 996 | return parse_number(str); |
| 997 | } |
| 998 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 999 | static uint64_t parse_flag_names(const char *str, int all) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1000 | { |
| 1001 | const char *p = str; |
| 1002 | uint64_t flags = 0; |
| 1003 | |
| 1004 | while (1) { |
| 1005 | if (*p == ',' || *p == '=' || *p == '\0') { |
| 1006 | if ((*str != '~') || (*str == '~' && all && *++str)) |
| 1007 | flags |= parse_flag_name(str, p - str); |
| 1008 | if (*p != ',') |
| 1009 | break; |
| 1010 | str = p + 1; |
| 1011 | } |
| 1012 | p++; |
| 1013 | } |
| 1014 | |
| 1015 | return flags; |
| 1016 | } |
| 1017 | |
Ladinu Chandrasinghe | b7ed698 | 2009-09-22 16:43:42 -0700 | [diff] [blame] | 1018 | static void parse_bits_mask(const char *optarg) |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1019 | { |
| 1020 | uint64_t mask; |
| 1021 | uint64_t bits; |
| 1022 | const char *p; |
| 1023 | |
| 1024 | p = strchr(optarg, '='); |
| 1025 | if (p == optarg) { |
| 1026 | mask = KPF_ALL_BITS; |
| 1027 | bits = parse_flag_names(p + 1, 0); |
| 1028 | } else if (p) { |
| 1029 | mask = parse_flag_names(optarg, 0); |
| 1030 | bits = parse_flag_names(p + 1, 0); |
| 1031 | } else if (strchr(optarg, '~')) { |
| 1032 | mask = parse_flag_names(optarg, 1); |
| 1033 | bits = parse_flag_names(optarg, 0); |
| 1034 | } else { |
| 1035 | mask = parse_flag_names(optarg, 0); |
| 1036 | bits = KPF_ALL_BITS; |
| 1037 | } |
| 1038 | |
| 1039 | add_bits_filter(mask, bits); |
| 1040 | } |
| 1041 | |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 1042 | static void describe_flags(const char *optarg) |
| 1043 | { |
| 1044 | uint64_t flags = parse_flag_names(optarg, 0); |
| 1045 | |
| 1046 | printf("0x%016llx\t%s\t%s\n", |
| 1047 | (unsigned long long)flags, |
| 1048 | page_flag_name(flags), |
| 1049 | page_flag_longname(flags)); |
| 1050 | } |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1051 | |
Tommi Rantala | 3428838 | 2009-12-14 17:57:48 -0800 | [diff] [blame] | 1052 | static const struct option opts[] = { |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1053 | { "raw" , 0, NULL, 'r' }, |
| 1054 | { "pid" , 1, NULL, 'p' }, |
| 1055 | { "file" , 1, NULL, 'f' }, |
| 1056 | { "addr" , 1, NULL, 'a' }, |
| 1057 | { "bits" , 1, NULL, 'b' }, |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 1058 | { "describe" , 1, NULL, 'd' }, |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1059 | { "list" , 0, NULL, 'l' }, |
| 1060 | { "list-each" , 0, NULL, 'L' }, |
| 1061 | { "no-summary", 0, NULL, 'N' }, |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 1062 | { "hwpoison" , 0, NULL, 'X' }, |
| 1063 | { "unpoison" , 0, NULL, 'x' }, |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1064 | { "help" , 0, NULL, 'h' }, |
| 1065 | { NULL , 0, NULL, 0 } |
| 1066 | }; |
| 1067 | |
| 1068 | int main(int argc, char *argv[]) |
| 1069 | { |
| 1070 | int c; |
| 1071 | |
| 1072 | page_size = getpagesize(); |
| 1073 | |
| 1074 | while ((c = getopt_long(argc, argv, |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 1075 | "rp:f:a:b:d:lLNXxh", opts, NULL)) != -1) { |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1076 | switch (c) { |
| 1077 | case 'r': |
| 1078 | opt_raw = 1; |
| 1079 | break; |
| 1080 | case 'p': |
| 1081 | parse_pid(optarg); |
| 1082 | break; |
| 1083 | case 'f': |
| 1084 | parse_file(optarg); |
| 1085 | break; |
| 1086 | case 'a': |
| 1087 | parse_addr_range(optarg); |
| 1088 | break; |
| 1089 | case 'b': |
| 1090 | parse_bits_mask(optarg); |
| 1091 | break; |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 1092 | case 'd': |
Alex Chiang | dcfe730 | 2009-12-14 17:57:52 -0800 | [diff] [blame] | 1093 | describe_flags(optarg); |
Alex Chiang | bb86a73 | 2009-12-14 17:57:54 -0800 | [diff] [blame] | 1094 | exit(0); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1095 | case 'l': |
| 1096 | opt_list = 1; |
| 1097 | break; |
| 1098 | case 'L': |
| 1099 | opt_list = 2; |
| 1100 | break; |
| 1101 | case 'N': |
| 1102 | opt_no_summary = 1; |
| 1103 | break; |
Wu Fengguang | a54fed9 | 2009-10-07 16:32:32 -0700 | [diff] [blame] | 1104 | case 'X': |
| 1105 | opt_hwpoison = 1; |
| 1106 | prepare_hwpoison_fd(); |
| 1107 | break; |
| 1108 | case 'x': |
| 1109 | opt_unpoison = 1; |
| 1110 | prepare_hwpoison_fd(); |
| 1111 | break; |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1112 | case 'h': |
| 1113 | usage(); |
| 1114 | exit(0); |
| 1115 | default: |
| 1116 | usage(); |
| 1117 | exit(1); |
| 1118 | } |
| 1119 | } |
| 1120 | |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 1121 | if (opt_list && opt_pid) |
| 1122 | printf("voffset\t"); |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 1123 | if (opt_list && opt_file) |
| 1124 | printf("foffset\t"); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1125 | if (opt_list == 1) |
Wu Fengguang | 0b4b2ad | 2009-09-23 15:56:16 -0700 | [diff] [blame] | 1126 | printf("offset\tlen\tflags\n"); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1127 | if (opt_list == 2) |
| 1128 | printf("offset\tflags\n"); |
| 1129 | |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 1130 | if (opt_file) |
| 1131 | walk_page_cache(); |
| 1132 | else |
| 1133 | walk_addr_ranges(); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1134 | |
| 1135 | if (opt_list == 1) |
Konstantin Khlebnikov | 65a6a41 | 2014-04-07 15:37:15 -0700 | [diff] [blame] | 1136 | flush_page_range(); |
Wu Fengguang | 35efa5e | 2009-06-16 15:32:27 -0700 | [diff] [blame] | 1137 | |
| 1138 | if (opt_no_summary) |
| 1139 | return 0; |
| 1140 | |
| 1141 | if (opt_list) |
| 1142 | printf("\n\n"); |
| 1143 | |
| 1144 | show_summary(); |
| 1145 | |
| 1146 | return 0; |
| 1147 | } |