tools/vm/page-types.c: a few improvements
cover tools/vm/page-types.c: a few improvements
Hi,
This patchset adds some improvements on tools/vm/page-types.c. Patch 1/3 makes -a option (specify address range) work with -f (file cache mode). Patch 2/3 and 3/3 are to fix minor formatting issues of this tool. These would make life a little easier for the users of this tool.
Please see individual patches for more details about specific issues.
Thanks,
Naoya Horiguchi
---
Summary:
Naoya Horiguchi (3):
tools/vm/page-types.c: make walk_file() aware of address range option tools/vm/page-types.c: move show_file() to summary output tools/vm/page-types.c: print file offset in hexadecimal
tools/vm/page-types.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-)
PATCH 1/3 tools/vm/page-types.c: make walk_file() aware of address range option
From: Naoya Horiguchi <[email protected]>
-a|--addr option is used to limit the range of address to be scanned for page status. It works now for physical address space (dafult mode) or for virtual address space (with -p option), but not for file address space (with -f option). So make walk_file() aware of -a option.
--- tools/vm/page-types.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
tools/vm/page-types.c +18 -6
@@ -967,22 +967,19 @@ static struct sigaction sigbus_action = { .sa_flags = SA_SIGINFO, }; -static void walk_file (const char *name,const struct stat *st) +static void walk_file_range (const char *name,int fd, +unsigned long off,unsigned long end) {uint8_t vec[PAGEMAP_BATCH ];uint64_t buf[PAGEMAP_BATCH ], flags;uint64_t cgroup =0 ;uint64_t mapcnt =0 ;unsigned long nr_pages, pfn, i; -off_t off, end = st->st_size; -int fd;ssize_t len;void *ptr;int first =1 ; - fd =checked_open (name,O_RDONLY |O_NOATIME |O_NOFOLLOW ); - -for (off =0 ; off < end; off += len) { +for (; off < end; off += len) { nr_pages = (end - off + page_size -1 ) / page_size;if (nr_pages >PAGEMAP_BATCH ) nr_pages =PAGEMAP_BATCH ;
@@ -1043,6 +1040,21 @@ static void walk_file(const char *name, const struct stat *st) flags, cgroup, mapcnt, buf[i]); } } +} + +static void walk_file (const char *name,const struct stat *st) +{ +int i; +int fd; + + fd =checked_open (name,O_RDONLY |O_NOATIME |O_NOFOLLOW ); + +if (!nr_addr_ranges) +add_addr_range (0 , st->st_size / page_size); + +for (i =0 ; i < nr_addr_ranges; i++) +walk_file_range (name, fd, opt_offset[i] * page_size, + (opt_offset[i] + opt_size[i]) * page_size);close (fd); }
Signature · 1 line
2.25.1
PATCH 2/3 tools/vm/page-types.c: move show_file() to summary output
In reply to Naoya HoriguchiFrom: Naoya Horiguchi <[email protected]>
Currently file info from show_file() is printed out within page list like below, but this is inconvenient a little to utilize the page list from other scripts (maybe needs additional filtering).
$ ./page-types -f page-types.c -l
foffset offset len flags
page-types.c Inode: 15108680 Size: 30953 (8 pages)
Modify: Sat Oct 2 23:11:20 2021 (2399 seconds ago)
Access: Sat Oct 2 23:11:28 2021 (2391 seconds ago)
0 d9f59e 1 ___U_lA____________________________________
1 1031eb5 1 __RU_l_____________________________________
2 13bf717 1 __RU_l_____________________________________
3 13ac333 1 ___U_lA____________________________________
4 d9f59f 1 __RU_l_____________________________________
5 183fd49 1 ___U_lA____________________________________
6 13cbf69 1 ___U_lA____________________________________
7 d9ef05 1 ___U_lA____________________________________ flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 3 0 __RU_l_____________________________________ referenced,uptodate,lru
0x0000000000000068 5 0 ___U_lA____________________________________ uptodate,lru,activetotal 8 0
With this patch file info is printed out in summary part like below:
$ ./page-types -f page-types.c -l
foffset offset len flags
0 d9f59e 1 ___U_lA_____________________________________
1 1031eb5 1 __RU_l______________________________________
2 13bf717 1 __RU_l______________________________________
3 13ac333 1 ___U_lA_____________________________________
4 d9f59f 1 __RU_l______________________________________
5 183fd49 1 ___U_lA_____________________________________
6 13cbf69 1 ___U_lA_____________________________________ page-types.c Inode: 15108680 Size: 30953 (8 pages)
Modify: Sat Oct 2 23:11:20 2021 (2435 seconds ago)
Access: Sat Oct 2 23:11:28 2021 (2427 seconds ago)
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 3 0 __RU_l______________________________________ referenced,uptodate,lru
0x0000000000000068 4 0 ___U_lA_____________________________________ uptodate,lru,active
total 7 0--- tools/vm/page-types.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/vm/page-types.c +7 -3
@@ -1034,7 +1034,6 @@ static void walk_file_range(const char *name, int fd,if (first && opt_list) { first =0 ;flush_page_range (); -show_file (name, st); }add_page (off / page_size + i, pfn, flags, cgroup, mapcnt, buf[i]);
@@ -1074,10 +1073,10 @@ int walk_tree(const char *name, const struct stat *st, int type, struct FTW *f)return 0 ; } +struct stat st; +static void walk_page_cache (void ) { -struct stat st; - kpageflags_fd =checked_open (opt_kpageflags,O_RDONLY ); pagemap_fd =checked_open ("/proc/self/pagemap" ,O_RDONLY );sigaction (SIGBUS , &sigbus_action,NULL );
@@ -1374,6 +1373,11 @@ int main(int argc, char *argv[])if (opt_list)printf ("\n\n" ); +if (opt_file) { +show_file (opt_file, &st); +printf ("\n" ); + } +show_summary ();if (opt_list_mapcnt)
Signature · 1 line
2.25.1
PATCH 3/3 tools/vm/page-types.c: print file offset in hexadecimal
In reply to Naoya HoriguchiFrom: Naoya Horiguchi <[email protected]>
In page list mode (with -l and -L option), virtual address and physical address are printed in hexadecimal, but file offset is not, which is confusing, so let's align it.
--- tools/vm/page-types.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/vm/page-types.c +2 -2
@@ -390,7 +390,7 @@ static void show_page_range(unsigned long voffset, unsigned long offset,if (opt_pid)printf ("%lx\t" , voff);if (opt_file) -printf ("%lu\t" , voff); +printf ("%lx\t" , voff);if (opt_list_cgroup)printf ("@%llu\t" , (unsigned long long )cgroup0);if (opt_list_mapcnt)
@@ -418,7 +418,7 @@ static void show_page(unsigned long voffset, unsigned long offset,if (opt_pid)printf ("%lx\t" , voffset);if (opt_file) -printf ("%lu\t" , voffset); +printf ("%lx\t" , voffset);if (opt_list_cgroup)printf ("@%llu\t" , (unsigned long long )cgroup);if (opt_list_mapcnt)
Signature · 1 line
2.25.1