* [PATCH] tools: adding support for idle page tracking to tool
@ 2018-06-12 15:32 Christian Hansen
2018-06-19 22:39 ` Andrew Morton
2018-06-19 22:41 ` Andrew Morton
0 siblings, 2 replies; 6+ messages in thread
From: Christian Hansen @ 2018-06-12 15:32 UTC (permalink / raw)
To: akpm; +Cc: xe-linux-external, linux-kernel, Christian Hansen
Adding a flag which will use the kernels's idle
page tracking to mark pages idle. As the tool already
prints the idle flag if set, subsequent runs will show
which pages have been accessed since last run.
Signed-off-by: Christian Hansen <chansen3@cisco.com>
---
tools/vm/page-types.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index a8783f4..1a4f70d 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -77,6 +77,8 @@
#define PROC_KPAGEFLAGS "/proc/kpageflags"
#define PROC_KPAGECGROUP "/proc/kpagecgroup"
+#define SYS_KERNEL_MM_PAGE_IDLE "/sys/kernel/mm/page_idle/bitmap"
+
/* [32-] kernel hacking assistances */
#define KPF_RESERVED 32
#define KPF_MLOCKED 33
@@ -167,6 +169,7 @@ static const char * const debugfs_known_mountpoints[] = {
static int opt_raw; /* for kernel developers */
static int opt_list; /* list pages (in ranges) */
+static int opt_mark_idle; /* set accessed bit */
static int opt_no_summary; /* don't show summary */
static pid_t opt_pid; /* process to walk */
const char *opt_file; /* file or directory path */
@@ -194,6 +197,7 @@ static int page_size;
static int pagemap_fd;
static int kpageflags_fd;
static int kpagecgroup_fd = -1;
+static int page_idle_fd = -1;
static int opt_hwpoison;
static int opt_unpoison;
@@ -566,6 +570,30 @@ static int unpoison_page(unsigned long offset)
return 0;
}
+static int mark_page_idle(unsigned long offset)
+{
+ static unsigned long off;
+ static uint64_t buf;
+ int len;
+
+ if ((offset / 64 == off / 64) || buf == 0) {
+ buf |= 1UL << (offset % 64);
+ off = offset;
+ return 0;
+ }
+
+ len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
+ if (len < 0) {
+ perror("mark page idle");
+ return len;
+ }
+
+ buf = 1UL << (offset % 64);
+ off = offset;
+
+ return 0;
+}
+
/*
* page frame walker
*/
@@ -613,6 +641,9 @@ static void add_page(unsigned long voffset, unsigned long offset,
if (opt_unpoison)
unpoison_page(offset);
+ if (opt_mark_idle)
+ mark_page_idle(offset);
+
if (opt_list == 1)
show_page_range(voffset, offset, 1, flags, cgroup);
else if (opt_list == 2)
@@ -755,6 +786,9 @@ static void walk_addr_ranges(void)
else
walk_task(opt_offset[i], opt_size[i]);
+ if (opt_mark_idle)
+ mark_page_idle(0);
+
close(kpageflags_fd);
}
@@ -785,6 +819,7 @@ static void usage(void)
" -c|--cgroup path|@inode Walk pages within memory cgroup\n"
" -p|--pid pid Walk process address space\n"
" -f|--file filename Walk file address space\n"
+" -i|--mark-idle Mark pages idle\n"
" -l|--list Show page details in ranges\n"
" -L|--list-each Show page details one by one\n"
" -C|--list-cgroup Show cgroup inode for pages\n"
@@ -1189,6 +1224,7 @@ static const struct option opts[] = {
{ "bits" , 1, NULL, 'b' },
{ "cgroup" , 1, NULL, 'c' },
{ "describe" , 1, NULL, 'd' },
+ { "mark-idle" , 0, NULL, 'i' },
{ "list" , 0, NULL, 'l' },
{ "list-each" , 0, NULL, 'L' },
{ "list-cgroup", 0, NULL, 'C' },
@@ -1207,7 +1243,7 @@ int main(int argc, char *argv[])
page_size = getpagesize();
while ((c = getopt_long(argc, argv,
- "rp:f:a:b:d:c:ClLNXxF:h", opts, NULL)) != -1) {
+ "rp:f:a:b:d:c:CilLNXxF:h", opts, NULL)) != -1) {
switch (c) {
case 'r':
opt_raw = 1;
@@ -1233,6 +1269,9 @@ int main(int argc, char *argv[])
case 'd':
describe_flags(optarg);
exit(0);
+ case 'i':
+ opt_mark_idle = 1;
+ break;
case 'l':
opt_list = 1;
break;
@@ -1268,6 +1307,9 @@ int main(int argc, char *argv[])
if (opt_cgroup || opt_list_cgroup)
kpagecgroup_fd = checked_open(PROC_KPAGECGROUP, O_RDONLY);
+ if (opt_mark_idle && opt_file)
+ page_idle_fd = checked_open(SYS_KERNEL_MM_PAGE_IDLE, O_RDWR);
+
if (opt_list && opt_pid)
printf("voffset\t");
if (opt_list && opt_file)
@@ -1295,5 +1337,8 @@ int main(int argc, char *argv[])
show_summary();
+ if (page_idle_fd >= 0)
+ close(page_idle_fd);
+
return 0;
}
--
2.10.3.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] tools: adding support for idle page tracking to tool
2018-06-12 15:32 [PATCH] tools: adding support for idle page tracking to tool Christian Hansen
@ 2018-06-19 22:39 ` Andrew Morton
2018-07-05 18:14 ` Christian Hansen (chansen3)
2018-06-19 22:41 ` Andrew Morton
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2018-06-19 22:39 UTC (permalink / raw)
To: Christian Hansen; +Cc: xe-linux-external, linux-kernel
On Tue, 12 Jun 2018 11:32:23 -0400 Christian Hansen <chansen3@cisco.com> wrote:
> Adding a flag which will use the kernels's idle
> page tracking to mark pages idle. As the tool already
> prints the idle flag if set, subsequent runs will show
> which pages have been accessed since last run.
That sounds useful.
This patch seems to have been prepared against the mainline kernel, so
it conflicts with your "tools: modifying page-types to include shared
map counts" patch. Awkward, but I seem to have got it fixed up.
> ...
>
> @@ -566,6 +570,30 @@ static int unpoison_page(unsigned long offset)
> return 0;
> }
>
> +static int mark_page_idle(unsigned long offset)
> +{
> + static unsigned long off;
> + static uint64_t buf;
> + int len;
> +
> + if ((offset / 64 == off / 64) || buf == 0) {
> + buf |= 1UL << (offset % 64);
> + off = offset;
> + return 0;
> + }
> +
> + len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
> + if (len < 0) {
> + perror("mark page idle");
> + return len;
> + }
> +
> + buf = 1UL << (offset % 64);
> + off = offset;
> +
> + return 0;
> +}
This is a bit cumbersome. Why not this way:
static int mark_page_idle(unsigned long offset)
{
static unsigned long off;
static uint64_t buf;
int len;
if ((offset / 64 != off / 64) && buf != 0) {
len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
if (len < 0) {
perror("mark page idle");
return len;
}
}
buf = 1UL << (offset % 64);
off = offset;
return 0;
}
Also, it's not very clear what's going on here - the handling of
offset, off and buf. Some well-crafted comments would help.
>
> ...
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools: adding support for idle page tracking to tool
2018-06-12 15:32 [PATCH] tools: adding support for idle page tracking to tool Christian Hansen
2018-06-19 22:39 ` Andrew Morton
@ 2018-06-19 22:41 ` Andrew Morton
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2018-06-19 22:41 UTC (permalink / raw)
To: Christian Hansen; +Cc: xe-linux-external, linux-kernel
On Tue, 12 Jun 2018 11:32:23 -0400 Christian Hansen <chansen3@cisco.com> wrote:
> Adding a flag which will use the kernels's idle
> page tracking to mark pages idle. As the tool already
> prints the idle flag if set, subsequent runs will show
> which pages have been accessed since last run.
Also, it would be appropriate to document this new feature in
Documentation/admin-guide/mm/idle_page_tracking.rst.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] tools: adding support for idle page tracking to tool
2018-06-19 22:39 ` Andrew Morton
@ 2018-07-05 18:14 ` Christian Hansen (chansen3)
0 siblings, 0 replies; 6+ messages in thread
From: Christian Hansen (chansen3) @ 2018-07-05 18:14 UTC (permalink / raw)
To: Andrew Morton; +Cc: xe-linux-external(mailer list), linux-kernel
Yes, I wasn't sure which one went in first. I can make this one dependent on the other.
On 2018-06-19, 6:39 PM, "Andrew Morton" <akpm@linux-foundation.org> wrote:
On Tue, 12 Jun 2018 11:32:23 -0400 Christian Hansen <chansen3@cisco.com> wrote:
> Adding a flag which will use the kernels's idle
> page tracking to mark pages idle. As the tool already
> prints the idle flag if set, subsequent runs will show
> which pages have been accessed since last run.
That sounds useful.
This patch seems to have been prepared against the mainline kernel, so
it conflicts with your "tools: modifying page-types to include shared
map counts" patch. Awkward, but I seem to have got it fixed up.
> ...
>
> @@ -566,6 +570,30 @@ static int unpoison_page(unsigned long offset)
> return 0;
> }
>
> +static int mark_page_idle(unsigned long offset)
> +{
> + static unsigned long off;
> + static uint64_t buf;
> + int len;
> +
> + if ((offset / 64 == off / 64) || buf == 0) {
> + buf |= 1UL << (offset % 64);
> + off = offset;
> + return 0;
> + }
> +
> + len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
> + if (len < 0) {
> + perror("mark page idle");
> + return len;
> + }
> +
> + buf = 1UL << (offset % 64);
> + off = offset;
> +
> + return 0;
> +}
This is a bit cumbersome. Why not this way:
static int mark_page_idle(unsigned long offset)
{
static unsigned long off;
static uint64_t buf;
int len;
if ((offset / 64 != off / 64) && buf != 0) {
len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
if (len < 0) {
perror("mark page idle");
return len;
}
}
buf = 1UL << (offset % 64);
off = offset;
return 0;
}
Also, it's not very clear what's going on here - the handling of
offset, off and buf. Some well-crafted comments would help.
>
> ...
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] tools: adding support for idle page tracking to tool
@ 2018-07-06 17:22 Christian Hansen
0 siblings, 0 replies; 6+ messages in thread
From: Christian Hansen @ 2018-07-06 17:22 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, Christian Hansen
Adding a new flag which will use the kernels's idle
page tracking to mark pages idle. As the tool already
prints the idle flag if set, subsequent runs will show
which pages have been accessed since last run.
Signed-off-by: Christian Hansen <chansen3@cisco.com>
---
.../admin-guide/mm/idle_page_tracking.rst | 5 +++
tools/vm/page-types.c | 47 +++++++++++++++++++++-
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/mm/idle_page_tracking.rst b/Documentation/admin-guide/mm/idle_page_tracking.rst
index 6f7b7ca..df9394f 100644
--- a/Documentation/admin-guide/mm/idle_page_tracking.rst
+++ b/Documentation/admin-guide/mm/idle_page_tracking.rst
@@ -65,6 +65,11 @@ workload one should:
are not reclaimable, he or she can filter them out using
``/proc/kpageflags``.
+The page-types tool in the tools/vm directory can be used to assist in this.
+If the tool is run initially with the appropriate option, it will mark all the
+queried pages as idle. Subsequent runs of the tool can then show which pages have
+their idle flag cleared in the interim.
+
See :ref:`Documentation/admin-guide/mm/pagemap.rst <pagemap>` for more
information about ``/proc/pid/pagemap``, ``/proc/kpageflags``, and
``/proc/kpagecgroup``.
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index 7fe4797..6394eca 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -78,6 +78,8 @@
#define PROC_KPAGECOUNT "/proc/kpagecount"
#define PROC_KPAGECGROUP "/proc/kpagecgroup"
+#define SYS_KERNEL_MM_PAGE_IDLE "/sys/kernel/mm/page_idle/bitmap"
+
/* [32-] kernel hacking assistances */
#define KPF_RESERVED 32
#define KPF_MLOCKED 33
@@ -169,6 +171,7 @@ static const char * const debugfs_known_mountpoints[] = {
static int opt_raw; /* for kernel developers */
static int opt_list; /* list pages (in ranges) */
+static int opt_mark_idle; /* set accessed bit */
static int opt_no_summary; /* don't show summary */
static pid_t opt_pid; /* process to walk */
const char *opt_file; /* file or directory path */
@@ -198,6 +201,7 @@ static int pagemap_fd;
static int kpageflags_fd;
static int kpagecount_fd = -1;
static int kpagecgroup_fd = -1;
+static int page_idle_fd = -1;
static int opt_hwpoison;
static int opt_unpoison;
@@ -587,6 +591,30 @@ static int unpoison_page(unsigned long offset)
return 0;
}
+static int mark_page_idle(unsigned long offset)
+{
+ static unsigned long off;
+ static uint64_t buf;
+ int len;
+
+ if ((offset / 64 == off / 64) || buf == 0) {
+ buf |= 1UL << (offset % 64);
+ off = offset;
+ return 0;
+ }
+
+ len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
+ if (len < 0) {
+ perror("mark page idle");
+ return len;
+ }
+
+ buf = 1UL << (offset % 64);
+ off = offset;
+
+ return 0;
+}
+
/*
* page frame walker
*/
@@ -635,6 +663,9 @@ static void add_page(unsigned long voffset, unsigned long offset,
if (opt_unpoison)
unpoison_page(offset);
+ if (opt_mark_idle)
+ mark_page_idle(offset);
+
if (opt_list == 1)
show_page_range(voffset, offset, 1, flags, cgroup, mapcnt);
else if (opt_list == 2)
@@ -783,6 +814,9 @@ static void walk_addr_ranges(void)
else
walk_task(opt_offset[i], opt_size[i]);
+ if (opt_mark_idle)
+ mark_page_idle(0);
+
close(kpageflags_fd);
}
@@ -813,6 +847,7 @@ static void usage(void)
" -c|--cgroup path|@inode Walk pages within memory cgroup\n"
" -p|--pid pid Walk process address space\n"
" -f|--file filename Walk file address space\n"
+" -i|--mark-idle Mark pages idle\n"
" -l|--list Show page details in ranges\n"
" -L|--list-each Show page details one by one\n"
" -C|--list-cgroup Show cgroup inode for pages\n"
@@ -1221,6 +1256,7 @@ static const struct option opts[] = {
{ "bits" , 1, NULL, 'b' },
{ "cgroup" , 1, NULL, 'c' },
{ "describe" , 1, NULL, 'd' },
+ { "mark-idle" , 0, NULL, 'i' },
{ "list" , 0, NULL, 'l' },
{ "list-each" , 0, NULL, 'L' },
{ "list-cgroup", 0, NULL, 'C' },
@@ -1240,7 +1276,7 @@ int main(int argc, char *argv[])
page_size = getpagesize();
while ((c = getopt_long(argc, argv,
- "rp:f:a:b:d:c:ClLMNXxF:h",
+ "rp:f:a:b:d:c:CilLMNXxF:h",
opts, NULL)) != -1) {
switch (c) {
case 'r':
@@ -1267,6 +1303,9 @@ int main(int argc, char *argv[])
case 'd':
describe_flags(optarg);
exit(0);
+ case 'i':
+ opt_mark_idle = 1;
+ break;
case 'l':
opt_list = 1;
break;
@@ -1308,6 +1347,9 @@ int main(int argc, char *argv[])
if (opt_list && opt_list_mapcnt)
kpagecount_fd = checked_open(PROC_KPAGECOUNT, O_RDONLY);
+ if (opt_mark_idle && opt_file)
+ page_idle_fd = checked_open(SYS_KERNEL_MM_PAGE_IDLE, O_RDWR);
+
if (opt_list && opt_pid)
printf("voffset\t");
if (opt_list && opt_file)
@@ -1341,5 +1383,8 @@ int main(int argc, char *argv[])
if (opt_list_mapcnt)
close(kpagecount_fd);
+ if (page_idle_fd >= 0)
+ close(page_idle_fd);
+
return 0;
}
--
2.10.3.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] tools: adding support for idle page tracking to tool
@ 2018-06-01 15:18 Christian Hansen
0 siblings, 0 replies; 6+ messages in thread
From: Christian Hansen @ 2018-06-01 15:18 UTC (permalink / raw)
To: linux-kernel; +Cc: xe-linux-external, Christian Hansen
Adding a -i flag which will use the kernels's idle
page tracking to mark pages idle. As the tool already
prints the idle flag if set, subsequent runs will show
which pages have been accessed since last run.
Signed-off-by: Christian Hansen <chansen3@cisco.com>
---
tools/vm/page-types.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index a8783f4..1a4f70d 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -77,6 +77,8 @@
#define PROC_KPAGEFLAGS "/proc/kpageflags"
#define PROC_KPAGECGROUP "/proc/kpagecgroup"
+#define SYS_KERNEL_MM_PAGE_IDLE "/sys/kernel/mm/page_idle/bitmap"
+
/* [32-] kernel hacking assistances */
#define KPF_RESERVED 32
#define KPF_MLOCKED 33
@@ -167,6 +169,7 @@ static const char * const debugfs_known_mountpoints[] = {
static int opt_raw; /* for kernel developers */
static int opt_list; /* list pages (in ranges) */
+static int opt_mark_idle; /* set accessed bit */
static int opt_no_summary; /* don't show summary */
static pid_t opt_pid; /* process to walk */
const char *opt_file; /* file or directory path */
@@ -194,6 +197,7 @@ static int page_size;
static int pagemap_fd;
static int kpageflags_fd;
static int kpagecgroup_fd = -1;
+static int page_idle_fd = -1;
static int opt_hwpoison;
static int opt_unpoison;
@@ -566,6 +570,30 @@ static int unpoison_page(unsigned long offset)
return 0;
}
+static int mark_page_idle(unsigned long offset)
+{
+ static unsigned long off;
+ static uint64_t buf;
+ int len;
+
+ if ((offset / 64 == off / 64) || buf == 0) {
+ buf |= 1UL << (offset % 64);
+ off = offset;
+ return 0;
+ }
+
+ len = pwrite(page_idle_fd, &buf, 8, 8 * (off / 64));
+ if (len < 0) {
+ perror("mark page idle");
+ return len;
+ }
+
+ buf = 1UL << (offset % 64);
+ off = offset;
+
+ return 0;
+}
+
/*
* page frame walker
*/
@@ -613,6 +641,9 @@ static void add_page(unsigned long voffset, unsigned long offset,
if (opt_unpoison)
unpoison_page(offset);
+ if (opt_mark_idle)
+ mark_page_idle(offset);
+
if (opt_list == 1)
show_page_range(voffset, offset, 1, flags, cgroup);
else if (opt_list == 2)
@@ -755,6 +786,9 @@ static void walk_addr_ranges(void)
else
walk_task(opt_offset[i], opt_size[i]);
+ if (opt_mark_idle)
+ mark_page_idle(0);
+
close(kpageflags_fd);
}
@@ -785,6 +819,7 @@ static void usage(void)
" -c|--cgroup path|@inode Walk pages within memory cgroup\n"
" -p|--pid pid Walk process address space\n"
" -f|--file filename Walk file address space\n"
+" -i|--mark-idle Mark pages idle\n"
" -l|--list Show page details in ranges\n"
" -L|--list-each Show page details one by one\n"
" -C|--list-cgroup Show cgroup inode for pages\n"
@@ -1189,6 +1224,7 @@ static const struct option opts[] = {
{ "bits" , 1, NULL, 'b' },
{ "cgroup" , 1, NULL, 'c' },
{ "describe" , 1, NULL, 'd' },
+ { "mark-idle" , 0, NULL, 'i' },
{ "list" , 0, NULL, 'l' },
{ "list-each" , 0, NULL, 'L' },
{ "list-cgroup", 0, NULL, 'C' },
@@ -1207,7 +1243,7 @@ int main(int argc, char *argv[])
page_size = getpagesize();
while ((c = getopt_long(argc, argv,
- "rp:f:a:b:d:c:ClLNXxF:h", opts, NULL)) != -1) {
+ "rp:f:a:b:d:c:CilLNXxF:h", opts, NULL)) != -1) {
switch (c) {
case 'r':
opt_raw = 1;
@@ -1233,6 +1269,9 @@ int main(int argc, char *argv[])
case 'd':
describe_flags(optarg);
exit(0);
+ case 'i':
+ opt_mark_idle = 1;
+ break;
case 'l':
opt_list = 1;
break;
@@ -1268,6 +1307,9 @@ int main(int argc, char *argv[])
if (opt_cgroup || opt_list_cgroup)
kpagecgroup_fd = checked_open(PROC_KPAGECGROUP, O_RDONLY);
+ if (opt_mark_idle && opt_file)
+ page_idle_fd = checked_open(SYS_KERNEL_MM_PAGE_IDLE, O_RDWR);
+
if (opt_list && opt_pid)
printf("voffset\t");
if (opt_list && opt_file)
@@ -1295,5 +1337,8 @@ int main(int argc, char *argv[])
show_summary();
+ if (page_idle_fd >= 0)
+ close(page_idle_fd);
+
return 0;
}
--
2.10.3.dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-07-06 17:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 15:32 [PATCH] tools: adding support for idle page tracking to tool Christian Hansen
2018-06-19 22:39 ` Andrew Morton
2018-07-05 18:14 ` Christian Hansen (chansen3)
2018-06-19 22:41 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2018-07-06 17:22 Christian Hansen
2018-06-01 15:18 Christian Hansen
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).