Skip to content

Commit

Permalink
tools/vm/page-types.c: make walk_file() aware of address range option
Browse files Browse the repository at this point in the history
Patch series "tools/vm/page-types.c: a few improvements".

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.

This patch (of 3):

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

Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Naoya Horiguchi <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Christian Hansen <[email protected]>
Cc: Changbin Du <[email protected]>
Cc: Bin Wang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
nhoriguchi authored and torvalds committed Nov 6, 2021
1 parent f7df2b1 commit a62f5ec
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tools/vm/page-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a62f5ec

Please sign in to comment.