linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Add trace events to mmap and brk
@ 2010-07-09 15:53 Eric B Munson
  2010-07-09 15:53 ` [PATCH 2/2] Add trace point to mremap Eric B Munson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric B Munson @ 2010-07-09 15:53 UTC (permalink / raw)
  To: akpm
  Cc: mingo, hugh.dickins, riel, peterz, anton, hch, linux-kernel,
	linux-mm, Eric B Munson

As requested by Peter Zijlstra, this patch builds on my earlier patch
and adds the corresponding trace points to mmap and brk.

Signed-off-by: Eric B Munson <emunson@mgebm.net>
---
 include/trace/events/mm.h |   38 ++++++++++++++++++++++++++++++++++++++
 mm/mmap.c                 |   10 +++++++++-
 2 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/include/trace/events/mm.h b/include/trace/events/mm.h
index c3a3857..1563988 100644
--- a/include/trace/events/mm.h
+++ b/include/trace/events/mm.h
@@ -24,6 +24,44 @@ TRACE_EVENT(munmap,
 	TP_printk("unmapping %u bytes at %lu\n", __entry->len, __entry->start)
 );
 
+TRACE_EVENT(brk,
+	TP_PROTO(unsigned long addr, unsigned long len),
+
+	TP_ARGS(addr, len),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, addr)
+		__field(unsigned long, len)
+	),
+
+	TP_fast_assign(
+		__entry->addr = addr;
+		__entry->len = len;
+	),
+
+	TP_printk("brk mmapping %lu bytes at %lu\n", __entry->len,
+		   __entry->addr)
+);
+
+TRACE_EVENT(mmap,
+	TP_PROTO(unsigned long addr, unsigned long len),
+
+	TP_ARGS(addr, len),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, addr)
+		__field(unsigned long, len)
+	),
+
+	TP_fast_assign(
+		__entry->addr = addr;
+		__entry->len = len;
+	),
+
+	TP_printk("mmapping %lu bytes at %lu\n", __entry->len,
+		   __entry->addr)
+);
+
 #endif /* _TRACE_MM_H_ */
 
 /* This part must be outside protection */
diff --git a/mm/mmap.c b/mm/mmap.c
index 0775a30..252e3e0 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -952,6 +952,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned int vm_flags;
 	int error;
 	unsigned long reqprot = prot;
+	unsigned long ret;
 
 	/*
 	 * Does the application expect PROT_READ to imply PROT_EXEC?
@@ -1077,7 +1078,12 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 	if (error)
 		return error;
 
-	return mmap_region(file, addr, len, flags, vm_flags, pgoff);
+	ret =  mmap_region(file, addr, len, flags, vm_flags, pgoff);
+
+	if (!(ret & ~PAGE_MASK))
+		trace_mmap(addr, len);
+
+	return ret;
 }
 EXPORT_SYMBOL(do_mmap_pgoff);
 
@@ -2218,6 +2224,8 @@ out:
 		if (!mlock_vma_pages_range(vma, addr, addr + len))
 			mm->locked_vm += (len >> PAGE_SHIFT);
 	}
+
+	trace_brk(addr, len);
 	return addr;
 }
 
-- 
1.7.0.4

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

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

* [PATCH 2/2] Add trace point to mremap
  2010-07-09 15:53 [PATCH 1/2] Add trace events to mmap and brk Eric B Munson
@ 2010-07-09 15:53 ` Eric B Munson
  2010-07-09 16:02   ` Christoph Hellwig
  2010-07-09 16:03 ` [PATCH 1/2] Add trace events to mmap and brk Christoph Hellwig
  2010-07-10  1:17 ` Steven Rostedt
  2 siblings, 1 reply; 6+ messages in thread
From: Eric B Munson @ 2010-07-09 15:53 UTC (permalink / raw)
  To: akpm
  Cc: mingo, hugh.dickins, riel, peterz, anton, hch, linux-kernel,
	linux-mm, Eric B Munson

This patch completes the trace point addition to the [m|mre|mun]map
and brk functions.  These trace points will be used by a userspace
tool that models application memory usage.

Signed-off-by: Eric B Munson <emunson@mgebm.net>
---
 include/trace/events/mremap.h |   37 +++++++++++++++++++++++++++++++++++++
 mm/mremap.c                   |    5 +++++
 2 files changed, 42 insertions(+), 0 deletions(-)
 create mode 100644 include/trace/events/mremap.h

diff --git a/include/trace/events/mremap.h b/include/trace/events/mremap.h
new file mode 100644
index 0000000..754a43b
--- /dev/null
+++ b/include/trace/events/mremap.h
@@ -0,0 +1,37 @@
+#if !defined(_TRACE_MREMAP_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_MREMAP_H_
+
+#include <linux/tracepoint.h>
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM mremap
+
+TRACE_EVENT(mremap,
+	TP_PROTO(unsigned long addr, unsigned long old_len,
+		 unsigned long new_addr, unsigned long new_len),
+
+	TP_ARGS(addr, old_len, new_addr, new_len),
+
+	TP_STRUCT__entry(
+		__field(unsigned long, addr)
+		__field(unsigned long, old_len)
+		__field(unsigned long, new_addr)
+		__field(unsigned long, new_len)
+	),
+
+	TP_fast_assign(
+		__entry->addr = addr;
+		__entry->old_len = old_len;
+		__entry->new_addr = new_addr;
+		__entry->new_len = new_len;
+	),
+
+	TP_printk("remapping %lu bytes from %lu to %lu bytes at %lu\n",
+		  __entry->old_len, __entry->addr, __entry->new_len,
+		  __entry->new_addr)
+);
+
+#endif /* _TRACE_MREMAP_H_ */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/mm/mremap.c b/mm/mremap.c
index cde56ee..b3aaff0 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -20,6 +20,9 @@
 #include <linux/syscalls.h>
 #include <linux/mmu_notifier.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/mremap.h>
+
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
@@ -504,6 +507,8 @@ unsigned long do_mremap(unsigned long addr,
 out:
 	if (ret & ~PAGE_MASK)
 		vm_unacct_memory(charged);
+	else
+		trace_mremap(addr, old_len, new_addr, new_len);
 	return ret;
 }
 
-- 
1.7.0.4

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

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

* Re: [PATCH 2/2] Add trace point to mremap
  2010-07-09 15:53 ` [PATCH 2/2] Add trace point to mremap Eric B Munson
