2009-06-17 06:32:27 +08:00
|
|
|
/*
|
|
|
|
* page-types: Tool for querying page flags
|
|
|
|
*
|
2009-12-16 19:19:57 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should find a copy of v2 of the GNU General Public License somewhere on
|
|
|
|
* your Linux system; if not, write to the Free Software Foundation, Inc., 59
|
|
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
*
|
2009-06-17 06:32:27 +08:00
|
|
|
* Copyright (C) 2009 Intel corporation
|
2009-10-08 07:32:28 +08:00
|
|
|
*
|
|
|
|
* Authors: Wu Fengguang <fengguang.wu@intel.com>
|
2009-06-17 06:32:27 +08:00
|
|
|
*/
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#define _GNU_SOURCE
|
2009-06-17 06:32:27 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <limits.h>
|
2009-09-24 06:56:16 +08:00
|
|
|
#include <assert.h>
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
#include <ftw.h>
|
|
|
|
#include <time.h>
|
2014-06-05 07:05:30 +08:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <signal.h>
|
2009-06-17 06:32:27 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/fcntl.h>
|
2011-03-23 07:35:03 +08:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/statfs.h>
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
#include <sys/mman.h>
|
2012-10-13 17:46:48 +08:00
|
|
|
#include "../../include/uapi/linux/magic.h"
|
2012-10-26 04:37:57 +08:00
|
|
|
#include "../../include/uapi/linux/kernel-page-flags.h"
|
2015-09-23 00:13:04 +08:00
|
|
|
#include <api/fs/fs.h>
|
2009-06-17 06:32:27 +08:00
|
|
|
|
2011-03-23 07:35:03 +08:00
|
|
|
#ifndef MAX_PATH
|
|
|
|
# define MAX_PATH 256
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STR
|
|
|
|
# define _STR(x) #x
|
|
|
|
# define STR(x) _STR(x)
|
|
|
|
#endif
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
/*
|
|
|
|
* pagemap kernel ABI bits
|
|
|
|
*/
|
|
|
|
|
2015-09-09 06:00:02 +08:00
|
|
|
#define PM_ENTRY_BYTES 8
|
|
|
|
#define PM_PFRAME_BITS 55
|
|
|
|
#define PM_PFRAME_MASK ((1LL << PM_PFRAME_BITS) - 1)
|
|
|
|
#define PM_PFRAME(x) ((x) & PM_PFRAME_MASK)
|
2016-03-18 05:17:47 +08:00
|
|
|
#define MAX_SWAPFILES_SHIFT 5
|
|
|
|
#define PM_SWAP_OFFSET(x) (((x) & PM_PFRAME_MASK) >> MAX_SWAPFILES_SHIFT)
|
2015-09-09 06:00:02 +08:00
|
|
|
#define PM_SOFT_DIRTY (1ULL << 55)
|
2015-09-09 06:00:10 +08:00
|
|
|
#define PM_MMAP_EXCLUSIVE (1ULL << 56)
|
2015-09-09 06:00:02 +08:00
|
|
|
#define PM_FILE (1ULL << 61)
|
|
|
|
#define PM_SWAP (1ULL << 62)
|
|
|
|
#define PM_PRESENT (1ULL << 63)
|
2009-09-24 06:56:16 +08:00
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
/*
|
|
|
|
* kernel page flags
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define KPF_BYTES 8
|
|
|
|
#define PROC_KPAGEFLAGS "/proc/kpageflags"
|
2016-03-18 05:18:18 +08:00
|
|
|
#define PROC_KPAGECGROUP "/proc/kpagecgroup"
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
/* [32-] kernel hacking assistances */
|
|
|
|
#define KPF_RESERVED 32
|
|
|
|
#define KPF_MLOCKED 33
|
|
|
|
#define KPF_MAPPEDTODISK 34
|
|
|
|
#define KPF_PRIVATE 35
|
|
|
|
#define KPF_PRIVATE_2 36
|
|
|
|
#define KPF_OWNER_PRIVATE 37
|
|
|
|
#define KPF_ARCH 38
|
|
|
|
#define KPF_UNCACHED 39
|
2013-11-13 07:07:50 +08:00
|
|
|
#define KPF_SOFTDIRTY 40
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
/* [48-] take some arbitrary free slots for expanding overloaded flags
|
|
|
|
* not part of kernel API
|
|
|
|
*/
|
|
|
|
#define KPF_READAHEAD 48
|
|
|
|
#define KPF_SLOB_FREE 49
|
|
|
|
#define KPF_SLUB_FROZEN 50
|
|
|
|
#define KPF_SLUB_DEBUG 51
|
2016-03-18 05:17:47 +08:00
|
|
|
#define KPF_FILE 61
|
|
|
|
#define KPF_SWAP 62
|
2015-09-09 06:00:10 +08:00
|
|
|
#define KPF_MMAP_EXCLUSIVE 63
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
#define KPF_ALL_BITS ((uint64_t)~0ULL)
|
|
|
|
#define KPF_HACKERS_BITS (0xffffULL << 32)
|
|
|
|
#define KPF_OVERLOADED_BITS (0xffffULL << 48)
|
|
|
|
#define BIT(name) (1ULL << KPF_##name)
|
|
|
|
#define BITS_COMPOUND (BIT(COMPOUND_HEAD) | BIT(COMPOUND_TAIL))
|
|
|
|
|
2012-03-29 05:42:55 +08:00
|
|
|
static const char * const page_flag_names[] = {
|
2009-06-17 06:32:27 +08:00
|
|
|
[KPF_LOCKED] = "L:locked",
|
|
|
|
[KPF_ERROR] = "E:error",
|
|
|
|
[KPF_REFERENCED] = "R:referenced",
|
|
|
|
[KPF_UPTODATE] = "U:uptodate",
|
|
|
|
[KPF_DIRTY] = "D:dirty",
|
|
|
|
[KPF_LRU] = "l:lru",
|
|
|
|
[KPF_ACTIVE] = "A:active",
|
|
|
|
[KPF_SLAB] = "S:slab",
|
|
|
|
[KPF_WRITEBACK] = "W:writeback",
|
|
|
|
[KPF_RECLAIM] = "I:reclaim",
|
|
|
|
[KPF_BUDDY] = "B:buddy",
|
|
|
|
|
|
|
|
[KPF_MMAP] = "M:mmap",
|
|
|
|
[KPF_ANON] = "a:anonymous",
|
|
|
|
[KPF_SWAPCACHE] = "s:swapcache",
|
|
|
|
[KPF_SWAPBACKED] = "b:swapbacked",
|
|
|
|
[KPF_COMPOUND_HEAD] = "H:compound_head",
|
|
|
|
[KPF_COMPOUND_TAIL] = "T:compound_tail",
|
|
|
|
[KPF_HUGE] = "G:huge",
|
|
|
|
[KPF_UNEVICTABLE] = "u:unevictable",
|
2009-10-08 07:32:27 +08:00
|
|
|
[KPF_HWPOISON] = "X:hwpoison",
|
2009-06-17 06:32:27 +08:00
|
|
|
[KPF_NOPAGE] = "n:nopage",
|
2009-10-08 07:32:28 +08:00
|
|
|
[KPF_KSM] = "x:ksm",
|
pagemap: document KPF_THP and make page-types aware of it
page-types, which is a common user of pagemap, gets aware of thp with this
patch. This helps system admins and kernel hackers know about how thp
works. Here is a sample output of page-types over a thp:
$ page-types -p <pid> --raw --list
voffset offset len flags
...
7f9d40200 3f8400 1 ___U_lA____Ma_bH______t____________
7f9d40201 3f8401 1ff ________________T_____t____________
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000410000 511 1 ________________T_____t____________ compound_tail,thp
0x000000000040d868 1 0 ___U_lA____Ma_bH______t____________ uptodate,lru,active,mmap,anonymous,swapbacked,compound_head,thp
Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Acked-by: Wu Fengguang <fengguang.wu@intel.com>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-22 07:33:58 +08:00
|
|
|
[KPF_THP] = "t:thp",
|
2014-10-10 06:29:32 +08:00
|
|
|
[KPF_BALLOON] = "o:balloon",
|
2018-06-08 08:08:23 +08:00
|
|
|
[KPF_PGTABLE] = "g:pgtable",
|
2015-02-12 07:24:51 +08:00
|
|
|
[KPF_ZERO_PAGE] = "z:zero_page",
|
2015-11-21 07:56:59 +08:00
|
|
|
[KPF_IDLE] = "i:idle_page",
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
[KPF_RESERVED] = "r:reserved",
|
|
|
|
[KPF_MLOCKED] = "m:mlocked",
|
|
|
|
[KPF_MAPPEDTODISK] = "d:mappedtodisk",
|
|
|
|
[KPF_PRIVATE] = "P:private",
|
|
|
|
[KPF_PRIVATE_2] = "p:private_2",
|
|
|
|
[KPF_OWNER_PRIVATE] = "O:owner_private",
|
|
|
|
[KPF_ARCH] = "h:arch",
|
|
|
|
[KPF_UNCACHED] = "c:uncached",
|
2013-11-13 07:07:50 +08:00
|
|
|
[KPF_SOFTDIRTY] = "f:softdirty",
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
[KPF_READAHEAD] = "I:readahead",
|
|
|
|
[KPF_SLOB_FREE] = "P:slob_free",
|
|
|
|
[KPF_SLUB_FROZEN] = "A:slub_frozen",
|
|
|
|
[KPF_SLUB_DEBUG] = "E:slub_debug",
|
2015-09-09 06:00:10 +08:00
|
|
|
|
|
|
|
[KPF_FILE] = "F:file",
|
2016-03-18 05:17:47 +08:00
|
|
|
[KPF_SWAP] = "w:swap",
|
2015-09-09 06:00:10 +08:00
|
|
|
[KPF_MMAP_EXCLUSIVE] = "1:mmap_exclusive",
|
2009-06-17 06:32:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-29 05:42:55 +08:00
|
|
|
static const char * const debugfs_known_mountpoints[] = {
|
2011-03-23 07:35:03 +08:00
|
|
|
"/sys/kernel/debug",
|
|
|
|
"/debug",
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
/*
|
|
|
|
* data structures
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int opt_raw; /* for kernel developers */
|
|
|
|
static int opt_list; /* list pages (in ranges) */
|
|
|
|
static int opt_no_summary; /* don't show summary */
|
|
|
|
static pid_t opt_pid; /* process to walk */
|
2018-02-01 08:21:23 +08:00
|
|
|
const char *opt_file; /* file or directory path */
|
2016-03-18 05:18:18 +08:00
|
|
|
static uint64_t opt_cgroup; /* cgroup inode */
|
|
|
|
static int opt_list_cgroup;/* list page cgroup */
|
2018-02-01 08:21:23 +08:00
|
|
|
static const char *opt_kpageflags;/* kpageflags file to parse */
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
#define MAX_ADDR_RANGES 1024
|
|
|
|
static int nr_addr_ranges;
|
|
|
|
static unsigned long opt_offset[MAX_ADDR_RANGES];
|
|
|
|
static unsigned long opt_size[MAX_ADDR_RANGES];
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
#define MAX_VMAS 10240
|
|
|
|
static int nr_vmas;
|
|
|
|
static unsigned long pg_start[MAX_VMAS];
|
|
|
|
static unsigned long pg_end[MAX_VMAS];
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
#define MAX_BIT_FILTERS 64
|
|
|
|
static int nr_bit_filters;
|
|
|
|
static uint64_t opt_mask[MAX_BIT_FILTERS];
|
|
|
|
static uint64_t opt_bits[MAX_BIT_FILTERS];
|
|
|
|
|
|
|
|
static int page_size;
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
static int pagemap_fd;
|
2009-06-17 06:32:27 +08:00
|
|
|
static int kpageflags_fd;
|
2016-03-18 05:18:18 +08:00
|
|
|
static int kpagecgroup_fd = -1;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
2009-10-08 07:32:32 +08:00
|
|
|
static int opt_hwpoison;
|
|
|
|
static int opt_unpoison;
|
|
|
|
|
2015-09-23 00:13:04 +08:00
|
|
|
static const char *hwpoison_debug_fs;
|
2009-10-08 07:32:32 +08:00
|
|
|
static int hwpoison_inject_fd;
|
|
|
|
static int hwpoison_forget_fd;
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
#define HASH_SHIFT 13
|
|
|
|
#define HASH_SIZE (1 << HASH_SHIFT)
|
|
|
|
#define HASH_MASK (HASH_SIZE - 1)
|
|
|
|
#define HASH_KEY(flags) (flags & HASH_MASK)
|
|
|
|
|
|
|
|
static unsigned long total_pages;
|
|
|
|
static unsigned long nr_pages[HASH_SIZE];
|
2012-03-29 05:42:55 +08:00
|
|
|
static uint64_t page_flags[HASH_SIZE];
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* helper functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
|
|
|
#define min_t(type, x, y) ({ \
|
|
|
|
type __min1 = (x); \
|
|
|
|
type __min2 = (y); \
|
|
|
|
__min1 < __min2 ? __min1 : __min2; })
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
#define max_t(type, x, y) ({ \
|
|
|
|
type __max1 = (x); \
|
|
|
|
type __max2 = (y); \
|
|
|
|
__max1 > __max2 ? __max1 : __max2; })
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static unsigned long pages2mb(unsigned long pages)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
return (pages * page_size) >> 20;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void fatal(const char *x, ...)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, x);
|
|
|
|
vfprintf(stderr, x, ap);
|
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2009-10-17 05:06:13 +08:00
|
|
|
static int checked_open(const char *pathname, int flags)
|
2009-10-08 07:32:29 +08:00
|
|
|
{
|
|
|
|
int fd = open(pathname, flags);
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
perror(pathname);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
/*
|
|
|
|
* pagemap/kpageflags routines
|
|
|
|
*/
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
static unsigned long do_u64_read(int fd, const char *name,
|
2009-10-08 07:32:30 +08:00
|
|
|
uint64_t *buf,
|
|
|
|
unsigned long index,
|
|
|
|
unsigned long count)
|
|
|
|
{
|
|
|
|
long bytes;
|
|
|
|
|
|
|
|
if (index > ULONG_MAX / 8)
|
|
|
|
fatal("index overflow: %lu\n", index);
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
bytes = pread(fd, buf, count * 8, (off_t)index * 8);
|
2009-10-08 07:32:30 +08:00
|
|
|
if (bytes < 0) {
|
|
|
|
perror(name);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (bytes % 8)
|
|
|
|
fatal("partial read: %lu bytes\n", bytes);
|
|
|
|
|
|
|
|
return bytes / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long kpageflags_read(uint64_t *buf,
|
|
|
|
unsigned long index,
|
|
|
|
unsigned long pages)
|
|
|
|
{
|
2018-02-01 08:21:23 +08:00
|
|
|
return do_u64_read(kpageflags_fd, opt_kpageflags, buf, index, pages);
|
2009-10-08 07:32:30 +08:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
static unsigned long kpagecgroup_read(uint64_t *buf,
|
|
|
|
unsigned long index,
|
|
|
|
unsigned long pages)
|
|
|
|
{
|
|
|
|
if (kpagecgroup_fd < 0)
|
|
|
|
return pages;
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
return do_u64_read(kpagecgroup_fd, opt_kpageflags, buf, index, pages);
|
2016-03-18 05:18:18 +08:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
static unsigned long pagemap_read(uint64_t *buf,
|
|
|
|
unsigned long index,
|
|
|
|
unsigned long pages)
|
|
|
|
{
|
|
|
|
return do_u64_read(pagemap_fd, "/proc/pid/pagemap", buf, index, pages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long pagemap_pfn(uint64_t val)
|
|
|
|
{
|
|
|
|
unsigned long pfn;
|
|
|
|
|
|
|
|
if (val & PM_PRESENT)
|
|
|
|
pfn = PM_PFRAME(val);
|
|
|
|
else
|
|
|
|
pfn = 0;
|
|
|
|
|
|
|
|
return pfn;
|
|
|
|
}
|
|
|
|
|
2016-03-18 05:17:47 +08:00
|
|
|
static unsigned long pagemap_swap_offset(uint64_t val)
|
|
|
|
{
|
|
|
|
return val & PM_SWAP ? PM_SWAP_OFFSET(val) : 0;
|
|
|
|
}
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* page flag names
|
|
|
|
*/
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static char *page_flag_name(uint64_t flags)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
static char buf[65];
|
|
|
|
int present;
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t i, j;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
for (i = 0, j = 0; i < ARRAY_SIZE(page_flag_names); i++) {
|
|
|
|
present = (flags >> i) & 1;
|
|
|
|
if (!page_flag_names[i]) {
|
|
|
|
if (present)
|
tree-wide: fix assorted typos all over the place
That is "success", "unknown", "through", "performance", "[re|un]mapping"
, "access", "default", "reasonable", "[con]currently", "temperature"
, "channel", "[un]used", "application", "example","hierarchy", "therefore"
, "[over|under]flow", "contiguous", "threshold", "enough" and others.
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2009-11-14 23:09:05 +08:00
|
|
|
fatal("unknown flag bit %d\n", i);
|
2009-06-17 06:32:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buf[j++] = present ? page_flag_names[i][0] : '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static char *page_flag_longname(uint64_t flags)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
static char buf[1024];
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t i, n;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
for (i = 0, n = 0; i < ARRAY_SIZE(page_flag_names); i++) {
|
|
|
|
if (!page_flag_names[i])
|
|
|
|
continue;
|
|
|
|
if ((flags >> i) & 1)
|
|
|
|
n += snprintf(buf + n, sizeof(buf) - n, "%s,",
|
|
|
|
page_flag_names[i] + 2);
|
|
|
|
}
|
|
|
|
if (n)
|
|
|
|
n--;
|
|
|
|
buf[n] = '\0';
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* page list and summary
|
|
|
|
*/
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
static void show_page_range(unsigned long voffset, unsigned long offset,
|
2016-03-18 05:18:18 +08:00
|
|
|
unsigned long size, uint64_t flags, uint64_t cgroup)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
static uint64_t flags0;
|
2016-03-18 05:18:18 +08:00
|
|
|
static uint64_t cgroup0;
|
2009-09-24 06:56:16 +08:00
|
|
|
static unsigned long voff;
|
2009-06-17 06:32:27 +08:00
|
|
|
static unsigned long index;
|
|
|
|
static unsigned long count;
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
if (flags == flags0 && cgroup == cgroup0 && offset == index + count &&
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
size && voffset == voff + count) {
|
|
|
|
count += size;
|
2009-06-17 06:32:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
if (count) {
|
|
|
|
if (opt_pid)
|
|
|
|
printf("%lx\t", voff);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (opt_file)
|
|
|
|
printf("%lu\t", voff);
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_list_cgroup)
|
|
|
|
printf("@%llu\t", (unsigned long long)cgroup0);
|
2009-09-24 06:56:16 +08:00
|
|
|
printf("%lx\t%lx\t%s\n",
|
2009-06-17 06:32:27 +08:00
|
|
|
index, count, page_flag_name(flags0));
|
2009-09-24 06:56:16 +08:00
|
|
|
}
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
flags0 = flags;
|
2016-03-18 05:18:18 +08:00
|
|
|
cgroup0= cgroup;
|
2009-06-17 06:32:27 +08:00
|
|
|
index = offset;
|
2009-09-24 06:56:16 +08:00
|
|
|
voff = voffset;
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
count = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_page_range(void)
|
|
|
|
{
|
2016-03-18 05:18:18 +08:00
|
|
|
show_page_range(0, 0, 0, 0, 0);
|
2009-06-17 06:32:27 +08:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
static void show_page(unsigned long voffset, unsigned long offset,
|
|
|
|
uint64_t flags, uint64_t cgroup)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2009-09-24 06:56:16 +08:00
|
|
|
if (opt_pid)
|
|
|
|
printf("%lx\t", voffset);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (opt_file)
|
|
|
|
printf("%lu\t", voffset);
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_list_cgroup)
|
|
|
|
printf("@%llu\t", (unsigned long long)cgroup);
|
2009-09-24 06:56:16 +08:00
|
|
|
printf("%lx\t%s\n", offset, page_flag_name(flags));
|
2009-06-17 06:32:27 +08:00
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void show_summary(void)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t i;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
printf(" flags\tpage-count MB"
|
|
|
|
" symbolic-flags\t\t\tlong-symbolic-flags\n");
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(nr_pages); i++) {
|
|
|
|
if (nr_pages[i])
|
|
|
|
printf("0x%016llx\t%10lu %8lu %s\t%s\n",
|
|
|
|
(unsigned long long)page_flags[i],
|
|
|
|
nr_pages[i],
|
|
|
|
pages2mb(nr_pages[i]),
|
|
|
|
page_flag_name(page_flags[i]),
|
|
|
|
page_flag_longname(page_flags[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" total\t%10lu %8lu\n",
|
|
|
|
total_pages, pages2mb(total_pages));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* page flag filters
|
|
|
|
*/
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static int bit_mask_ok(uint64_t flags)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_bit_filters; i++) {
|
|
|
|
if (opt_bits[i] == KPF_ALL_BITS) {
|
|
|
|
if ((flags & opt_mask[i]) == 0)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if ((flags & opt_mask[i]) != opt_bits[i])
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-11-13 07:07:50 +08:00
|
|
|
static uint64_t expand_overloaded_flags(uint64_t flags, uint64_t pme)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
/* SLOB/SLUB overload several page flags */
|
|
|
|
if (flags & BIT(SLAB)) {
|
|
|
|
if (flags & BIT(PRIVATE))
|
|
|
|
flags ^= BIT(PRIVATE) | BIT(SLOB_FREE);
|
|
|
|
if (flags & BIT(ACTIVE))
|
|
|
|
flags ^= BIT(ACTIVE) | BIT(SLUB_FROZEN);
|
|
|
|
if (flags & BIT(ERROR))
|
|
|
|
flags ^= BIT(ERROR) | BIT(SLUB_DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PG_reclaim is overloaded as PG_readahead in the read path */
|
|
|
|
if ((flags & (BIT(RECLAIM) | BIT(WRITEBACK))) == BIT(RECLAIM))
|
|
|
|
flags ^= BIT(RECLAIM) | BIT(READAHEAD);
|
|
|
|
|
2013-11-13 07:07:50 +08:00
|
|
|
if (pme & PM_SOFT_DIRTY)
|
|
|
|
flags |= BIT(SOFTDIRTY);
|
2015-09-09 06:00:10 +08:00
|
|
|
if (pme & PM_FILE)
|
|
|
|
flags |= BIT(FILE);
|
2016-03-18 05:17:47 +08:00
|
|
|
if (pme & PM_SWAP)
|
|
|
|
flags |= BIT(SWAP);
|
2015-09-09 06:00:10 +08:00
|
|
|
if (pme & PM_MMAP_EXCLUSIVE)
|
|
|
|
flags |= BIT(MMAP_EXCLUSIVE);
|
2013-11-13 07:07:50 +08:00
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static uint64_t well_known_flags(uint64_t flags)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
/* hide flags intended only for kernel hacker */
|
|
|
|
flags &= ~KPF_HACKERS_BITS;
|
|
|
|
|
|
|
|
/* hide non-hugeTLB compound pages */
|
|
|
|
if ((flags & BITS_COMPOUND) && !(flags & BIT(HUGE)))
|
|
|
|
flags &= ~BITS_COMPOUND;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2013-11-13 07:07:50 +08:00
|
|
|
static uint64_t kpageflags_flags(uint64_t flags, uint64_t pme)
|
2009-10-08 07:32:31 +08:00
|
|
|
{
|
2013-11-13 07:07:50 +08:00
|
|
|
if (opt_raw)
|
|
|
|
flags = expand_overloaded_flags(flags, pme);
|
|
|
|
else
|
2009-10-08 07:32:31 +08:00
|
|
|
flags = well_known_flags(flags);
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:32:32 +08:00
|
|
|
/*
|
|
|
|
* page actions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void prepare_hwpoison_fd(void)
|
|
|
|
{
|
2011-03-23 07:35:03 +08:00
|
|
|
char buf[MAX_PATH + 1];
|
|
|
|
|
2015-09-23 00:13:04 +08:00
|
|
|
hwpoison_debug_fs = debugfs__mount();
|
2013-02-20 23:32:33 +08:00
|
|
|
if (!hwpoison_debug_fs) {
|
|
|
|
perror("mount debugfs");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2009-10-08 07:32:32 +08:00
|
|
|
|
|
|
|
if (opt_hwpoison && !hwpoison_inject_fd) {
|
2011-03-23 07:35:03 +08:00
|
|
|
snprintf(buf, MAX_PATH, "%s/hwpoison/corrupt-pfn",
|
|
|
|
hwpoison_debug_fs);
|
2009-10-08 07:32:32 +08:00
|
|
|
hwpoison_inject_fd = checked_open(buf, O_WRONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_unpoison && !hwpoison_forget_fd) {
|
2011-03-23 07:35:03 +08:00
|
|
|
snprintf(buf, MAX_PATH, "%s/hwpoison/unpoison-pfn",
|
|
|
|
hwpoison_debug_fs);
|
2009-10-08 07:32:32 +08:00
|
|
|
hwpoison_forget_fd = checked_open(buf, O_WRONLY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwpoison_page(unsigned long offset)
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = sprintf(buf, "0x%lx\n", offset);
|
|
|
|
len = write(hwpoison_inject_fd, buf, len);
|
|
|
|
if (len < 0) {
|
|
|
|
perror("hwpoison inject");
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unpoison_page(unsigned long offset)
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = sprintf(buf, "0x%lx\n", offset);
|
|
|
|
len = write(hwpoison_forget_fd, buf, len);
|
|
|
|
if (len < 0) {
|
|
|
|
perror("hwpoison forget");
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
/*
|
|
|
|
* page frame walker
|
|
|
|
*/
|
|
|
|
|
2012-05-30 06:06:30 +08:00
|
|
|
static size_t hash_slot(uint64_t flags)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t k = HASH_KEY(flags);
|
|
|
|
size_t i;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
/* Explicitly reserve slot 0 for flags 0: the following logic
|
|
|
|
* cannot distinguish an unoccupied slot from slot (flags==0).
|
|
|
|
*/
|
|
|
|
if (flags == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* search through the remaining (HASH_SIZE-1) slots */
|
|
|
|
for (i = 1; i < ARRAY_SIZE(page_flags); i++, k++) {
|
|
|
|
if (!k || k >= ARRAY_SIZE(page_flags))
|
|
|
|
k = 1;
|
|
|
|
if (page_flags[k] == 0) {
|
|
|
|
page_flags[k] = flags;
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
if (page_flags[k] == flags)
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal("hash table full: bump up HASH_SHIFT?\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
static void add_page(unsigned long voffset, unsigned long offset,
|
|
|
|
uint64_t flags, uint64_t cgroup, uint64_t pme)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2013-11-13 07:07:50 +08:00
|
|
|
flags = kpageflags_flags(flags, pme);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
if (!bit_mask_ok(flags))
|
|
|
|
return;
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_cgroup && cgroup != (uint64_t)opt_cgroup)
|
|
|
|
return;
|
|
|
|
|
2009-10-08 07:32:32 +08:00
|
|
|
if (opt_hwpoison)
|
|
|
|
hwpoison_page(offset);
|
|
|
|
if (opt_unpoison)
|
|
|
|
unpoison_page(offset);
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
if (opt_list == 1)
|
2016-03-18 05:18:18 +08:00
|
|
|
show_page_range(voffset, offset, 1, flags, cgroup);
|
2009-06-17 06:32:27 +08:00
|
|
|
else if (opt_list == 2)
|
2016-03-18 05:18:18 +08:00
|
|
|
show_page(voffset, offset, flags, cgroup);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
nr_pages[hash_slot(flags)]++;
|
|
|
|
total_pages++;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
#define KPAGEFLAGS_BATCH (64 << 10) /* 64k pages */
|
2009-10-08 07:32:30 +08:00
|
|
|
static void walk_pfn(unsigned long voffset,
|
|
|
|
unsigned long index,
|
2013-11-13 07:07:50 +08:00
|
|
|
unsigned long count,
|
|
|
|
uint64_t pme)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2009-10-08 07:32:30 +08:00
|
|
|
uint64_t buf[KPAGEFLAGS_BATCH];
|
2016-03-18 05:18:18 +08:00
|
|
|
uint64_t cgi[KPAGEFLAGS_BATCH];
|
2009-06-17 06:32:27 +08:00
|
|
|
unsigned long batch;
|
2012-05-30 06:06:30 +08:00
|
|
|
unsigned long pages;
|
2009-06-17 06:32:27 +08:00
|
|
|
unsigned long i;
|
|
|
|
|
2016-03-18 05:20:22 +08:00
|
|
|
/*
|
|
|
|
* kpagecgroup_read() reads only if kpagecgroup were opened, but
|
|
|
|
* /proc/kpagecgroup might even not exist, so it's better to fill
|
|
|
|
* them with zeros here.
|
|
|
|
*/
|
|
|
|
if (count == 1)
|
|
|
|
cgi[0] = 0;
|
|
|
|
else
|
|
|
|
memset(cgi, 0, sizeof cgi);
|
2016-03-18 05:18:18 +08:00
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
while (count) {
|
2009-10-08 07:32:30 +08:00
|
|
|
batch = min_t(unsigned long, count, KPAGEFLAGS_BATCH);
|
|
|
|
pages = kpageflags_read(buf, index, batch);
|
|
|
|
if (pages == 0)
|
2009-06-17 06:32:27 +08:00
|
|
|
break;
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
if (kpagecgroup_read(cgi, index, pages) != pages)
|
|
|
|
fatal("kpagecgroup returned fewer pages than expected");
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
for (i = 0; i < pages; i++)
|
2016-03-18 05:18:18 +08:00
|
|
|
add_page(voffset + i, index + i, buf[i], cgi[i], pme);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
index += pages;
|
|
|
|
count -= pages;
|
2009-06-17 06:32:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 05:17:47 +08:00
|
|
|
static void walk_swap(unsigned long voffset, uint64_t pme)
|
|
|
|
{
|
|
|
|
uint64_t flags = kpageflags_flags(0, pme);
|
|
|
|
|
|
|
|
if (!bit_mask_ok(flags))
|
|
|
|
return;
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_cgroup)
|
|
|
|
return;
|
|
|
|
|
2016-03-18 05:17:47 +08:00
|
|
|
if (opt_list == 1)
|
2016-03-18 05:18:18 +08:00
|
|
|
show_page_range(voffset, pagemap_swap_offset(pme), 1, flags, 0);
|
2016-03-18 05:17:47 +08:00
|
|
|
else if (opt_list == 2)
|
2016-03-18 05:18:18 +08:00
|
|
|
show_page(voffset, pagemap_swap_offset(pme), flags, 0);
|
2016-03-18 05:17:47 +08:00
|
|
|
|
|
|
|
nr_pages[hash_slot(flags)]++;
|
|
|
|
total_pages++;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
#define PAGEMAP_BATCH (64 << 10)
|
|
|
|
static void walk_vma(unsigned long index, unsigned long count)
|
2009-09-24 06:56:16 +08:00
|
|
|
{
|
2009-10-08 07:32:30 +08:00
|
|
|
uint64_t buf[PAGEMAP_BATCH];
|
|
|
|
unsigned long batch;
|
|
|
|
unsigned long pages;
|
|
|
|
unsigned long pfn;
|
|
|
|
unsigned long i;
|
2009-09-24 06:56:16 +08:00
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
while (count) {
|
|
|
|
batch = min_t(unsigned long, count, PAGEMAP_BATCH);
|
|
|
|
pages = pagemap_read(buf, index, batch);
|
|
|
|
if (pages == 0)
|
|
|
|
break;
|
2009-09-24 06:56:16 +08:00
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
for (i = 0; i < pages; i++) {
|
|
|
|
pfn = pagemap_pfn(buf[i]);
|
|
|
|
if (pfn)
|
2013-11-13 07:07:50 +08:00
|
|
|
walk_pfn(index + i, pfn, 1, buf[i]);
|
2016-03-18 05:17:47 +08:00
|
|
|
if (buf[i] & PM_SWAP)
|
|
|
|
walk_swap(index + i, buf[i]);
|
2009-10-08 07:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
index += pages;
|
|
|
|
count -= pages;
|
|
|
|
}
|
2009-09-24 06:56:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void walk_task(unsigned long index, unsigned long count)
|
|
|
|
{
|
|
|
|
const unsigned long end = index + count;
|
2009-10-08 07:32:30 +08:00
|
|
|
unsigned long start;
|
|
|
|
int i = 0;
|
2009-09-24 06:56:16 +08:00
|
|
|
|
|
|
|
while (index < end) {
|
|
|
|
|
|
|
|
while (pg_end[i] <= index)
|
|
|
|
if (++i >= nr_vmas)
|
|
|
|
return;
|
|
|
|
if (pg_start[i] >= end)
|
|
|
|
return;
|
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
start = max_t(unsigned long, pg_start[i], index);
|
|
|
|
index = min_t(unsigned long, pg_end[i], end);
|
2009-09-24 06:56:16 +08:00
|
|
|
|
2009-10-08 07:32:30 +08:00
|
|
|
assert(start < index);
|
|
|
|
walk_vma(start, index - start);
|
2009-09-24 06:56:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_addr_range(unsigned long offset, unsigned long size)
|
|
|
|
{
|
|
|
|
if (nr_addr_ranges >= MAX_ADDR_RANGES)
|
|
|
|
fatal("too many addr ranges\n");
|
|
|
|
|
|
|
|
opt_offset[nr_addr_ranges] = offset;
|
|
|
|
opt_size[nr_addr_ranges] = min_t(unsigned long, size, ULONG_MAX-offset);
|
|
|
|
nr_addr_ranges++;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void walk_addr_ranges(void)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
kpageflags_fd = checked_open(opt_kpageflags, O_RDONLY);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
if (!nr_addr_ranges)
|
2009-09-24 06:56:16 +08:00
|
|
|
add_addr_range(0, ULONG_MAX);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nr_addr_ranges; i++)
|
2009-09-24 06:56:16 +08:00
|
|
|
if (!opt_pid)
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
walk_pfn(opt_offset[i], opt_offset[i], opt_size[i], 0);
|
2009-09-24 06:56:16 +08:00
|
|
|
else
|
|
|
|
walk_task(opt_offset[i], opt_size[i]);
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
close(kpageflags_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* user interface
|
|
|
|
*/
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static const char *page_flag_type(uint64_t flag)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
if (flag & KPF_HACKERS_BITS)
|
|
|
|
return "(r)";
|
|
|
|
if (flag & KPF_OVERLOADED_BITS)
|
|
|
|
return "(o)";
|
|
|
|
return " ";
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void usage(void)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t i, j;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
printf(
|
|
|
|
"page-types [options]\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" -r|--raw Raw mode, for kernel developers\n"
|
2009-12-15 09:57:52 +08:00
|
|
|
" -d|--describe flags Describe flags\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" -a|--addr addr-spec Walk a range of pages\n"
|
|
|
|
" -b|--bits bits-spec Walk pages with specified bits\n"
|
2016-03-18 05:18:18 +08:00
|
|
|
" -c|--cgroup path|@inode Walk pages within memory cgroup\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" -p|--pid pid Walk process address space\n"
|
|
|
|
" -f|--file filename Walk file address space\n"
|
|
|
|
" -l|--list Show page details in ranges\n"
|
|
|
|
" -L|--list-each Show page details one by one\n"
|
2016-03-18 05:18:18 +08:00
|
|
|
" -C|--list-cgroup Show cgroup inode for pages\n"
|
2010-08-06 02:23:11 +08:00
|
|
|
" -N|--no-summary Don't show summary info\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" -X|--hwpoison hwpoison pages\n"
|
|
|
|
" -x|--unpoison unpoison pages\n"
|
2018-02-01 08:21:23 +08:00
|
|
|
" -F|--kpageflags filename kpageflags file to parse\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" -h|--help Show this usage message\n"
|
2009-12-15 09:57:52 +08:00
|
|
|
"flags:\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" 0x10 bitfield format, e.g.\n"
|
|
|
|
" anon bit-name, e.g.\n"
|
|
|
|
" 0x10,anon comma-separated list, e.g.\n"
|
2009-06-17 06:32:27 +08:00
|
|
|
"addr-spec:\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" N one page at offset N (unit: pages)\n"
|
|
|
|
" N+M pages range from N to N+M-1\n"
|
|
|
|
" N,M pages range from N to M-1\n"
|
|
|
|
" N, pages range from N to end\n"
|
|
|
|
" ,M pages range from 0 to M-1\n"
|
2009-06-17 06:32:27 +08:00
|
|
|
"bits-spec:\n"
|
2009-12-15 09:57:53 +08:00
|
|
|
" bit1,bit2 (flags & (bit1|bit2)) != 0\n"
|
|
|
|
" bit1,bit2=bit1 (flags & (bit1|bit2)) == bit1\n"
|
|
|
|
" bit1,~bit2 (flags & (bit1|bit2)) == bit1\n"
|
|
|
|
" =bit1,bit2 flags == (bit1|bit2)\n"
|
2009-06-17 06:32:27 +08:00
|
|
|
"bit-names:\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < ARRAY_SIZE(page_flag_names); i++) {
|
|
|
|
if (!page_flag_names[i])
|
|
|
|
continue;
|
|
|
|
printf("%16s%s", page_flag_names[i] + 2,
|
|
|
|
page_flag_type(1ULL << i));
|
|
|
|
if (++j > 3) {
|
|
|
|
j = 0;
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n "
|
|
|
|
"(r) raw mode bits (o) overloaded bits\n");
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static unsigned long long parse_number(const char *str)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
unsigned long long n;
|
|
|
|
|
|
|
|
n = strtoll(str, NULL, 0);
|
|
|
|
|
|
|
|
if (n == 0 && str[0] != '0')
|
|
|
|
fatal("invalid name or number: %s\n", str);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void parse_pid(const char *str)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2009-09-24 06:56:16 +08:00
|
|
|
FILE *file;
|
|
|
|
char buf[5000];
|
|
|
|
|
2009-06-17 06:32:27 +08:00
|
|
|
opt_pid = parse_number(str);
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
sprintf(buf, "/proc/%d/pagemap", opt_pid);
|
2009-10-08 07:32:29 +08:00
|
|
|
pagemap_fd = checked_open(buf, O_RDONLY);
|
2009-09-24 06:56:16 +08:00
|
|
|
|
|
|
|
sprintf(buf, "/proc/%d/maps", opt_pid);
|
|
|
|
file = fopen(buf, "r");
|
|
|
|
if (!file) {
|
|
|
|
perror(buf);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), file) != NULL) {
|
|
|
|
unsigned long vm_start;
|
|
|
|
unsigned long vm_end;
|
|
|
|
unsigned long long pgoff;
|
|
|
|
int major, minor;
|
|
|
|
char r, w, x, s;
|
|
|
|
unsigned long ino;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = sscanf(buf, "%lx-%lx %c%c%c%c %llx %x:%x %lu",
|
|
|
|
&vm_start,
|
|
|
|
&vm_end,
|
|
|
|
&r, &w, &x, &s,
|
|
|
|
&pgoff,
|
|
|
|
&major, &minor,
|
|
|
|
&ino);
|
|
|
|
if (n < 10) {
|
|
|
|
fprintf(stderr, "unexpected line: %s\n", buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pg_start[nr_vmas] = vm_start / page_size;
|
|
|
|
pg_end[nr_vmas] = vm_end / page_size;
|
|
|
|
if (++nr_vmas >= MAX_VMAS) {
|
|
|
|
fprintf(stderr, "too many VMAs\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(file);
|
2009-06-17 06:32:27 +08:00
|
|
|
}
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
static void show_file(const char *name, const struct stat *st)
|
|
|
|
{
|
|
|
|
unsigned long long size = st->st_size;
|
|
|
|
char atime[64], mtime[64];
|
|
|
|
long now = time(NULL);
|
|
|
|
|
|
|
|
printf("%s\tInode: %u\tSize: %llu (%llu pages)\n",
|
|
|
|
name, (unsigned)st->st_ino,
|
|
|
|
size, (size + page_size - 1) / page_size);
|
|
|
|
|
|
|
|
strftime(atime, sizeof(atime), "%c", localtime(&st->st_atime));
|
|
|
|
strftime(mtime, sizeof(mtime), "%c", localtime(&st->st_mtime));
|
|
|
|
|
|
|
|
printf("Modify: %s (%ld seconds ago)\nAccess: %s (%ld seconds ago)\n",
|
|
|
|
mtime, now - st->st_mtime,
|
|
|
|
atime, now - st->st_atime);
|
|
|
|
}
|
|
|
|
|
2014-06-05 07:05:30 +08:00
|
|
|
static sigjmp_buf sigbus_jmp;
|
|
|
|
|
|
|
|
static void * volatile sigbus_addr;
|
|
|
|
|
|
|
|
static void sigbus_handler(int sig, siginfo_t *info, void *ucontex)
|
|
|
|
{
|
|
|
|
(void)sig;
|
|
|
|
(void)ucontex;
|
|
|
|
sigbus_addr = info ? info->si_addr : NULL;
|
|
|
|
siglongjmp(sigbus_jmp, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sigaction sigbus_action = {
|
|
|
|
.sa_sigaction = sigbus_handler,
|
|
|
|
.sa_flags = SA_SIGINFO,
|
|
|
|
};
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
static void walk_file(const char *name, const struct stat *st)
|
|
|
|
{
|
|
|
|
uint8_t vec[PAGEMAP_BATCH];
|
|
|
|
uint64_t buf[PAGEMAP_BATCH], flags;
|
2016-03-18 05:18:18 +08:00
|
|
|
uint64_t cgroup = 0;
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
unsigned long nr_pages, pfn, i;
|
2014-06-05 07:05:30 +08:00
|
|
|
off_t off, end = st->st_size;
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
int fd;
|
|
|
|
ssize_t len;
|
|
|
|
void *ptr;
|
|
|
|
int first = 1;
|
|
|
|
|
|
|
|
fd = checked_open(name, O_RDONLY|O_NOATIME|O_NOFOLLOW);
|
|
|
|
|
2014-06-05 07:05:30 +08:00
|
|
|
for (off = 0; off < end; off += len) {
|
|
|
|
nr_pages = (end - off + page_size - 1) / page_size;
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (nr_pages > PAGEMAP_BATCH)
|
|
|
|
nr_pages = PAGEMAP_BATCH;
|
|
|
|
len = nr_pages * page_size;
|
|
|
|
|
|
|
|
ptr = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, off);
|
|
|
|
if (ptr == MAP_FAILED)
|
|
|
|
fatal("mmap failed: %s", name);
|
|
|
|
|
|
|
|
/* determine cached pages */
|
|
|
|
if (mincore(ptr, len, vec))
|
|
|
|
fatal("mincore failed: %s", name);
|
|
|
|
|
|
|
|
/* turn off readahead */
|
|
|
|
if (madvise(ptr, len, MADV_RANDOM))
|
|
|
|
fatal("madvice failed: %s", name);
|
|
|
|
|
2014-06-05 07:05:30 +08:00
|
|
|
if (sigsetjmp(sigbus_jmp, 1)) {
|
|
|
|
end = off + sigbus_addr ? sigbus_addr - ptr : 0;
|
|
|
|
fprintf(stderr, "got sigbus at offset %lld: %s\n",
|
|
|
|
(long long)end, name);
|
|
|
|
goto got_sigbus;
|
|
|
|
}
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
/* populate ptes */
|
|
|
|
for (i = 0; i < nr_pages ; i++) {
|
|
|
|
if (vec[i] & 1)
|
|
|
|
(void)*(volatile int *)(ptr + i * page_size);
|
|
|
|
}
|
2014-06-05 07:05:30 +08:00
|
|
|
got_sigbus:
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
|
|
|
|
/* turn off harvesting reference bits */
|
|
|
|
if (madvise(ptr, len, MADV_SEQUENTIAL))
|
|
|
|
fatal("madvice failed: %s", name);
|
|
|
|
|
|
|
|
if (pagemap_read(buf, (unsigned long)ptr / page_size,
|
|
|
|
nr_pages) != nr_pages)
|
|
|
|
fatal("cannot read pagemap");
|
|
|
|
|
|
|
|
munmap(ptr, len);
|
|
|
|
|
|
|
|
for (i = 0; i < nr_pages; i++) {
|
|
|
|
pfn = pagemap_pfn(buf[i]);
|
|
|
|
if (!pfn)
|
|
|
|
continue;
|
|
|
|
if (!kpageflags_read(&flags, pfn, 1))
|
|
|
|
continue;
|
2016-03-18 05:18:18 +08:00
|
|
|
if (!kpagecgroup_read(&cgroup, pfn, 1))
|
|
|
|
fatal("kpagecgroup_read failed");
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (first && opt_list) {
|
|
|
|
first = 0;
|
|
|
|
flush_page_range();
|
|
|
|
show_file(name, st);
|
|
|
|
}
|
2016-03-18 05:18:18 +08:00
|
|
|
add_page(off / page_size + i, pfn,
|
|
|
|
flags, cgroup, buf[i]);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int walk_tree(const char *name, const struct stat *st, int type, struct FTW *f)
|
|
|
|
{
|
|
|
|
(void)f;
|
|
|
|
switch (type) {
|
|
|
|
case FTW_F:
|
|
|
|
if (S_ISREG(st->st_mode))
|
|
|
|
walk_file(name, st);
|
|
|
|
break;
|
|
|
|
case FTW_DNR:
|
|
|
|
fprintf(stderr, "cannot read dir: %s\n", name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void walk_page_cache(void)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
kpageflags_fd = checked_open(opt_kpageflags, O_RDONLY);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
pagemap_fd = checked_open("/proc/self/pagemap", O_RDONLY);
|
2014-06-05 07:05:30 +08:00
|
|
|
sigaction(SIGBUS, &sigbus_action, NULL);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
|
|
|
|
if (stat(opt_file, &st))
|
|
|
|
fatal("stat failed: %s\n", opt_file);
|
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode)) {
|
|
|
|
walk_file(opt_file, &st);
|
|
|
|
} else if (S_ISDIR(st.st_mode)) {
|
|
|
|
/* do not follow symlinks and mountpoints */
|
|
|
|
if (nftw(opt_file, walk_tree, 64, FTW_MOUNT | FTW_PHYS) < 0)
|
|
|
|
fatal("nftw failed: %s\n", opt_file);
|
|
|
|
} else
|
|
|
|
fatal("unhandled file type: %s\n", opt_file);
|
|
|
|
|
|
|
|
close(kpageflags_fd);
|
|
|
|
close(pagemap_fd);
|
2014-06-05 07:05:30 +08:00
|
|
|
signal(SIGBUS, SIG_DFL);
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
}
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
static void parse_file(const char *name)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
opt_file = name;
|
2009-06-17 06:32:27 +08:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
static void parse_cgroup(const char *path)
|
|
|
|
{
|
|
|
|
if (path[0] == '@') {
|
|
|
|
opt_cgroup = parse_number(path + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(path, &st))
|
|
|
|
fatal("stat failed: %s: %m\n", path);
|
|
|
|
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
fatal("cgroup supposed to be a directory: %s\n", path);
|
|
|
|
|
|
|
|
opt_cgroup = st.st_ino;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void parse_addr_range(const char *optarg)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
unsigned long offset;
|
|
|
|
unsigned long size;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strchr(optarg, ',');
|
|
|
|
if (!p)
|
|
|
|
p = strchr(optarg, '+');
|
|
|
|
|
|
|
|
if (p == optarg) {
|
|
|
|
offset = 0;
|
|
|
|
size = parse_number(p + 1);
|
|
|
|
} else if (p) {
|
|
|
|
offset = parse_number(optarg);
|
|
|
|
if (p[1] == '\0')
|
|
|
|
size = ULONG_MAX;
|
|
|
|
else {
|
|
|
|
size = parse_number(p + 1);
|
|
|
|
if (*p == ',') {
|
|
|
|
if (size < offset)
|
|
|
|
fatal("invalid range: %lu,%lu\n",
|
|
|
|
offset, size);
|
|
|
|
size -= offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
offset = parse_number(optarg);
|
|
|
|
size = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_addr_range(offset, size);
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void add_bits_filter(uint64_t mask, uint64_t bits)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
if (nr_bit_filters >= MAX_BIT_FILTERS)
|
|
|
|
fatal("too much bit filters\n");
|
|
|
|
|
|
|
|
opt_mask[nr_bit_filters] = mask;
|
|
|
|
opt_bits[nr_bit_filters] = bits;
|
|
|
|
nr_bit_filters++;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static uint64_t parse_flag_name(const char *str, int len)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
2012-05-30 06:06:30 +08:00
|
|
|
size_t i;
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
if (!*str || !len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (len <= 8 && !strncmp(str, "compound", len))
|
|
|
|
return BITS_COMPOUND;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(page_flag_names); i++) {
|
|
|
|
if (!page_flag_names[i])
|
|
|
|
continue;
|
|
|
|
if (!strncmp(str, page_flag_names[i] + 2, len))
|
|
|
|
return 1ULL << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parse_number(str);
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static uint64_t parse_flag_names(const char *str, int all)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
const char *p = str;
|
|
|
|
uint64_t flags = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (*p == ',' || *p == '=' || *p == '\0') {
|
|
|
|
if ((*str != '~') || (*str == '~' && all && *++str))
|
|
|
|
flags |= parse_flag_name(str, p - str);
|
|
|
|
if (*p != ',')
|
|
|
|
break;
|
|
|
|
str = p + 1;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-09-23 07:43:42 +08:00
|
|
|
static void parse_bits_mask(const char *optarg)
|
2009-06-17 06:32:27 +08:00
|
|
|
{
|
|
|
|
uint64_t mask;
|
|
|
|
uint64_t bits;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
p = strchr(optarg, '=');
|
|
|
|
if (p == optarg) {
|
|
|
|
mask = KPF_ALL_BITS;
|
|
|
|
bits = parse_flag_names(p + 1, 0);
|
|
|
|
} else if (p) {
|
|
|
|
mask = parse_flag_names(optarg, 0);
|
|
|
|
bits = parse_flag_names(p + 1, 0);
|
|
|
|
} else if (strchr(optarg, '~')) {
|
|
|
|
mask = parse_flag_names(optarg, 1);
|
|
|
|
bits = parse_flag_names(optarg, 0);
|
|
|
|
} else {
|
|
|
|
mask = parse_flag_names(optarg, 0);
|
|
|
|
bits = KPF_ALL_BITS;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_bits_filter(mask, bits);
|
|
|
|
}
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
static void parse_kpageflags(const char *name)
|
|
|
|
{
|
|
|
|
opt_kpageflags = name;
|
|
|
|
}
|
|
|
|
|
2009-12-15 09:57:52 +08:00
|
|
|
static void describe_flags(const char *optarg)
|
|
|
|
{
|
|
|
|
uint64_t flags = parse_flag_names(optarg, 0);
|
|
|
|
|
|
|
|
printf("0x%016llx\t%s\t%s\n",
|
|
|
|
(unsigned long long)flags,
|
|
|
|
page_flag_name(flags),
|
|
|
|
page_flag_longname(flags));
|
|
|
|
}
|
2009-06-17 06:32:27 +08:00
|
|
|
|
2009-12-15 09:57:48 +08:00
|
|
|
static const struct option opts[] = {
|
2009-06-17 06:32:27 +08:00
|
|
|
{ "raw" , 0, NULL, 'r' },
|
|
|
|
{ "pid" , 1, NULL, 'p' },
|
|
|
|
{ "file" , 1, NULL, 'f' },
|
|
|
|
{ "addr" , 1, NULL, 'a' },
|
|
|
|
{ "bits" , 1, NULL, 'b' },
|
2016-03-18 05:18:18 +08:00
|
|
|
{ "cgroup" , 1, NULL, 'c' },
|
2009-12-15 09:57:52 +08:00
|
|
|
{ "describe" , 1, NULL, 'd' },
|
2009-06-17 06:32:27 +08:00
|
|
|
{ "list" , 0, NULL, 'l' },
|
|
|
|
{ "list-each" , 0, NULL, 'L' },
|
2016-03-18 05:18:18 +08:00
|
|
|
{ "list-cgroup", 0, NULL, 'C' },
|
2009-06-17 06:32:27 +08:00
|
|
|
{ "no-summary", 0, NULL, 'N' },
|
2009-10-08 07:32:32 +08:00
|
|
|
{ "hwpoison" , 0, NULL, 'X' },
|
|
|
|
{ "unpoison" , 0, NULL, 'x' },
|
2018-02-01 08:21:23 +08:00
|
|
|
{ "kpageflags", 0, NULL, 'F' },
|
2009-06-17 06:32:27 +08:00
|
|
|
{ "help" , 0, NULL, 'h' },
|
|
|
|
{ NULL , 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
page_size = getpagesize();
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv,
|
2018-02-01 08:21:23 +08:00
|
|
|
"rp:f:a:b:d:c:ClLNXxF:h", opts, NULL)) != -1) {
|
2009-06-17 06:32:27 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'r':
|
|
|
|
opt_raw = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
parse_pid(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
parse_file(optarg);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
parse_addr_range(optarg);
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
parse_bits_mask(optarg);
|
|
|
|
break;
|
2016-03-18 05:18:18 +08:00
|
|
|
case 'c':
|
|
|
|
parse_cgroup(optarg);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
opt_list_cgroup = 1;
|
|
|
|
break;
|
2009-12-15 09:57:52 +08:00
|
|
|
case 'd':
|
|
|
|
describe_flags(optarg);
|
2009-12-15 09:57:54 +08:00
|
|
|
exit(0);
|
2009-06-17 06:32:27 +08:00
|
|
|
case 'l':
|
|
|
|
opt_list = 1;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
opt_list = 2;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
opt_no_summary = 1;
|
|
|
|
break;
|
2009-10-08 07:32:32 +08:00
|
|
|
case 'X':
|
|
|
|
opt_hwpoison = 1;
|
|
|
|
prepare_hwpoison_fd();
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
opt_unpoison = 1;
|
|
|
|
prepare_hwpoison_fd();
|
|
|
|
break;
|
2018-02-01 08:21:23 +08:00
|
|
|
case 'F':
|
|
|
|
parse_kpageflags(optarg);
|
|
|
|
break;
|
2009-06-17 06:32:27 +08:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 08:21:23 +08:00
|
|
|
if (!opt_kpageflags)
|
|
|
|
opt_kpageflags = PROC_KPAGEFLAGS;
|
|
|
|
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_cgroup || opt_list_cgroup)
|
|
|
|
kpagecgroup_fd = checked_open(PROC_KPAGECGROUP, O_RDONLY);
|
|
|
|
|
2009-09-24 06:56:16 +08:00
|
|
|
if (opt_list && opt_pid)
|
|
|
|
printf("voffset\t");
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (opt_list && opt_file)
|
|
|
|
printf("foffset\t");
|
2016-03-18 05:18:18 +08:00
|
|
|
if (opt_list && opt_list_cgroup)
|
|
|
|
printf("cgroup\t");
|
2009-06-17 06:32:27 +08:00
|
|
|
if (opt_list == 1)
|
2009-09-24 06:56:16 +08:00
|
|
|
printf("offset\tlen\tflags\n");
|
2009-06-17 06:32:27 +08:00
|
|
|
if (opt_list == 2)
|
|
|
|
printf("offset\tflags\n");
|
|
|
|
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
if (opt_file)
|
|
|
|
walk_page_cache();
|
|
|
|
else
|
|
|
|
walk_addr_ranges();
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
if (opt_list == 1)
|
tools/vm/page-types.c: page-cache sniffing feature
After this patch 'page-types' can walk over a file's mappings and
analyze populated page cache pages mostly without disturbing its state.
It maps chunk of file, marks VMA as MADV_RANDOM to turn off readahead,
pokes VMA via mincore() to determine cached pages, triggers page-fault
only for them, and finally gathers information via pagemap/kpageflags.
Before unmap it marks VMA as MADV_SEQUENTIAL for ignoring reference
bits.
usage: page-types -f <path>
If <path> is directory it will analyse all files in all subdirectories.
Symlinks are not followed as well as mount points. Hardlinks aren't
handled, they'll be dumped as many times as they are found. Recursive
walk brings all dentries into dcache and populates page cache of
block-devices aka 'Buffers'.
Probably it's worth to add ioctl for dumping file page cache as array of
PFNs as a replacement for this hackish juggling with
mmap/madvise/mincore/pagemap. Also recursive walk could be replaced
with dumping cached inodes via some ioctl or debugfs interface followed
by openning them via open_by_handle_at, this would fix hardlinks
handling and unneeded population of dcache and buffers. This interface
might be used as data source for constructing readahead plans and for
background optimizations of actively used files.
collateral changes:
+ fix 64-bit LFS: define _FILE_OFFSET_BITS instead of _LARGEFILE64_SOURCE
+ replace lseek + read with single pread
+ make show_page_range() reusable after flush
usage example:
~/src/linux/tools/vm$ sudo ./page-types -L -f page-types
foffset offset flags
page-types Inode: 2229277 Size: 89065 (22 pages)
Modify: Tue Feb 25 12:00:59 2014 (162 seconds ago)
Access: Tue Feb 25 12:01:00 2014 (161 seconds ago)
0 3cbf3b __RU_lA____M________________________
1 38946a __RU_lA____M________________________
2 1a3cec __RU_lA____M________________________
3 1a8321 __RU_lA____M________________________
4 3af7cc __RU_lA____M________________________
5 1ed532 __RU_lA_____________________________
6 2e436a __RU_lA_____________________________
7 29a35e ___U_lA_____________________________
8 2de86e ___U_lA_____________________________
9 3bdfb4 ___U_lA_____________________________
10 3cd8a3 ___U_lA_____________________________
11 2afa50 ___U_lA_____________________________
12 2534c2 ___U_lA_____________________________
13 1b7a40 ___U_lA_____________________________
14 17b0be ___U_lA_____________________________
15 392b0c ___U_lA_____________________________
16 3ba46a __RU_lA_____________________________
17 397dc8 ___U_lA_____________________________
18 1f2a36 ___U_lA_____________________________
19 21fd30 __RU_lA_____________________________
20 2c35ba __RU_l______________________________
21 20f181 __RU_l______________________________
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 2 0 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 11 0 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 4 0 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000086c 5 0 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 22 0
~/src/linux/tools/vm$ sudo ./page-types -f /
flags page-count MB symbolic-flags long-symbolic-flags
0x0000000000000028 21761 85 ___U_l______________________________ uptodate,lru
0x000000000000002c 127279 497 __RU_l______________________________ referenced,uptodate,lru
0x0000000000000068 74160 289 ___U_lA_____________________________ uptodate,lru,active
0x000000000000006c 84469 329 __RU_lA_____________________________ referenced,uptodate,lru,active
0x000000000000007c 1 0 __RUDlA_____________________________ referenced,uptodate,dirty,lru,active
0x0000000000000228 370 1 ___U_l___I__________________________ uptodate,lru,reclaim
0x0000000000000828 49 0 ___U_l_____M________________________ uptodate,lru,mmap
0x000000000000082c 126 0 __RU_l_____M________________________ referenced,uptodate,lru,mmap
0x0000000000000868 137 0 ___U_lA____M________________________ uptodate,lru,active,mmap
0x000000000000086c 12890 50 __RU_lA____M________________________ referenced,uptodate,lru,active,mmap
total 321242 1254
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-04-08 06:37:15 +08:00
|
|
|
flush_page_range();
|
2009-06-17 06:32:27 +08:00
|
|
|
|
|
|
|
if (opt_no_summary)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (opt_list)
|
|
|
|
printf("\n\n");
|
|
|
|
|
|
|
|
show_summary();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|