From: Keiichi KII <k-keiichi@bx.jp.nec.com>
To: linux-kernel@vger.kernel.org
Cc: lwoodman@redhat.com, linux-mm@kvack.org, mingo@elte.hu,
tzanussi@gmail.com, riel@redhat.com, rostedt@goodmis.org,
akpm@linux-foundation.org, fweisbec@gmail.com,
Munehiro Ikeda <m-ikeda@ds.jp.nec.com>,
Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
Subject: [RFC PATCH -tip 2/2 v2] add a scripts for pagecache usage per process
Date: Fri, 22 Jan 2010 19:08:57 -0500 [thread overview]
Message-ID: <4B5A3E19.6060502@bx.jp.nec.com> (raw)
In-Reply-To: <4B5A3D00.8080901@bx.jp.nec.com>
The scripts are implemented based on the trace stream scripting support.
And the scripts implement the following.
- how many pagecaches each process has per each file
- how many pages are cached per each file
- how many pagecaches each process shares
To monitor pagecache usage per a process, run "pagecache-usage-record" to
record perf data for "pagecache-usage.pl" and run "pagecache-usage-report"
to display.
The below outputs show execution sample.
[file list]
device inode caches
--------------------------------
253:0 1051413 130
253:0 1051399 2
253:0 1051414 44
253:0 1051417 154
[process list]
o postmaster-2330
cached added removed indirect
device inode pages pages pages removed pages
----------------------------------------------------------------
253:0 1051399 0 2 0 0
253:0 1051417 154 0 0 0
253:0 1051413 130 0 0 0
253:0 1051414 44 0 0 0
----------------------------------------------------------------
total: 337 2 0 0
>From the output, we can know some information like:
- if "added pages" > "cached pages" on process list then
It means repeating add/remove pagecache many times.
=> Bad case for pagecache usage
- if "added pages" <= "cached pages" on process list then
It means no unnecessary I/O operations.
=> Good case for pagecache usage.
- if "caches" on file list >
sum "cached pages" per each file on process list then
It means there are unneccessary pagecaches in the memory.
=> Bad case for pagecache usage
Signed-off-by: Keiichi Kii <k-keiichi@bx.jp.nec.com>
Cc: Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
---
tools/perf/scripts/perl/bin/pagecache-usage-record | 7
tools/perf/scripts/perl/bin/pagecache-usage-report | 6
tools/perf/scripts/perl/pagecache-usage.pl | 160 +++++++++++++++++++++
3 files changed, 173 insertions(+)
Index: linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-record
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-record
@@ -0,0 +1,7 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e filemap:add_to_page_cache -e filemap:find_get_page -e filemap:remove_from_page_cache
+
+
+
+
+
Index: linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-report
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-report
@@ -0,0 +1,6 @@
+#!/bin/bash
+# description: pagecache usage per process
+perf trace -s ~/libexec/perf-core/scripts/perl/pagecache-usage.pl
+
+
+
Index: linux-2.6-tip/tools/perf/scripts/perl/pagecache-usage.pl
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/pagecache-usage.pl
@@ -0,0 +1,160 @@
+# perf trace event handlers, generated by perf trace -g perl
+# Licensed under the terms of the GNU GPL License version 2
+
+# The common_* event handler fields are the most useful fields common to
+# all events. They don't necessarily correspond to the 'common_*' fields
+# in the format files. Those fields not available as handler params can
+# be retrieved using Perl functions of the form common_*($context).
+# See Context.pm for the list of available functions.
+
+use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
+use lib "./Perf-Trace-Util/lib";
+use Perf::Trace::Core;
+use Perf::Trace::Context;
+use Perf::Trace::Util;
+use List::Util qw/sum/;
+my %files;
+my %processes;
+my %records;
+
+sub trace_end
+{
+ print_pagecache_usage_per_file();
+ print "\n";
+ print_pagecache_usage_per_process();
+ print_unhandled();
+}
+
+sub filemap::remove_from_page_cache
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ delete $$f{$offset};
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+ if (exists $$r{added}{$offset}) {
+ $$r{removed}++;
+ } else {
+ $$r{indirect_removed}++;
+ }
+}
+
+sub filemap::add_to_page_cache
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ $$f{$offset}++;
+ $$r{added}{$offset}++;
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+}
+
+sub filemap::find_get_page
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset, $page) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ if ($page != 0) {
+ $$f{$offset}++;
+ $$r{cached}++;
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+ }
+}
+
+my %unhandled;
+
+sub trace_unhandled
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm) = @_;
+
+ $unhandled{$event_name}++;
+}
+
+sub print_unhandled
+{
+ if ((scalar keys %unhandled) == 0) {
+ print "unhandled events nothing\n";
+ return;
+ }
+
+ print "\nunhandled events:\n\n";
+
+ printf("%-40s %10s\n", "event", "count");
+ printf("%-40s %10s\n", "----------------------------------------",
+ "-----------");
+
+ foreach my $event_name (keys %unhandled) {
+ printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
+ }
+}
+
+sub minor
+{
+ my $dev = shift;
+ return $dev & ((1 << 20) - 1);
+}
+
+sub major
+{
+ my $dev = shift;
+ return $dev >> 20;
+}
+
+sub print_pagecache_usage_per_file
+{
+ print "[file list]\n";
+ printf(" %12s %10s %8s\n", "", "", "cached");
+ printf(" %12s %10s %8s\n", "device", "inode", "pages");
+ printf(" %s\n", '-' x 32);
+ while(my($dev, $file) = each(%files)) {
+ while(my($inode, $r) = each(%$file)) {
+ my $count = values %$r;
+ next if $count == 0;
+ printf(" %12s %10d %8d\n",
+ major($dev).":".minor($dev), $inode, $count);
+ }
+ }
+}
+
+sub print_pagecache_usage_per_process
+{
+ print "[process list]\n";
+ while(my ($pid, $v) = each(%records)) {
+ my ($sum_cached, $sum_added, $sum_removed, $sum_indirect_removed);
+
+ print "o $pid\n";
+ printf(" %12s %10s %8s %8s %8s %13s\n", "", "",
+ "cached", "added", "removed", "indirect");
+ printf(" %12s %10s %8s %8s %8s %13s\n", "device", "inode",
+ "pages", "pages", "pages", "removed pages");
+ printf(" %s\n", '-' x 64);
+ while(my ($file, $r) = each(%$v)) {
+ my $added_num = List::Util::sum(values %{$$r{added}});
+ $sum_cached += $$r{cached};
+ $sum_added += $added_num;
+ $sum_removed += $$r{removed};
+ $sum_indirect_removed += $$r{indirect_removed};
+ printf(" %12s %10d %8d %8d %8d %13d\n",
+ major($$r{dev}).":".minor($$r{dev}), $$r{inode},
+ $$r{cached}, $added_num, $$r{removed},
+ $$r{indirect_removed});
+ }
+ printf(" %s\n", '-' x 64);
+ printf(" total: %5s %10s %8d %8d %8d %13d\n", "", "", $sum_cached,
+ $sum_added, $sum_removed, $sum_indirect_removed);
+ print "\n";
+ }
+}
WARNING: multiple messages have this Message-ID (diff)
From: Keiichi KII <k-keiichi@bx.jp.nec.com>
To: linux-kernel@vger.kernel.org
Cc: lwoodman@redhat.com, linux-mm@kvack.org, mingo@elte.hu,
tzanussi@gmail.com, riel@redhat.com, rostedt@goodmis.org,
akpm@linux-foundation.org, fweisbec@gmail.com,
Munehiro Ikeda <m-ikeda@ds.jp.nec.com>,
Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
Subject: [RFC PATCH -tip 2/2 v2] add a scripts for pagecache usage per process
Date: Fri, 22 Jan 2010 19:08:57 -0500 [thread overview]
Message-ID: <4B5A3E19.6060502@bx.jp.nec.com> (raw)
In-Reply-To: <4B5A3D00.8080901@bx.jp.nec.com>
The scripts are implemented based on the trace stream scripting support.
And the scripts implement the following.
- how many pagecaches each process has per each file
- how many pages are cached per each file
- how many pagecaches each process shares
To monitor pagecache usage per a process, run "pagecache-usage-record" to
record perf data for "pagecache-usage.pl" and run "pagecache-usage-report"
to display.
The below outputs show execution sample.
[file list]
device inode caches
--------------------------------
253:0 1051413 130
253:0 1051399 2
253:0 1051414 44
253:0 1051417 154
[process list]
o postmaster-2330
cached added removed indirect
device inode pages pages pages removed pages
----------------------------------------------------------------
253:0 1051399 0 2 0 0
253:0 1051417 154 0 0 0
253:0 1051413 130 0 0 0
253:0 1051414 44 0 0 0
----------------------------------------------------------------
total: 337 2 0 0
>From the output, we can know some information like:
- if "added pages" > "cached pages" on process list then
It means repeating add/remove pagecache many times.
=> Bad case for pagecache usage
- if "added pages" <= "cached pages" on process list then
It means no unnecessary I/O operations.
=> Good case for pagecache usage.
- if "caches" on file list >
sum "cached pages" per each file on process list then
It means there are unneccessary pagecaches in the memory.
=> Bad case for pagecache usage
Signed-off-by: Keiichi Kii <k-keiichi@bx.jp.nec.com>
Cc: Atsushi Tsuji <a-tsuji@bk.jp.nec.com>
---
tools/perf/scripts/perl/bin/pagecache-usage-record | 7
tools/perf/scripts/perl/bin/pagecache-usage-report | 6
tools/perf/scripts/perl/pagecache-usage.pl | 160 +++++++++++++++++++++
3 files changed, 173 insertions(+)
Index: linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-record
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-record
@@ -0,0 +1,7 @@
+#!/bin/bash
+perf record -c 1 -f -a -M -R -e filemap:add_to_page_cache -e filemap:find_get_page -e filemap:remove_from_page_cache
+
+
+
+
+
Index: linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-report
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/bin/pagecache-usage-report
@@ -0,0 +1,6 @@
+#!/bin/bash
+# description: pagecache usage per process
+perf trace -s ~/libexec/perf-core/scripts/perl/pagecache-usage.pl
+
+
+
Index: linux-2.6-tip/tools/perf/scripts/perl/pagecache-usage.pl
===================================================================
--- /dev/null
+++ linux-2.6-tip/tools/perf/scripts/perl/pagecache-usage.pl
@@ -0,0 +1,160 @@
+# perf trace event handlers, generated by perf trace -g perl
+# Licensed under the terms of the GNU GPL License version 2
+
+# The common_* event handler fields are the most useful fields common to
+# all events. They don't necessarily correspond to the 'common_*' fields
+# in the format files. Those fields not available as handler params can
+# be retrieved using Perl functions of the form common_*($context).
+# See Context.pm for the list of available functions.
+
+use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
+use lib "./Perf-Trace-Util/lib";
+use Perf::Trace::Core;
+use Perf::Trace::Context;
+use Perf::Trace::Util;
+use List::Util qw/sum/;
+my %files;
+my %processes;
+my %records;
+
+sub trace_end
+{
+ print_pagecache_usage_per_file();
+ print "\n";
+ print_pagecache_usage_per_process();
+ print_unhandled();
+}
+
+sub filemap::remove_from_page_cache
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ delete $$f{$offset};
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+ if (exists $$r{added}{$offset}) {
+ $$r{removed}++;
+ } else {
+ $$r{indirect_removed}++;
+ }
+}
+
+sub filemap::add_to_page_cache
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ $$f{$offset}++;
+ $$r{added}{$offset}++;
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+}
+
+sub filemap::find_get_page
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm,
+ $s_dev, $i_ino, $offset, $page) = @_;
+ my $f = \%{$files{$s_dev}{$i_ino}};
+ my $r = \%{$records{$common_comm."-".$common_pid}{$f}};
+
+ if ($page != 0) {
+ $$f{$offset}++;
+ $$r{cached}++;
+ $$r{inode} = $i_ino;
+ $$r{dev} = $s_dev;
+ }
+}
+
+my %unhandled;
+
+sub trace_unhandled
+{
+ my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+ $common_pid, $common_comm) = @_;
+
+ $unhandled{$event_name}++;
+}
+
+sub print_unhandled
+{
+ if ((scalar keys %unhandled) == 0) {
+ print "unhandled events nothing\n";
+ return;
+ }
+
+ print "\nunhandled events:\n\n";
+
+ printf("%-40s %10s\n", "event", "count");
+ printf("%-40s %10s\n", "----------------------------------------",
+ "-----------");
+
+ foreach my $event_name (keys %unhandled) {
+ printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
+ }
+}
+
+sub minor
+{
+ my $dev = shift;
+ return $dev & ((1 << 20) - 1);
+}
+
+sub major
+{
+ my $dev = shift;
+ return $dev >> 20;
+}
+
+sub print_pagecache_usage_per_file
+{
+ print "[file list]\n";
+ printf(" %12s %10s %8s\n", "", "", "cached");
+ printf(" %12s %10s %8s\n", "device", "inode", "pages");
+ printf(" %s\n", '-' x 32);
+ while(my($dev, $file) = each(%files)) {
+ while(my($inode, $r) = each(%$file)) {
+ my $count = values %$r;
+ next if $count == 0;
+ printf(" %12s %10d %8d\n",
+ major($dev).":".minor($dev), $inode, $count);
+ }
+ }
+}
+
+sub print_pagecache_usage_per_process
+{
+ print "[process list]\n";
+ while(my ($pid, $v) = each(%records)) {
+ my ($sum_cached, $sum_added, $sum_removed, $sum_indirect_removed);
+
+ print "o $pid\n";
+ printf(" %12s %10s %8s %8s %8s %13s\n", "", "",
+ "cached", "added", "removed", "indirect");
+ printf(" %12s %10s %8s %8s %8s %13s\n", "device", "inode",
+ "pages", "pages", "pages", "removed pages");
+ printf(" %s\n", '-' x 64);
+ while(my ($file, $r) = each(%$v)) {
+ my $added_num = List::Util::sum(values %{$$r{added}});
+ $sum_cached += $$r{cached};
+ $sum_added += $added_num;
+ $sum_removed += $$r{removed};
+ $sum_indirect_removed += $$r{indirect_removed};
+ printf(" %12s %10d %8d %8d %8d %13d\n",
+ major($$r{dev}).":".minor($$r{dev}), $$r{inode},
+ $$r{cached}, $added_num, $$r{removed},
+ $$r{indirect_removed});
+ }
+ printf(" %s\n", '-' x 64);
+ printf(" total: %5s %10s %8d %8d %8d %13d\n", "", "", $sum_cached,
+ $sum_added, $sum_removed, $sum_indirect_removed);
+ print "\n";
+ }
+}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-01-23 0:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-23 0:04 [RFC PATCH -tip 0/2 v2] pagecache tracepoints proposal Keiichi KII
2010-01-23 0:04 ` Keiichi KII
2010-01-23 0:07 ` [RFC PATCH -tip 1/2 v2] add tracepoints for pagecache Keiichi KII
2010-01-23 0:07 ` Keiichi KII
2010-01-23 2:28 ` Steven Rostedt
2010-01-23 2:28 ` Steven Rostedt
2010-01-25 22:17 ` Keiichi KII
2010-01-25 22:17 ` Keiichi KII
2010-01-23 0:08 ` Keiichi KII [this message]
2010-01-23 0:08 ` [RFC PATCH -tip 2/2 v2] add a scripts for pagecache usage per process Keiichi KII
2010-01-23 8:21 ` Tom Zanussi
2010-01-23 8:21 ` Tom Zanussi
2010-01-25 22:16 ` Keiichi KII
2010-01-25 22:16 ` Keiichi KII
2010-02-01 8:17 ` Tom Zanussi
2010-02-01 8:17 ` Tom Zanussi
2010-02-01 21:20 ` Keiichi KII
2010-02-01 21:20 ` Keiichi KII
2010-02-23 17:54 ` Frederic Weisbecker
2010-02-23 17:54 ` Frederic Weisbecker
2010-02-23 18:13 ` Peter Zijlstra
2010-02-23 18:13 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B5A3E19.6060502@bx.jp.nec.com \
--to=k-keiichi@bx.jp.nec.com \
--cc=a-tsuji@bk.jp.nec.com \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lwoodman@redhat.com \
--cc=m-ikeda@ds.jp.nec.com \
--cc=mingo@elte.hu \
--cc=riel@redhat.com \
--cc=rostedt@goodmis.org \
--cc=tzanussi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.