@ 2010-07-09 16:02   ` Christoph Hellwig
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2010-07-09 16:02 UTC (permalink / raw)
  To: Eric B Munson
  Cc: akpm, mingo, hugh.dickins, riel, peterz, anton, hch, linux-kernel,
	linux-mm

On Fri, Jul 09, 2010 at 04:53:50PM +0100, Eric B Munson wrote:
> This patch completes the trace point addition to the [m|mre|mun]map
> and brk functions.  These trace points will be used by a userspace
> tool that models application memory usage.

Please keep all the trace events for the mmap family of syscalls in
one subsystem identifier / header file as they're closely related.

I'd prefer to have them all in the mmap one, not mm but that's
debatable.

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

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

* Re: [PATCH 1/2] Add trace events to mmap and brk
  2010-07-09 15:53 [PATCH 1/2] Add trace events to mmap and brk Eric B Munson
  2010-07-09 15:53 ` [PATCH 2/2] Add trace point to mremap Eric B Munson
@ 2010-07-09 16:03 ` Christoph Hellwig
  2010-07-12  1:58   ` KOSAKI Motohiro
  2010-07-10  1:17 ` Steven Rostedt
  2 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2010-07-09 16:03 UTC (permalink / raw)
  To: Eric B Munson
  Cc: akpm, mingo, hugh.dickins, riel, peterz, anton, hch, linux-kernel,
	linux-mm

Hmm, thinking about it a bit more, what do you trace events give us that
the event based syscall tracer doesn't?

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

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

* Re: [PATCH 1/2] Add trace events to mmap and brk
  2010-07-09 15:53 [PATCH 1/2] Add trace events to mmap and brk Eric B Munson
  2010-07-09 15:53 ` [PATCH 2/2] Add trace point to mremap Eric B Munson
  2010-07-09 16:03 ` [PATCH 1/2] Add trace events to mmap and brk Christoph Hellwig
@ 2010-07-10  1:17 ` Steven Rostedt
  2 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2010-07-10  1:17 UTC (permalink / raw)
  To: Eric B Munson
  Cc: akpm, mingo, hugh.dickins, riel, peterz, anton, hch, linux-kernel,
	linux-mm

