From: Pavel Emelyanov <xemul@parallels.com>
To: Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Michal Hocko <mhocko@suse.cz>, Mel Gorman <mgorman@suse.de>,
Johannes Weiner <hannes@cmpxchg.org>,
Linux MM <linux-mm@kvack.org>, Rik van Riel <riel@redhat.com>
Subject: [PATCH 1/2] mm: Mark VMA with VM_TRACE bit
Date: Fri, 30 Nov 2012 21:55:31 +0400 [thread overview]
Message-ID: <50B8F313.4030707@parallels.com> (raw)
In-Reply-To: <50B8F2F4.6000508@parallels.com>
When marked, mmu events on this vma will emit an event via
trace-events engine. For now only two events are added --
when the mark is set (on) and when it's unset or the marked
vma is unmapped (off). On fork() the mark is not inherited.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
---
fs/proc/task_mmu.c | 1 +
include/linux/mm.h | 1 +
include/trace/events/mmu.h | 48 ++++++++++++++++++++++++++++++++
include/uapi/asm-generic/mman-common.h | 2 +
kernel/fork.c | 2 +-
mm/madvise.c | 12 ++++++++
mm/memory.c | 3 ++
mm/mmap.c | 3 ++
8 files changed, 71 insertions(+), 1 deletions(-)
create mode 100644 include/trace/events/mmu.h
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index c0b4a04..3d43343 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -564,6 +564,7 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
[ilog2(VM_HUGEPAGE)] = "hg",
[ilog2(VM_NOHUGEPAGE)] = "nh",
[ilog2(VM_MERGEABLE)] = "mg",
+ [ilog2(VM_TRACE)] = "tr",
};
size_t i;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index bcaab4e..c7fad8d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -84,6 +84,7 @@ extern unsigned int kobjsize(const void *objp);
#define VM_MAYSHARE 0x00000080
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
+#define VM_TRACE 0x00000200 /* generate trace events */
#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
diff --git a/include/trace/events/mmu.h b/include/trace/events/mmu.h
new file mode 100644
index 0000000..71b1ba6
--- /dev/null
+++ b/include/trace/events/mmu.h
@@ -0,0 +1,48 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM mmu
+
+#if !defined(_TRACE_MMU_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_MMU_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT_CONDITION(mmu_trace_on,
+ TP_PROTO(struct vm_area_struct *vma),
+
+ TP_ARGS(vma),
+
+ TP_CONDITION(!(vma->vm_flags & VM_TRACE)),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, start)
+ ),
+
+ TP_fast_assign(
+ __entry->start = vma->vm_start;
+ ),
+
+ TP_printk("start %#lx", __entry->start)
+);
+
+TRACE_EVENT_CONDITION(mmu_trace_off,
+ TP_PROTO(struct vm_area_struct *vma),
+
+ TP_ARGS(vma),
+
+ TP_CONDITION(vma->vm_flags & VM_TRACE),
+
+ TP_STRUCT__entry(
+ __field(unsigned long, start)
+ ),
+
+ TP_fast_assign(
+ __entry->start = vma->vm_start;
+ ),
+
+ TP_printk("start %#lx", __entry->start)
+);
+
+#endif /* _TRACE_MMU_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
index d030d2c..c2b633d 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -51,6 +51,8 @@
#define MADV_DONTDUMP 16 /* Explicity exclude from the core dump,
overrides the coredump filter bits */
#define MADV_DODUMP 17 /* Clear the MADV_NODUMP flag */
+#define MADV_DOTRACE 18 /* generate mmu: trace events */
+#define MADV_DONTTRACE 19 /* stop generating events */
/* compatibility flags */
#define MAP_FILE 0
diff --git a/kernel/fork.c b/kernel/fork.c
index 8b20ab7..068ec0d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -408,7 +408,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
tmp->vm_mm = mm;
if (anon_vma_fork(tmp, mpnt))
goto fail_nomem_anon_vma_fork;
- tmp->vm_flags &= ~VM_LOCKED;
+ tmp->vm_flags &= ~(VM_LOCKED | VM_TRACE);
tmp->vm_next = tmp->vm_prev = NULL;
file = tmp->vm_file;
if (file) {
diff --git a/mm/madvise.c b/mm/madvise.c
index 03dfa5c..65633e9 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -17,6 +17,8 @@
#include <linux/fs.h>
#include <linux/file.h>
+#include <trace/events/mmu.h>
+
/*
* Any behaviour which results in changes to the vma->vm_flags needs to
* take mmap_sem for writing. Others, which simply traverse vmas, need
@@ -61,6 +63,14 @@ static long madvise_behavior(struct vm_area_struct * vma,
case MADV_DONTFORK:
new_flags |= VM_DONTCOPY;
break;
+ case MADV_DOTRACE:
+ trace_mmu_trace_on(vma);
+ new_flags |= VM_TRACE;
+ break;
+ case MADV_DONTTRACE:
+ trace_mmu_trace_off(vma);
+ new_flags &= ~VM_TRACE;
+ break;
case MADV_DOFORK:
if (vma->vm_flags & VM_IO) {
error = -EINVAL;
@@ -314,6 +324,8 @@ madvise_behavior_valid(int behavior)
#endif
case MADV_DONTDUMP:
case MADV_DODUMP:
+ case MADV_DOTRACE:
+ case MADV_DONTTRACE:
return 1;
default:
diff --git a/mm/memory.c b/mm/memory.c
index 221fc9f..a6f5951 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -58,6 +58,9 @@
#include <linux/elf.h>
#include <linux/gfp.h>
+#define CREATE_TRACE_POINTS
+#include <trace/events/mmu.h>
+
#include <asm/io.h>
#include <asm/pgalloc.h>
#include <asm/uaccess.h>
diff --git a/mm/mmap.c b/mm/mmap.c
index 9a796c4..29c9e69 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -32,6 +32,8 @@
#include <linux/khugepaged.h>
#include <linux/uprobes.h>
+#include <trace/events/mmu.h>
+
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
#include <asm/tlb.h>
@@ -227,6 +229,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
vma->vm_ops->close(vma);
if (vma->vm_file)
fput(vma->vm_file);
+ trace_mmu_trace_off(vma);
mpol_put(vma_policy(vma));
kmem_cache_free(vm_area_cachep, vma);
return next;
--
1.7.6.5
--
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:[~2012-11-30 17:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-30 17:55 [RFC PATCH 0/2] mm: Add ability to monitor task's memory changes Pavel Emelyanov
2012-11-30 17:55 ` Pavel Emelyanov [this message]
2012-11-30 17:55 ` [PATCH 2/2] mm: Generate events when tasks change their memory Pavel Emelyanov
2012-12-03 23:42 ` Xiao Guangrong
2012-12-04 5:04 ` Pavel Emelyanov
2012-12-03 8:36 ` [RFC PATCH 0/2] mm: Add ability to monitor task's memory changes Glauber Costa
2012-12-03 20:16 ` Marcelo Tosatti
2012-12-04 7:39 ` Glauber Costa
2012-12-03 22:43 ` Andrew Morton
2012-12-04 5:15 ` Pavel Emelyanov
2012-12-04 23:21 ` Andrew Morton
2012-12-05 0:17 ` Matt Mackall
2012-12-05 0:24 ` Andrew Morton
2012-12-05 0:38 ` Matt Mackall
2012-12-05 9:53 ` Pavel Emelyanov
2012-12-05 22:06 ` Andrew Morton
2012-12-06 6:32 ` Pavel Emelyanov
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=50B8F313.4030707@parallels.com \
--to=xemul@parallels.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.cz \
--cc=riel@redhat.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 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).