linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/3] tools/vm/page-types.c: a few improvements
@ 2021-10-04  6:13 Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option Naoya Horiguchi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Naoya Horiguchi @ 2021-10-04  6:13 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Konstantin Khlebnikov, Christian Hansen,
	Changbin Du, Bin Wang, Naoya Horiguchi, linux-kernel

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(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option
  2021-10-04  6:13 [PATCH v1 0/3] tools/vm/page-types.c: a few improvements Naoya Horiguchi
@ 2021-10-04  6:13 ` Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 2/3] tools/vm/page-types.c: move show_file() to summary output Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 3/3] tools/vm/page-types.c: print file offset in hexadecimal Naoya Horiguchi
  2 siblings, 0 replies; 4+ messages in thread
From: Naoya Horiguchi @ 2021-10-04  6:13 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Konstantin Khlebnikov, Christian Hansen,
	Changbin Du, Bin Wang, Naoya Horiguchi, linux-kernel

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

-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.

Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
---
 tools/vm/page-types.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git v5.15-rc3/tools/vm/page-types.c v5.15-rc3_patched/tools/vm/page-types.c
index f62f10c988db..b14376af1f16 100644
--- v5.15-rc3/tools/vm/page-types.c
+++ v5.15-rc3_patched/tools/vm/page-types.c
@@ -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);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/3] tools/vm/page-types.c: move show_file() to summary output
  2021-10-04  6:13 [PATCH v1 0/3] tools/vm/page-types.c: a few improvements Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option Naoya Horiguchi
@ 2021-10-04  6:13 ` Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 3/3] tools/vm/page-types.c: print file offset in hexadecimal Naoya Horiguchi
  2 siblings, 0 replies; 4+ messages in thread
From: Naoya Horiguchi @ 2021-10-04  6:13 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Konstantin Khlebnikov, Christian Hansen,
	Changbin Du, Bin Wang, Naoya Horiguchi, linux-kernel

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

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,active
                 total               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

Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
---
 tools/vm/page-types.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git v5.15-rc3/tools/vm/page-types.c v5.15-rc3_patched/tools/vm/page-types.c
index b14376af1f16..fdb1891faf90 100644
--- v5.15-rc3/tools/vm/page-types.c
+++ v5.15-rc3_patched/tools/vm/page-types.c
@@ -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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 3/3] tools/vm/page-types.c: print file offset in hexadecimal
  2021-10-04  6:13 [PATCH v1 0/3] tools/vm/page-types.c: a few improvements Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option Naoya Horiguchi
  2021-10-04  6:13 ` [PATCH v1 2/3] tools/vm/page-types.c: move show_file() to summary output Naoya Horiguchi
@ 2021-10-04  6:13 ` Naoya Horiguchi
  2 siblings, 0 replies; 4+ messages in thread
From: Naoya Horiguchi @ 2021-10-04  6:13 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, Konstantin Khlebnikov, Christian Hansen,
	Changbin Du, Bin Wang, Naoya Horiguchi, linux-kernel

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

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.

Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
---
 tools/vm/page-types.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git v5.15-rc3/tools/vm/page-types.c v5.15-rc3_patched/tools/vm/page-types.c
index fdb1891faf90..b1ed76d9a979 100644
--- v5.15-rc3/tools/vm/page-types.c
+++ v5.15-rc3_patched/tools/vm/page-types.c
@@ -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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-04  6:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04  6:13 [PATCH v1 0/3] tools/vm/page-types.c: a few improvements Naoya Horiguchi
2021-10-04  6:13 ` [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option Naoya Horiguchi
2021-10-04  6:13 ` [PATCH v1 2/3] tools/vm/page-types.c: move show_file() to summary output Naoya Horiguchi
2021-10-04  6:13 ` [PATCH v1 3/3] tools/vm/page-types.c: print file offset in hexadecimal Naoya Horiguchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).