On Fri, 2010-07-09 at 16:53 +0100, Eric B Munson wrote:
> As requested by Peter Zijlstra, this patch builds on my earlier patch
> and adds the corresponding trace points to mmap and brk.
> 
> Signed-off-by: Eric B Munson <emunson@mgebm.net>
> ---
>  include/trace/events/mm.h |   38 ++++++++++++++++++++++++++++++++++++++
>  mm/mmap.c                 |   10 +++++++++-
>  2 files changed, 47 insertions(+), 1 deletions(-)
> 
> diff --git a/include/trace/events/mm.h b/include/trace/events/mm.h
> index c3a3857..1563988 100644
> --- a/include/trace/events/mm.h
> +++ b/include/trace/events/mm.h
> @@ -24,6 +24,44 @@ TRACE_EVENT(munmap,
>  	TP_printk("unmapping %u bytes at %lu\n", __entry->len, __entry->start)
>  );
>  
> +TRACE_EVENT(brk,
> +	TP_PROTO(unsigned long addr, unsigned long len),
> +
> +	TP_ARGS(addr, len),
> +
> +	TP_STRUCT__entry(
> +		__field(unsigned long, addr)
> +		__field(unsigned long, len)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->addr = addr;
> +		__entry->len = len;
> +	),
> +
> +	TP_printk("brk mmapping %lu bytes at %lu\n", __entry->len,
> +		   __entry->addr)
> +);
> +
> +TRACE_EVENT(mmap,
> +	TP_PROTO(unsigned long addr, unsigned long len),
> +
> +	TP_ARGS(addr, len),
> +
> +	TP_STRUCT__entry(
> +		__field(unsigned long, addr)
> +		__field(unsigned long, len)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->addr = addr;
> +		__entry->len = len;
> +	),
> +
> +	TP_printk("mmapping %lu bytes at %lu\n", __entry->len,
> +		   __entry->addr)
> +);
> +

Please convert the above two into DECLARE_EVENT_CLASS() and
DEFINE_EVENT(). You don't need the "mapping" and "brk mapping" in the
TP_printk() format since the event name will be displayed as well to
differentiate the two.

Thanks,

-- Steve

>  #endif /* _TRACE_MM_H_ */
>  
>  /* This part must be outside protection */
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 0775a30..252e3e0 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -952,6 +952,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  	unsigned int vm_flags;
>  	int error;
>  	unsigned long reqprot = prot;
> +	unsigned long ret;
>  
>  	/*
>  	 * Does the application expect PROT_READ to imply PROT_EXEC?
> @@ -1077,7 +1078,12 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  	if (error)
>  		return error;
>  
> -	return mmap_region(file, addr, len, flags, vm_flags, pgoff);
> +	ret =  mmap_region(file, addr, len, flags, vm_flags, pgoff);
> +
> +	if (!(ret & ~PAGE_MASK))
> +		trace_mmap(addr, len);
> +
> +	return ret;
>  }
>  EXPORT_SYMBOL(do_mmap_pgoff);
>  
> @@ -2218,6 +2224,8 @@ out:
>  		if (!mlock_vma_pages_range(vma, addr, addr + len))
>  			mm->locked_vm += (len >> PAGE_SHIFT);
>  	}
> +
> +	trace_brk(addr, len);
>  	return addr;
>  }
>  


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

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

* Re: [PATCH 1/2] Add trace events to mmap and brk
  2010-07-09 16:03 ` [PATCH 1/2] Add trace events to mmap and brk Christoph Hellwig
@ 2010-07-12  1:58   ` KOSAKI Motohiro
  0 siblings, 0 replies; 6+ messages in thread
From: KOSAKI Motohiro @ 2010-07-12  1:58 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kosaki.motohiro, Eric B Munson, akpm, mingo, hugh.dickins, riel,
	peterz, anton, linux-kernel, linux-mm

> Hmm, thinking about it a bit more, what do you trace events give us that
> the event based syscall tracer doesn't?

Yup. I think we need two tracepoint.

 1) need to know userland argument.
    -> syscall tracer
 2) need to know actual vma change.
    -> need to trace more low layer


As I said, if userland app have following code,

	mmap(0x10000, PROT_READ|PROT_WRITE)
	mmap(0x10000, PROT_NONE)

second mmap implicitly unmap firt mmap region and map another region.
so if we want to track munmap activity, syscall exiting point is not
so good place. we need to trace per-vma activity.

btw, perf_event_mmap() already take vma argument.





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

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

end of thread, other threads:[~2010-07-12  1:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-09 15:53 [PATCH 1/2] Add trace events to mmap and brk Eric B Munson
2010-07-09 15:53 ` [PATCH 2/2] Add trace point to mremap Eric B Munson
2010-07-09 16:02   ` Christoph Hellwig
2010-07-09 16:03 ` [PATCH 1/2] Add trace events to mmap and brk Christoph Hellwig
2010-07-12  1:58   ` KOSAKI Motohiro
2010-07-10  1:17 ` Steven Rostedt

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