Skip to contentSkip to conversation

perf: Add 'perf kmem' tool

RFC PATCH In review Li Zefan 6 participants 32 messages Nov 20, 2009 – Nov 23, 2009

Subsystems (5)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

RFC PATCH 1/2 perf: Add 'perf kmem' tool

This tool is mostly a perf version of kmemtrace-user.

The following information is provided by this tool:

- the total amount of memory allocated and fragmentation per call-site
- the total amount of memory allocated and fragmentation per allocation
- total memory allocated and fragmentation in the collected dataset
- ...

 # ./perf kmem record
 ^C
 # ./perf kmem --stat caller --stat alloc -l 10

------------------------------------------------------------------------------
Callsite | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xc052f37a        |   790528/4096   |   790528/4096   |    193 |    0.000%
 0xc0541d70        |   524288/4096   |   524288/4096   |    128 |    0.000%
 0xc051cc68        |   481600/200    |   481600/200    |   2408 |    0.000%
 0xc0572623        |   297444/676    |   297440/676    |    440 |    0.001%
 0xc05399f1        |    73476/164    |    73472/164    |    448 |    0.005%
 0xc05243bf        |    51456/256    |    51456/256    |    201 |    0.000%
 0xc0730d0e        |    31844/497    |    31808/497    |     64 |    0.113%
 0xc0734c4e        |    17152/256    |    17152/256    |     67 |    0.000%
 0xc0541a6d        |    16384/128    |    16384/128    |    128 |    0.000%
 0xc059c217        |    13120/40     |    13120/40     |    328 |    0.000%
 0xc0501ee6        |    11264/88     |    11264/88     |    128 |    0.000%
 0xc04daef0        |     7504/682    |     7128/648    |     11 |    5.011%
 0xc04e14a3        |     4216/191    |     4216/191    |     22 |    0.000%
 0xc05041ca        |     3524/44     |     3520/44     |     80 |    0.114%
 0xc0734fa3        |     2104/701    |     1620/540    |      3 |   23.004%
 0xc05ec9f1        |     2024/289    |     2016/288    |      7 |    0.395%
 0xc06a1999        |     1792/256    |     1792/256    |      7 |    0.000%
 0xc0463b9a        |     1584/144    |     1584/144    |     11 |    0.000%
 0xc0541eb0        |     1024/16     |     1024/16     |     64 |    0.000%
 0xc06a19ac        |      896/128    |      896/128    |      7 |    0.000%
 0xc05721c0        |      772/12     |      768/12     |     64 |    0.518%
 0xc054d1e6        |      288/57     |      280/56     |      5 |    2.778%
 0xc04b562e        |      157/31     |      154/30     |      5 |    1.911%
 0xc04b536f        |       80/16     |       80/16     |      5 |    0.000%
 0xc05855a0        |       64/64     |       36/36     |      1 |   43.750%

------------------------------------------------------------------------------

------------------------------------------------------------------------------
Alloc Ptr | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xda884000        |  1052672/4096   |  1052672/4096   |    257 |    0.000%
 0xda886000        |   262144/4096   |   262144/4096   |     64 |    0.000%
 0xf60c7c00        |    16512/128    |    16512/128    |    129 |    0.000%
 0xf59a4118        |    13120/40     |    13120/40     |    328 |    0.000%
 0xdfd4b2c0        |    11264/88     |    11264/88     |    128 |    0.000%
 0xf5274600        |     7680/256    |     7680/256    |     30 |    0.000%
 0xe8395000        |     5948/594    |     5464/546    |     10 |    8.137%
 0xe59c3c00        |     5748/479    |     5712/476    |     12 |    0.626%
 0xf4cd1a80        |     3524/44     |     3520/44     |     80 |    0.114%
 0xe5bd1600        |     2892/482    |     2856/476    |      6 |    1.245%
 ...               | ...             | ...             | ...    | ...

------------------------------------------------------------------------------

SUMMARY
=======
Total bytes requested: 2333626
Total bytes allocated: 2353712
Total bytes wasted on internal fragmentation: 20086 Internal fragmentation: 0.853375%

TODO:
- show sym+offset in 'callsite' column
- show cross node allocation stats
- collect more useful stats?
- ...

---
 tools/perf/Makefile       |    1 +
 tools/perf/builtin-kmem.c |  578 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h      |    1 +
 tools/perf/perf.c         |   27 +-
 4 files changed, 594 insertions(+), 13 deletions(-)
 create mode 100644 tools/perf/builtin-kmem.c
tools/perf/Makefile +1 -0
index 53e663a..4ec86da 100644
@@ -445,6 +445,7 @@ BUILTIN_OBJS += builtin-timechart.o
 BUILTIN_OBJS += builtin-top.o
 BUILTIN_OBJS += builtin-trace.o
 BUILTIN_OBJS += builtin-probe.o
+BUILTIN_OBJS += builtin-kmem.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/builtin-kmem.c new file +578 -0

578 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 9b02d85..a3d8bf6 100644
@@ -28,5 +28,6 @@ extern int cmd_top(int argc, const char **argv, const char *prefix);
 extern int cmd_trace(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
+extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/perf.c +14 -13
index 89b82ac..cf64049 100644
@@ -285,20 +285,21 @@ static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
 	static struct cmd_struct commands[] = {
-		{ "help", cmd_help, 0 },
-		{ "list", cmd_list, 0 },
 		{ "buildid-list", cmd_buildid_list, 0 },
-		{ "record", cmd_record, 0 },
-		{ "report", cmd_report, 0 },
-		{ "bench", cmd_bench, 0 },
-		{ "stat", cmd_stat, 0 },
-		{ "timechart", cmd_timechart, 0 },
-		{ "top", cmd_top, 0 },
-		{ "annotate", cmd_annotate, 0 },
-		{ "version", cmd_version, 0 },
-		{ "trace", cmd_trace, 0 },
-		{ "sched", cmd_sched, 0 },
-		{ "probe", cmd_probe, 0 },
+		{ "help",	cmd_help,	0 },
+		{ "list",	cmd_list,	0 },
+		{ "record",	cmd_record,	0 },
+		{ "report",	cmd_report,	0 },
+		{ "bench",	cmd_bench,	0 },
+		{ "stat",	cmd_stat,	0 },
+		{ "timechart",	cmd_timechart,	0 },
+		{ "top",	cmd_top,	0 },
+		{ "annotate",	cmd_annotate,	0 },
+		{ "version",	cmd_version,	0 },
+		{ "trace",	cmd_trace,	0 },
+		{ "sched",	cmd_sched,	0 },
+		{ "probe",	cmd_probe,	0 },
+		{ "kmem",	cmd_kmem,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;
Signature · 7 lines
1.6.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw

PATCH 2/2 tracing: Remove kmemtrace tracer

The kmem trace events can replace the functions of kmemtrace tracer.

And kmemtrace-user can be modified to use trace events. (But after cloning the git repo, I found it's still based on the original relay version..), not to mention now we have 'perf kmem' tool.

---
 Documentation/ABI/testing/debugfs-kmemtrace |   71 ----
 Documentation/trace/kmemtrace.txt           |  126 -------
 MAINTAINERS                                 |    7 -
 include/linux/kmemtrace.h                   |   25 --
 include/linux/slab_def.h                    |   16 +-
 include/linux/slub_def.h                    |   14 +-
 init/main.c                                 |    2 -
 kernel/trace/Kconfig                        |   20 -
 kernel/trace/Makefile                       |    1 -
 kernel/trace/kmemtrace.c                    |  511 ---------------------------
 kernel/trace/trace.h                        |   11 -
 kernel/trace/trace_entries.h                |   35 --
 mm/slab.c                                   |   11 -
 mm/slub.c                                   |    3 -
 14 files changed, 7 insertions(+), 846 deletions(-)
 delete mode 100644 Documentation/ABI/testing/debugfs-kmemtrace
 delete mode 100644 Documentation/trace/kmemtrace.txt
 delete mode 100644 include/linux/kmemtrace.h
 delete mode 100644 kernel/trace/kmemtrace.c
Documentation/ABI/testing/debugfs-kmemtrace deleted +0 -71
deleted file mode 100644
index 5e6a92a..0000000
@@ -1,71 +0,0 @@
-What:		/sys/kernel/debug/kmemtrace/
-Date:		July 2008
-Contact:	Eduard - Gabriel Munteanu <[email protected]>
-Description:
-
-In kmemtrace-enabled kernels, the following files are created:
-
-/sys/kernel/debug/kmemtrace/
-	cpu<n>		(0400)	Per-CPU tracing data, see below. (binary)
-	total_overruns	(0400)	Total number of bytes which were dropped from
-				cpu<n> files because of full buffer condition,
-				non-binary. (text)
-	abi_version	(0400)	Kernel's kmemtrace ABI version. (text)
-
-Each per-CPU file should be read according to the relay interface. That is,
-the reader should set affinity to that specific CPU and, as currently done by
-the userspace application (though there are other methods), use poll() with
-an infinite timeout before every read(). Otherwise, erroneous data may be
-read. The binary data has the following _core_ format:
-
-	Event ID	(1 byte)	Unsigned integer, one of:
-		0 - represents an allocation (KMEMTRACE_EVENT_ALLOC)
-		1 - represents a freeing of previously allocated memory
-		    (KMEMTRACE_EVENT_FREE)
-	Type ID		(1 byte)	Unsigned integer, one of:
-		0 - this is a kmalloc() / kfree()
-		1 - this is a kmem_cache_alloc() / kmem_cache_free()
-		2 - this is a __get_free_pages() et al.
-	Event size	(2 bytes)	Unsigned integer representing the
-					size of this event. Used to extend
-					kmemtrace. Discard the bytes you
-					don't know about.
-	Sequence number	(4 bytes)	Signed integer used to reorder data
-					logged on SMP machines. Wraparound
-					must be taken into account, although
-					it is unlikely.
-	Caller address	(8 bytes)	Return address to the caller.
-	Pointer to mem	(8 bytes)	Pointer to target memory area. Can be
-					NULL, but not all such calls might be
-					recorded.
-
-In case of KMEMTRACE_EVENT_ALLOC events, the next fields follow:
-
-	Requested bytes	(8 bytes)	Total number of requested bytes,
-					unsigned, must not be zero.
-	Allocated bytes (8 bytes)	Total number of actually allocated
-					bytes, unsigned, must not be lower
-					than requested bytes.
-	Requested flags	(4 bytes)	GFP flags supplied by the caller.
-	Target CPU	(4 bytes)	Signed integer, valid for event id 1.
-					If equal to -1, target CPU is the same
-					as origin CPU, but the reverse might
-					not be true.
-
-The data is made available in the same endianness the machine has.
-
-Other event ids and type ids may be defined and added. Other fields may be
-added by increasing event size, but see below for details.
-Every modification to the ABI, including new id definitions, are followed
-by bumping the ABI version by one.
-
-Adding new data to the packet (features) is done at the end of the mandatory
-data:
-	Feature size	(2 byte)
-	Feature ID	(1 byte)
-	Feature data	(Feature size - 3 bytes)
-
-
-Users:
-	kmemtrace-user - git://repo.or.cz/kmemtrace-user.git
-
Documentation/trace/kmemtrace.txt deleted +0 -126

126 lines not on this page · raw message

MAINTAINERS +0 -7
index c824b4d..dfb2e7d 100644
@@ -3100,13 +3100,6 @@ F:	include/linux/kmemleak.h
 F:	mm/kmemleak.c
 F:	mm/kmemleak-test.c
 
-KMEMTRACE
-M:	Eduard - Gabriel Munteanu <[email protected]>
-S:	Maintained
-F:	Documentation/trace/kmemtrace.txt
-F:	include/linux/kmemtrace.h
-F:	kernel/trace/kmemtrace.c
-
 KPROBES
 M:	Ananth N Mavinakayanahalli <[email protected]>
 M:	Anil S Keshavamurthy <[email protected]>
include/linux/kmemtrace.h deleted +0 -25
deleted file mode 100644
index b616d39..0000000
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 Eduard - Gabriel Munteanu
- *
- * This file is released under GPL version 2.
- */
-
-#ifndef _LINUX_KMEMTRACE_H
-#define _LINUX_KMEMTRACE_H
-
-#ifdef __KERNEL__
-
-#include <trace/events/kmem.h>
-
-#ifdef CONFIG_KMEMTRACE
-extern void kmemtrace_init(void);
-#else
-static inline void kmemtrace_init(void)
-{
-}
-#endif
-
-#endif /* __KERNEL__ */
-
-#endif /* _LINUX_KMEMTRACE_H */
-
include/linux/slab_def.h +4 -12
index 850d057..56171d6 100644
@@ -14,7 +14,8 @@
 #include <asm/page.h>		/* kmalloc_sizes.h needs PAGE_SIZE */
 #include <asm/cache.h>		/* kmalloc_sizes.h needs L1_CACHE_BYTES */
 #include <linux/compiler.h>
-#include <linux/kmemtrace.h>
+
+#include <trace/events/kmem.h>
 
 /*
  * struct kmem_cache
@@ -108,22 +109,13 @@ struct cache_sizes {
 extern struct cache_sizes malloc_sizes[];
 
 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
+void *kmem_cache_alloc_notrace(struct kmem_cache *, gfp_t);
 void *__kmalloc(size_t size, gfp_t flags);
 
-#ifdef CONFIG_KMEMTRACE
-extern void *kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags);
-extern size_t slab_buffer_size(struct kmem_cache *cachep);
-#else
-static __always_inline void *
-kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags)
-{
-	return kmem_cache_alloc(cachep, flags);
-}
 static inline size_t slab_buffer_size(struct kmem_cache *cachep)
 {
-	return 0;
+	return cachep->buffer_size;
 }
-#endif
 
 static __always_inline void *kmalloc(size_t size, gfp_t flags)
 {
include/linux/slub_def.h +3 -11
index 5ad70a6..b41dd8c 100644
@@ -10,9 +10,10 @@
 #include <linux/gfp.h>
 #include <linux/workqueue.h>
 #include <linux/kobject.h>
-#include <linux/kmemtrace.h>
 #include <linux/kmemleak.h>
 
+#include <trace/events/kmem.h>
+
 enum stat_item {
 	ALLOC_FASTPATH,		/* Allocation from cpu slab */
 	ALLOC_SLOWPATH,		/* Allocation by getting a new cpu slab */
@@ -215,18 +216,9 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
 #endif
 
 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
+void *kmem_cache_alloc_notrace(struct kmem_cache *, gfp_t);
 void *__kmalloc(size_t size, gfp_t flags);
 
-#ifdef CONFIG_KMEMTRACE
-extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
-#else
-static __always_inline void *
-kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags)
-{
-	return kmem_cache_alloc(s, gfpflags);
-}
-#endif
-
 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
 {
 	unsigned int order = get_order(size);
init/main.c +0 -2
index 5988deb..daf13a4 100644
@@ -66,7 +66,6 @@
 #include <linux/ftrace.h>
 #include <linux/async.h>
 #include <linux/kmemcheck.h>
-#include <linux/kmemtrace.h>
 #include <linux/sfi.h>
 #include <linux/shmem_fs.h>
 #include <trace/boot.h>
@@ -645,7 +644,6 @@ asmlinkage void __init start_kernel(void)
 #endif
 	page_cgroup_init();
 	enable_debug_pagealloc();
-	kmemtrace_init();
 	kmemleak_init();
 	debug_objects_mem_init();
 	idr_init_cache();
kernel/trace/Kconfig +0 -20
index 20e3695..530bbb1 100644
@@ -406,26 +406,6 @@ config HW_BRANCH_TRACER
 	  This tracer records all branches on the system in a circular
 	  buffer giving access to the last N branches for each cpu.
 
-config KMEMTRACE
-	bool "Trace SLAB allocations"
-	select GENERIC_TRACER
-	help
-	  kmemtrace provides tracing for slab allocator functions, such as
-	  kmalloc, kfree, kmem_cache_alloc, kmem_cache_free etc.. Collected
-	  data is then fed to the userspace application in order to analyse
-	  allocation hotspots, internal fragmentation and so on, making it
-	  possible to see how well an allocator performs, as well as debug
-	  and profile kernel code.
-
-	  This requires an userspace application to use. See
-	  Documentation/trace/kmemtrace.txt for more information.
-
-	  Saying Y will make the kernel somewhat larger and slower. However,
-	  if you disable kmemtrace at run-time or boot-time, the performance
-	  impact is minimal (depending on the arch the kernel is built for).
-
-	  If unsure, say N.
-
 config WORKQUEUE_TRACER
 	bool "Trace workqueues"
 	select GENERIC_TRACER
kernel/trace/Makefile +0 -1
index cd9ecd8..cd5ed77 100644
@@ -42,7 +42,6 @@ obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
 obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
 obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o
-obj-$(CONFIG_KMEMTRACE) += kmemtrace.o
 obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o
 obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
 ifeq ($(CONFIG_BLOCK),y)
kernel/trace/kmemtrace.c deleted +0 -511

511 lines not on this page · raw message

kernel/trace/trace.h +0 -11
index 5d6398b..d850dc2 100644
@@ -10,7 +10,6 @@
 #include <linux/tracepoint.h>
 #include <linux/ftrace.h>
 #include <trace/boot.h>
-#include <linux/kmemtrace.h>
 #include <linux/hw_breakpoint.h>
 
 #include <linux/trace_seq.h>
@@ -43,12 +42,6 @@ enum trace_type {
 	__TRACE_LAST_TYPE,
 };
 
-enum kmemtrace_type_id {
-	KMEMTRACE_TYPE_KMALLOC = 0,	/* kmalloc() or kfree(). */
-	KMEMTRACE_TYPE_CACHE,		/* kmem_cache_*(). */
-	KMEMTRACE_TYPE_PAGES,		/* __get_free_pages() and friends. */
-};
-
 extern struct tracer boot_tracer;
 
 #undef __field
@@ -230,10 +223,6 @@ extern void __ftrace_bad_type(void);
 		IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,	\
 			  TRACE_GRAPH_RET);		\
 		IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
-		IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry,	\
-			  TRACE_KMEM_ALLOC);	\
-		IF_ASSIGN(var, ent, struct kmemtrace_free_entry,	\
-			  TRACE_KMEM_FREE);	\
 		IF_ASSIGN(var, ent, struct ksym_trace_entry, TRACE_KSYM);\
 		__ftrace_bad_type();					\
 	} while (0)
kernel/trace/trace_entries.h +0 -35
index c16a08f..7564b56 100644
@@ -330,41 +330,6 @@ FTRACE_ENTRY(hw_branch, hw_branch_entry,
 	F_printk("from: %llx to: %llx", __entry->from, __entry->to)
 );
 
-FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry,
-
-	TRACE_KMEM_ALLOC,
-
-	F_STRUCT(
-		__field(	enum kmemtrace_type_id,	type_id		)
-		__field(	unsigned long,		call_site	)
-		__field(	const void *,		ptr		)
-		__field(	size_t,			bytes_req	)
-		__field(	size_t,			bytes_alloc	)
-		__field(	gfp_t,			gfp_flags	)
-		__field(	int,			node		)
-	),
-
-	F_printk("type:%u call_site:%lx ptr:%p req:%zi alloc:%zi"
-		 " flags:%x node:%d",
-		 __entry->type_id, __entry->call_site, __entry->ptr,
-		 __entry->bytes_req, __entry->bytes_alloc,
-		 __entry->gfp_flags, __entry->node)
-);
-
-FTRACE_ENTRY(kmem_free, kmemtrace_free_entry,
-
-	TRACE_KMEM_FREE,
-
-	F_STRUCT(
-		__field(	enum kmemtrace_type_id,	type_id		)
-		__field(	unsigned long,		call_site	)
-		__field(	const void *,		ptr		)
-	),
-
-	F_printk("type:%u call_site:%lx ptr:%p",
-		 __entry->type_id, __entry->call_site, __entry->ptr)
-);
-
 FTRACE_ENTRY(ksym_trace, ksym_trace_entry,
 
 	TRACE_KSYM,
mm/slab.c +0 -11
index 7dfa481..07e4072 100644
@@ -102,7 +102,6 @@
 #include	<linux/cpu.h>
 #include	<linux/sysctl.h>
 #include	<linux/module.h>
-#include	<linux/kmemtrace.h>
 #include	<linux/rcupdate.h>
 #include	<linux/string.h>
 #include	<linux/uaccess.h>
@@ -490,14 +489,6 @@ static void **dbg_userword(struct kmem_cache *cachep, void *objp)
 
 #endif
 
-#ifdef CONFIG_KMEMTRACE
-size_t slab_buffer_size(struct kmem_cache *cachep)
-{
-	return cachep->buffer_size;
-}
-EXPORT_SYMBOL(slab_buffer_size);
-#endif
-
 /*
  * Do not go above this order unless 0 objects fit into the slab.
  */
@@ -3558,13 +3549,11 @@ void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags)
 }
 EXPORT_SYMBOL(kmem_cache_alloc);
 
-#ifdef CONFIG_KMEMTRACE
 void *kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags)
 {
 	return __cache_alloc(cachep, flags, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kmem_cache_alloc_notrace);
-#endif
 
 /**
  * kmem_ptr_validate - check if an untrusted pointer might be a slab entry.
mm/slub.c +0 -3
index 4996fc7..97f2da6 100644
@@ -17,7 +17,6 @@
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-#include <linux/kmemtrace.h>
 #include <linux/kmemcheck.h>
 #include <linux/cpu.h>
 #include <linux/cpuset.h>
@@ -1754,13 +1753,11 @@ void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags)
 }
 EXPORT_SYMBOL(kmem_cache_alloc);
 
-#ifdef CONFIG_KMEMTRACE
 void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags)
 {
 	return slab_alloc(s, gfpflags, -1, _RET_IP_);
 }
 EXPORT_SYMBOL(kmem_cache_alloc_notrace);
-#endif
 
 #ifdef CONFIG_NUMA
 void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node)
Signature · 1 line
1.6.3
#6 lore raw
In reply to Li Zefan
Quoted 57 lines · Li Zefan

This tool is mostly a perf version of kmemtrace-user.

The following information is provided by this tool:

- the total amount of memory allocated and fragmentation per call-site
- the total amount of memory allocated and fragmentation per allocation
- total memory allocated and fragmentation in the collected dataset
- ...

 # ./perf kmem record
 ^C
 # ./perf kmem --stat caller --stat alloc -l 10

------------------------------------------------------------------------------
Callsite | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xc052f37a        |   790528/4096   |   790528/4096   |    193 |    0.000%
 0xc0541d70        |   524288/4096   |   524288/4096   |    128 |    0.000%
 0xc051cc68        |   481600/200    |   481600/200    |   2408 |    0.000%
 0xc0572623        |   297444/676    |   297440/676    |    440 |    0.001%
 0xc05399f1        |    73476/164    |    73472/164    |    448 |    0.005%
 0xc05243bf        |    51456/256    |    51456/256    |    201 |    0.000%
 0xc0730d0e        |    31844/497    |    31808/497    |     64 |    0.113%
 0xc0734c4e        |    17152/256    |    17152/256    |     67 |    0.000%
 0xc0541a6d        |    16384/128    |    16384/128    |    128 |    0.000%
 0xc059c217        |    13120/40     |    13120/40     |    328 |    0.000%
 0xc0501ee6        |    11264/88     |    11264/88     |    128 |    0.000%
 0xc04daef0        |     7504/682    |     7128/648    |     11 |    5.011%
 0xc04e14a3        |     4216/191    |     4216/191    |     22 |    0.000%
 0xc05041ca        |     3524/44     |     3520/44     |     80 |    0.114%
 0xc0734fa3        |     2104/701    |     1620/540    |      3 |   23.004%
 0xc05ec9f1        |     2024/289    |     2016/288    |      7 |    0.395%
 0xc06a1999        |     1792/256    |     1792/256    |      7 |    0.000%
 0xc0463b9a        |     1584/144    |     1584/144    |     11 |    0.000%
 0xc0541eb0        |     1024/16     |     1024/16     |     64 |    0.000%
 0xc06a19ac        |      896/128    |      896/128    |      7 |    0.000%
 0xc05721c0        |      772/12     |      768/12     |     64 |    0.518%
 0xc054d1e6        |      288/57     |      280/56     |      5 |    2.778%
 0xc04b562e        |      157/31     |      154/30     |      5 |    1.911%
 0xc04b536f        |       80/16     |       80/16     |      5 |    0.000%
 0xc05855a0        |       64/64     |       36/36     |      1 |   43.750%

------------------------------------------------------------------------------

------------------------------------------------------------------------------
Alloc Ptr | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xda884000        |  1052672/4096   |  1052672/4096   |    257 |    0.000%
 0xda886000        |   262144/4096   |   262144/4096   |     64 |    0.000%
 0xf60c7c00        |    16512/128    |    16512/128    |    129 |    0.000%
 0xf59a4118        |    13120/40     |    13120/40     |    328 |    0.000%
 0xdfd4b2c0        |    11264/88     |    11264/88     |    128 |    0.000%
 0xf5274600        |     7680/256    |     7680/256    |     30 |    0.000%
 0xe8395000        |     5948/594    |     5464/546    |     10 |    8.137%
 0xe59c3c00        |     5748/479    |     5712/476    |     12 |    0.626%
 0xf4cd1a80        |     3524/44     |     3520/44     |     80 |    0.114%
 0xe5bd1600        |     2892/482    |     2856/476    |      6 |    1.245%
 ...               | ...             | ...             | ...    | ...
Quoted 8 lines

------------------------------------------------------------------------------

SUMMARY
=======
Total bytes requested: 2333626
Total bytes allocated: 2353712
Total bytes wasted on internal fragmentation: 20086 Internal fragmentation: 0.853375%

Very impressive!

Quoted 2 lines

TODO:
- show sym+offset in 'callsite' column

The way to print symbolic information for the 'callsite' column is to fill in and walk the thread->DSO->symbol trees that all perf tools maintain:

	/* simplified, without error handling */

	ip = event->ip.ip;

	thread = threads__findnew(event->ip.pid);

	map = thread__find_map(thread, ip);

	ip = map->map_ip(map, ip); /* map absolute RIP into DSO-relative one */

	sym = map__find_symbol(map, ip, symbol_filter);

then sym->name is the string that can be printed out. This works in a symmetric way for both kernel-space and user-space symbols. (Call-chain information can be captured and displayed too.)

( 'Alloc Ptr' symbolization is harder, but it would be useful too i
think, to map it back to the slab cache name. )

Quoted 1 line

- show cross node allocation stats

I checked and we appear to have all the right events for that - the node ID is being traced consistently AFAICS.

Quoted 2 lines

- collect more useful stats?
- ...

Pekka, Eduard and the other slab hackers might have ideas about what other stats they generally like to see to judge the health of a workload (or system).

If this iteration looks good to the slab folks then i can apply it as-is and we can do the other changes relative to that. It looks good to me as a first step, and it's functional already.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by
#7 lore raw
Quoted 3 lines · Ingo Molnar

Pekka, Eduard and the other slab hackers might have ideas about what other stats they generally like to see to judge the health of a workload (or system).

kmalloc()/kfree() CPU ping-pong call-sites (i.e. alloc and free happening on different CPUs) is one interesting metric we haven't implemented yet. Valgrind massif tool type of output graph would be helpful as well:

http://valgrind.org/docs/manual/ms-manual.html

Quoted 3 lines · Ingo Molnar

If this iteration looks good to the slab folks then i can apply it as-is and we can do the other changes relative to that. It looks good to me as a first step, and it's functional already.

Yeah, looks OK to me as the first step. Patch 2 looks premature, though, looking at the output of "perf kmem" from patch 1.

Pekka

#2 lore raw

Re: [PATCH 2/2] tracing: Remove kmemtrace tracer

In reply to Li Zefan

Li Zefan kirjoitti:

Quoted 9 lines

The kmem trace events can replace the functions of kmemtrace tracer.

And kmemtrace-user can be modified to use trace events. (But after cloning the git repo, I found it's still based on the original relay version..), not to mention now we have 'perf kmem' tool.

NAK for the time being. "perf kmem" output is not yet as good as that of kmemtrace-user.

Pekka

author
#28 lore raw
In reply to Ingo Molnar
Quoted 19 lines
Quoted 2 lines

TODO:
- show sym+offset in 'callsite' column

The way to print symbolic information for the 'callsite' column is to fill in and walk the thread->DSO->symbol trees that all perf tools maintain:

	/* simplified, without error handling */

	ip = event->ip.ip;

	thread = threads__findnew(event->ip.pid);

	map = thread__find_map(thread, ip);

	ip = map->map_ip(map, ip); /* map absolute RIP into DSO-relative one */

	sym = map__find_symbol(map, ip, symbol_filter);
Quoted 7 lines

then sym->name is the string that can be printed out. This works in a symmetric way for both kernel-space and user-space symbols. (Call-chain information can be captured and displayed too.)

( 'Alloc Ptr' symbolization is harder, but it would be useful too i
think, to map it back to the slab cache name. )

Thanks.

I was lazy to figure it out by myself. ;)

Quoted 5 lines
Quoted 1 line

- show cross node allocation stats

I checked and we appear to have all the right events for that - the node ID is being traced consistently AFAICS.

Actually kmemtrace-user shows this stats, but in a wrong way. It doesn't map cpu_nr to node.

Quoted 11 lines
Quoted 2 lines

- collect more useful stats?
- ...

Pekka, Eduard and the other slab hackers might have ideas about what other stats they generally like to see to judge the health of a workload (or system).

If this iteration looks good to the slab folks then i can apply it as-is and we can do the other changes relative to that. It looks good to me as a first step, and it's functional already.

Thanks!

author
#3 lore raw

Re: [PATCH 2/2] tracing: Remove kmemtrace tracer

In reply to Pekka Enberg
Quoted 9 lines · Pekka Enberg

Li Zefan kirjoitti:

Quoted 8 lines

The kmem trace events can replace the functions of kmemtrace tracer.

And kmemtrace-user can be modified to use trace events. (But after cloning the git repo, I found it's still based on the original relay version..), not to mention now we have 'perf kmem' tool.

Quoted 5 lines
Quoted 1 line

NAK for the time being. "perf kmem" output is not yet as good as that of kmemtrace-user.

But is the current kmemtrace-user based on kmemtrace?

Quoted 1 line

From the git repo:

http://repo.or.cz/w/kmemtrace-user.git

I found it's still based on relay.

#4 lore raw

Re: [PATCH 2/2] tracing: Remove kmemtrace tracer

Quoted 16 lines · Li Zefan
Quoted 9 lines · Pekka Enberg

Li Zefan kirjoitti:

Quoted 8 lines

The kmem trace events can replace the functions of kmemtrace tracer.

And kmemtrace-user can be modified to use trace events. (But after cloning the git repo, I found it's still based on the original relay version..), not to mention now we have 'perf kmem' tool.

Quoted 5 lines
Quoted 1 line

NAK for the time being. "perf kmem" output is not yet as good as that of kmemtrace-user.

Quoted 6 lines

But is the current kmemtrace-user based on kmemtrace?

From the git repo:
http://repo.or.cz/w/kmemtrace-user.git

I found it's still based on relay.

The "ftrace-temp" branch seems to have the ftrace based version in it. Eduard?

Pekka

#8 lore raw
In reply to Pekka Enberg
Quoted 13 lines · Pekka Enberg
Quoted 3 lines · Ingo Molnar

Pekka, Eduard and the other slab hackers might have ideas about what other stats they generally like to see to judge the health of a workload (or system).

kmalloc()/kfree() CPU ping-pong call-sites (i.e. alloc and free happening on different CPUs) is one interesting metric we haven't implemented yet. Valgrind massif tool type of output graph would be helpful as well:

http://valgrind.org/docs/manual/ms-manual.html

On Fri, Nov 20, 2009 at 10:14 AM, Ingo Molnar <[email protected]> wrote:

Quoted 8 lines
Quoted 3 lines

If this iteration looks good to the slab folks then i can apply it as-is and we can do the other changes relative to that. It looks good to me as a first step, and it's functional already.

Yeah, looks OK to me as the first step. Patch 2 looks premature, though, looking at the output of "perf kmem" from patch 1.

Great - thanks for the quick ack!

Regarding patch 2 - can we set some definitive benchmark threshold for that? I.e. a list of must-have features in 'perf kmem' before we can do it? 100% information and analysis equivalency with kmemtrace-user tool? Eduard, what do you think?

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#5 lore raw

Re: [PATCH 2/2] tracing: Remove kmemtrace tracer

In reply to Pekka Enberg
Quoted 15 lines · Pekka Enberg
Quoted 14 lines · Li Zefan
Quoted 13 lines · Pekka Enberg

Li Zefan kirjoitti:

Quoted 9 lines

The kmem trace events can replace the functions of kmemtrace tracer.

And kmemtrace-user can be modified to use trace events. (But after cloning the git repo, I found it's still based on the original relay version..), not to mention now we have 'perf kmem' tool.

NAK for the time being. "perf kmem" output is not yet as good as that of kmemtrace-user.

Quoted 9 lines
Quoted 6 lines

But is the current kmemtrace-user based on kmemtrace?

From the git repo:
http://repo.or.cz/w/kmemtrace-user.git

I found it's still based on relay.

The "ftrace-temp" branch seems to have the ftrace based version in it. Eduard?

Thanks. I just overlooked the branch..

#9 lore raw
In reply to Ingo Molnar

Ingo Molnar kirjoitti:

Quoted 1 line

Regarding patch 2 - can we set some definitive benchmark threshold for that? I.e. a list of must-have features in 'perf kmem' before we can do it? 100% information and analysis equivalency with kmemtrace-user tool?

I'd be interested to hear Eduard's comment on that.

That said, I'll try to find some time to test "perf kmem" and provide feedback on that. I can ACK the patch when I'm happy with the output. :-)

I'm mostly interested in two scenarios: (1) getting a nice report on worst fragmented call-sites (perf kmem needs symbol lookup) and (2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Pekka

author
#10 lore raw
Quoted 6 lines · Pekka Enberg

Ingo Molnar kirjoitti:

Quoted 4 lines

Regarding patch 2 - can we set some definitive benchmark threshold for that? I.e. a list of must-have features in 'perf kmem' before we can do it? 100% information and analysis equivalency with kmemtrace-user tool?

Quoted 7 lines

I'd be interested to hear Eduard's comment on that.

That said, I'll try to find some time to test "perf kmem" and provide feedback on that. I can ACK the patch when I'm happy with the output. :-)

I'm mostly interested in two scenarios: (1) getting a nice report on worst fragmented call-sites (perf kmem needs symbol lookup) and

This will be done in next version.

Quoted 4 lines

(2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Everything needed and machine-specific will be recorded in perf.data, so this should already been supported. I'll try it.

#29 lore raw
In reply to Li Zefan
Commit-ID:  ba77c9e11111a172c9e8687fe16a6a173a61916f
Gitweb:     http://git.kernel.org/tip/ba77c9e11111a172c9e8687fe16a6a173a61916f
Author:     Li Zefan <[email protected]>
AuthorDate: Fri, 20 Nov 2009 15:53:25 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 20 Nov 2009 09:51:41 +0100

perf: Add 'perf kmem' tool

This tool is mostly a perf version of kmemtrace-user.

The following information is provided by this tool:

- the total amount of memory allocated and fragmentation per call-site

- the total amount of memory allocated and fragmentation per allocation

- total memory allocated and fragmentation in the collected dataset - ...

Sample output:

 # ./perf kmem record
 ^C
 # ./perf kmem --stat caller --stat alloc -l 10

------------------------------------------------------------------------------
Callsite | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xc052f37a        |   790528/4096   |   790528/4096   |    193 |    0.000%
 0xc0541d70        |   524288/4096   |   524288/4096   |    128 |    0.000%
 0xc051cc68        |   481600/200    |   481600/200    |   2408 |    0.000%
 0xc0572623        |   297444/676    |   297440/676    |    440 |    0.001%
 0xc05399f1        |    73476/164    |    73472/164    |    448 |    0.005%
 0xc05243bf        |    51456/256    |    51456/256    |    201 |    0.000%
 0xc0730d0e        |    31844/497    |    31808/497    |     64 |    0.113%
 0xc0734c4e        |    17152/256    |    17152/256    |     67 |    0.000%
 0xc0541a6d        |    16384/128    |    16384/128    |    128 |    0.000%
 0xc059c217        |    13120/40     |    13120/40     |    328 |    0.000%
 0xc0501ee6        |    11264/88     |    11264/88     |    128 |    0.000%
 0xc04daef0        |     7504/682    |     7128/648    |     11 |    5.011%
 0xc04e14a3        |     4216/191    |     4216/191    |     22 |    0.000%
 0xc05041ca        |     3524/44     |     3520/44     |     80 |    0.114%
 0xc0734fa3        |     2104/701    |     1620/540    |      3 |   23.004%
 0xc05ec9f1        |     2024/289    |     2016/288    |      7 |    0.395%
 0xc06a1999        |     1792/256    |     1792/256    |      7 |    0.000%
 0xc0463b9a        |     1584/144    |     1584/144    |     11 |    0.000%
 0xc0541eb0        |     1024/16     |     1024/16     |     64 |    0.000%
 0xc06a19ac        |      896/128    |      896/128    |      7 |    0.000%
 0xc05721c0        |      772/12     |      768/12     |     64 |    0.518%
 0xc054d1e6        |      288/57     |      280/56     |      5 |    2.778%
 0xc04b562e        |      157/31     |      154/30     |      5 |    1.911%
 0xc04b536f        |       80/16     |       80/16     |      5 |    0.000%
 0xc05855a0        |       64/64     |       36/36     |      1 |   43.750%

------------------------------------------------------------------------------

------------------------------------------------------------------------------
Alloc Ptr | Total_alloc/Per | Total_req/Per | Hit | Fragmentation
------------------------------------------------------------------------------

 0xda884000        |  1052672/4096   |  1052672/4096   |    257 |    0.000%
 0xda886000        |   262144/4096   |   262144/4096   |     64 |    0.000%
 0xf60c7c00        |    16512/128    |    16512/128    |    129 |    0.000%
 0xf59a4118        |    13120/40     |    13120/40     |    328 |    0.000%
 0xdfd4b2c0        |    11264/88     |    11264/88     |    128 |    0.000%
 0xf5274600        |     7680/256    |     7680/256    |     30 |    0.000%
 0xe8395000        |     5948/594    |     5464/546    |     10 |    8.137%
 0xe59c3c00        |     5748/479    |     5712/476    |     12 |    0.626%
 0xf4cd1a80        |     3524/44     |     3520/44     |     80 |    0.114%
 0xe5bd1600        |     2892/482    |     2856/476    |      6 |    1.245%
 ...               | ...             | ...             | ...    | ...

------------------------------------------------------------------------------

SUMMARY
=======
Total bytes requested: 2333626
Total bytes allocated: 2353712
Total bytes wasted on internal fragmentation: 20086 Internal fragmentation: 0.853375%

TODO:
- show sym+offset in 'callsite' column
- show cross node allocation stats
- collect more useful stats?
- ...

LKML-Reference: <[email protected]>

---
 tools/perf/Makefile       |    1 +
 tools/perf/builtin-kmem.c |  578 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h      |    1 +
 tools/perf/perf.c         |   27 +-
 4 files changed, 594 insertions(+), 13 deletions(-)
tools/perf/Makefile +1 -0
index 3f0666a..d7198c5 100644
@@ -444,6 +444,7 @@ BUILTIN_OBJS += builtin-timechart.o
 BUILTIN_OBJS += builtin-top.o
 BUILTIN_OBJS += builtin-trace.o
 BUILTIN_OBJS += builtin-probe.o
+BUILTIN_OBJS += builtin-kmem.o
 
 PERFLIBS = $(LIB_FILE)
 
tools/perf/builtin-kmem.c new file +578 -0

578 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 9b02d85..a3d8bf6 100644
@@ -28,5 +28,6 @@ extern int cmd_top(int argc, const char **argv, const char *prefix);
 extern int cmd_trace(int argc, const char **argv, const char *prefix);
 extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
+extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 
 #endif
tools/perf/perf.c +14 -13
index 89b82ac..cf64049 100644
@@ -285,20 +285,21 @@ static void handle_internal_command(int argc, const char **argv)
 {
 	const char *cmd = argv[0];
 	static struct cmd_struct commands[] = {
-		{ "help", cmd_help, 0 },
-		{ "list", cmd_list, 0 },
 		{ "buildid-list", cmd_buildid_list, 0 },
-		{ "record", cmd_record, 0 },
-		{ "report", cmd_report, 0 },
-		{ "bench", cmd_bench, 0 },
-		{ "stat", cmd_stat, 0 },
-		{ "timechart", cmd_timechart, 0 },
-		{ "top", cmd_top, 0 },
-		{ "annotate", cmd_annotate, 0 },
-		{ "version", cmd_version, 0 },
-		{ "trace", cmd_trace, 0 },
-		{ "sched", cmd_sched, 0 },
-		{ "probe", cmd_probe, 0 },
+		{ "help",	cmd_help,	0 },
+		{ "list",	cmd_list,	0 },
+		{ "record",	cmd_record,	0 },
+		{ "report",	cmd_report,	0 },
+		{ "bench",	cmd_bench,	0 },
+		{ "stat",	cmd_stat,	0 },
+		{ "timechart",	cmd_timechart,	0 },
+		{ "top",	cmd_top,	0 },
+		{ "annotate",	cmd_annotate,	0 },
+		{ "version",	cmd_version,	0 },
+		{ "trace",	cmd_trace,	0 },
+		{ "sched",	cmd_sched,	0 },
+		{ "probe",	cmd_probe,	0 },
+		{ "kmem",	cmd_kmem,	0 },
 	};
 	unsigned int i;
 	static const char ext[] = STRIP_EXTENSION;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#30 lore raw
In reply to Li Zefan
Quoted 7 lines · Li Zefan
---
 tools/perf/Makefile       |    1 +
 tools/perf/builtin-kmem.c |  578 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h      |    1 +
 tools/perf/perf.c         |   27 +-
 4 files changed, 594 insertions(+), 13 deletions(-)
 create mode 100644 tools/perf/builtin-kmem.c

btw., you might want to add it to command-list.txt as well (in a future patch), so that 'kmem' shows up in the default 'perf' output.

Plus a Documentation/perf-kmem.txt file will make sure that 'perf help kmem' and 'perf kmem --help' displays a help page, etc.

Thanks,

Ingo

#21 lore raw
In reply to Pekka Enberg
Quoted 12 lines · Pekka Enberg

Ingo Molnar kirjoitti:

Quoted 4 lines

Regarding patch 2 - can we set some definitive benchmark threshold for that? I.e. a list of must-have features in 'perf kmem' before we can do it? 100% information and analysis equivalency with kmemtrace-user tool?

I'd be interested to hear Eduard's comment on that.

That said, I'll try to find some time to test "perf kmem" and provide feedback on that. I can ACK the patch when I'm happy with the output. :-)

Quoted 5 lines

I'm mostly interested in two scenarios: (1) getting a nice report on worst fragmented call-sites (perf kmem needs symbol lookup) and (2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

The perf.data can be copied over and to get off-side kernel symbol resolution you can specify the kernel vmlinux via -k/--vmlinux to perf report, then perf will look up the symbols from that vmlinux.

Cross word-size data files should work fine - cross-endian probably needs a few fixes.

Plus off-site user-space symbols need more work, right now we dont embedd them in the perf.data. It would need a symbol lookup + embedd-it pass in perf record (perhaps available as a separate 'perf archive' command as well), and some smarts on the reporting side to make use of them. (Probably a copy of all relevant DSOs is what works best - that enables off-site annotate as well.)

But ... even without that, perf is really fast and is supposed to build fine even in minimal (embedded) environments, so you can run it on the embedded board too. That's useful to get live inspection features like 'perf top', 'perf stat' and 'perf probe' anyway.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw
In reply to Li Zefan
Quoted 7 lines · Li Zefan
Quoted 4 lines

(2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Everything needed and machine-specific will be recorded in perf.data, so this should already been supported. I'll try it.

Right now the DSOs are not recorded in the perf.data - but it would be useful to add it and to turn perf.data into a self-sufficient capture of all relevant data, which can be analyzed on any box.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#31 lore raw
In reply to Ingo Molnar
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Li Zefan
---
 tools/perf/Makefile       |    1 +
 tools/perf/builtin-kmem.c |  578 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin.h      |    1 +
 tools/perf/perf.c         |   27 +-
 4 files changed, 594 insertions(+), 13 deletions(-)
 create mode 100644 tools/perf/builtin-kmem.c
Quoted 6 lines

btw., you might want to add it to command-list.txt as well (in a future patch), so that 'kmem' shows up in the default 'perf' output.

Plus a Documentation/perf-kmem.txt file will make sure that 'perf help kmem' and 'perf kmem --help' displays a help page, etc.

I planed to do these after collecting comments and getting positive responses. So sure, I'll post further patches.

author
#12 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Li Zefan
Quoted 4 lines

(2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Quoted 7 lines
Quoted 2 lines

Everything needed and machine-specific will be recorded in perf.data, so this should already been supported. I'll try it.

Right now the DSOs are not recorded in the perf.data - but it would be useful to add it and to turn perf.data into a self-sufficient capture of all relevant data, which can be analyzed on any box.

But still 'perf kmem' should function better than kmemtrace-user, since the latter records no more than raw trace data.

#22 lore raw
In reply to Ingo Molnar

Hi Ingo,

Quoted 4 lines · Ingo Molnar

But ... even without that, perf is really fast and is supposed to build fine even in minimal (embedded) environments, so you can run it on the embedded board too. That's useful to get live inspection features like 'perf top', 'perf stat' and 'perf probe' anyway.

Maybe I'm just too damn lazy but if I don't go through the trouble of building my kernel on the box, I sure don't want to do that for perf either. Anyway, I'm sure we can fix "perf kmem" to support what kmemtrace-user does so it's not an issue.

Pekka

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw
Quoted 11 lines · Pekka Enberg

Hi Ingo,

Quoted 4 lines · Ingo Molnar

But ... even without that, perf is really fast and is supposed to build fine even in minimal (embedded) environments, so you can run it on the embedded board too. That's useful to get live inspection features like 'perf top', 'perf stat' and 'perf probe' anyway.

Maybe I'm just too damn lazy but if I don't go through the trouble of building my kernel on the box, I sure don't want to do that for perf either. [...]

Well you'll need 'perf' on that box anyway, to be able to do 'perf kmem record'.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#24 lore raw

Ingo Molnar kirjoitti:

Quoted 9 lines · Pekka Enberg
Quoted 8 lines

Hi Ingo,

Quoted 4 lines · Ingo Molnar

But ... even without that, perf is really fast and is supposed to build fine even in minimal (embedded) environments, so you can run it on the embedded board too. That's useful to get live inspection features like 'perf top', 'perf stat' and 'perf probe' anyway.

Quoted 5 lines
Quoted 3 lines

Maybe I'm just too damn lazy but if I don't go through the trouble of building my kernel on the box, I sure don't want to do that for perf either. [...]

Well you'll need 'perf' on that box anyway, to be able to do 'perf kmem record'.

/me turns brains on

You're right, of course. With kmemtrace-user, I just copied the raw trace file from /sys/kernel. I wonder if that's a good enough reason to keep kmemtrace bits around?

Pekka

#25 lore raw
Quoted 14 lines · Pekka Enberg

Ingo Molnar kirjoitti:

Quoted 13 lines · Pekka Enberg
Quoted 11 lines

Hi Ingo,

Quoted 4 lines · Ingo Molnar

But ... even without that, perf is really fast and is supposed to build fine even in minimal (embedded) environments, so you can run it on the embedded board too. That's useful to get live inspection features like 'perf top', 'perf stat' and 'perf probe' anyway.

Maybe I'm just too damn lazy but if I don't go through the trouble of building my kernel on the box, I sure don't want to do that for perf either. [...]

Quoted 8 lines
Quoted 2 lines

Well you'll need 'perf' on that box anyway, to be able to do 'perf kmem record'.

/me turns brains on

You're right, of course. With kmemtrace-user, I just copied the raw trace file from /sys/kernel. I wonder if that's a good enough reason to keep kmemtrace bits around?

Not really. If then a light-weight recording app could be made but i'd rather wait for actual usecases to pop up.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
In reply to Ingo Molnar

Em Fri, Nov 20, 2009 at 10:03:53AM +0100, Ingo Molnar escreveu:

Quoted 8 lines · Li Zefan
Quoted 6 lines
Quoted 5 lines

(2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Quoted 6 lines
Quoted 2 lines

Everything needed and machine-specific will be recorded in perf.data, so this should already been supported. I'll try it.

Right now the DSOs are not recorded in the perf.data - but it would be useful to add it and to turn perf.data into a self-sufficient capture of all relevant data, which can be analyzed on any box.

Well, the DSOs are recorded in perf.data, just not its symtabs, but now we have buildids, so we can ask for them to be installed on the other machine and it'll all work. Or should. :)

For instance:

[root@doppio linux-2.6-tip]# perf buildid-list -i perf.data | egrep 'vmlinux|nfs|libc-' ec8dd400904ddfcac8b1c343263a790f977159dc /lib64/libc-2.10.1.so 0da49504693a200583fda6f1b949e6d2f799e692 /usr/lib64/libnfsidmap_nsswitch.so.0.0.0 c90269c87eaf08559012a9fa29f60780743360cd /usr/lib64/libnfsidmap.so.0.3.0 18e7cc53db62a7d35e9d6f6c9ddc23017d38ee9a vmlinux 3982866276471cde6ac5821fdced42a7b1bfd848 [nfs] 1489007276a50005753e730198fd93dd05b2082f [nfsd] 5a128f082fe7fdcab6fb5d1b71935accb1f34383 [nfs_acl]
[root@doppio linux-2.6-tip]#

Now if I ask that the buildid for /usr/lib64/libnfsidmap.so.0.3.0 above to be installed, like this:

[root@doppio linux-2.6-tip]# yum install /usr/lib/debug/.build-id/c9/0269c87eaf08559012a9fa29f60780743360cd Loaded plugins: auto-update-debuginfo, refresh-packagekit
Found 44 installed debuginfo package(s)
Enabling fedora-debuginfo: Fedora 11 - x86_64 - Debug
Reading repository metadata in from local files
Enabling updates-debuginfo: Fedora 11 - x86_64 - Updates - Debug
Reading repository metadata in from local files
Setting up Install Process
Importing additional filelist information
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils-lib-debuginfo.x86_64 0:1.1.4-6.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================
Package Arch Version Repository Size
========================================================================
Installing:
nfs-utils-lib-debuginfo x86_64 1.1.4-6.fc11 fedora-debuginfo 174 k

Transaction Summary
========================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 174 k
Is this ok [y/N]:

So now we have:

1) 'perf record' records the build-ids into perf.data
2) 'perf buildid-list' list them, distro specific porcelain needed to do the equivalent to the yum install above.
3) 'perf report' will only use the symtab in a file that has the matching build-id, if a build-id is found in the perf.data header for a particular DSO.

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

I'm working on some of these aspects, but most of the infrastructure is alreadu in tip.

- Arnaldo

#14 lore raw
Quoted 74 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 20, 2009 at 10:03:53AM +0100, Ingo Molnar escreveu:

Quoted 8 lines · Li Zefan
Quoted 6 lines
Quoted 5 lines

(2) doing "perf kmem record" on machine A (think embedded here) and then "perf kmem report" on machine B. I haven't tried kmemtrace-user for a while but it did support both of them quite nicely at some point.

Quoted 6 lines
Quoted 2 lines

Everything needed and machine-specific will be recorded in perf.data, so this should already been supported. I'll try it.

Right now the DSOs are not recorded in the perf.data - but it would be useful to add it and to turn perf.data into a self-sufficient capture of all relevant data, which can be analyzed on any box.

Well, the DSOs are recorded in perf.data, just not its symtabs, but now we have buildids, so we can ask for them to be installed on the other machine and it'll all work. Or should. :)

For instance:

[root@doppio linux-2.6-tip]# perf buildid-list -i perf.data | egrep 'vmlinux|nfs|libc-' ec8dd400904ddfcac8b1c343263a790f977159dc /lib64/libc-2.10.1.so 0da49504693a200583fda6f1b949e6d2f799e692 /usr/lib64/libnfsidmap_nsswitch.so.0.0.0 c90269c87eaf08559012a9fa29f60780743360cd /usr/lib64/libnfsidmap.so.0.3.0 18e7cc53db62a7d35e9d6f6c9ddc23017d38ee9a vmlinux 3982866276471cde6ac5821fdced42a7b1bfd848 [nfs] 1489007276a50005753e730198fd93dd05b2082f [nfsd] 5a128f082fe7fdcab6fb5d1b71935accb1f34383 [nfs_acl]
[root@doppio linux-2.6-tip]#

Now if I ask that the buildid for /usr/lib64/libnfsidmap.so.0.3.0 above to be installed, like this:

[root@doppio linux-2.6-tip]# yum install /usr/lib/debug/.build-id/c9/0269c87eaf08559012a9fa29f60780743360cd Loaded plugins: auto-update-debuginfo, refresh-packagekit
Found 44 installed debuginfo package(s)
Enabling fedora-debuginfo: Fedora 11 - x86_64 - Debug
Reading repository metadata in from local files
Enabling updates-debuginfo: Fedora 11 - x86_64 - Updates - Debug
Reading repository metadata in from local files
Setting up Install Process
Importing additional filelist information
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils-lib-debuginfo.x86_64 0:1.1.4-6.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================
Package Arch Version Repository Size
========================================================================
Installing:
nfs-utils-lib-debuginfo x86_64 1.1.4-6.fc11 fedora-debuginfo 174 k

Transaction Summary
========================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 174 k
Is this ok [y/N]:

So now we have:

1) 'perf record' records the build-ids into perf.data
2) 'perf buildid-list' list them, distro specific porcelain needed to do the equivalent to the yum install above.
3) 'perf report' will only use the symtab in a file that has the matching build-id, if a build-id is found in the perf.data header for a particular DSO.

Quoted 3 lines

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

But what do we do if we have another box that runs say on a MIPS CPU, uses some minimal distro - and copy that perf.data over to an x86 box.

The idea is there to be some new mode of perf.data where all the relevant DSO contents (symtabs but also sections with instructions for perf annotate to work) are copied into perf.data, during or after data capture - on the box that does the recording.

Once we have everything embedded in the perf.data, analysis passes only have to work based on that particular perf.data - no external data.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Em Fri, Nov 20, 2009 at 05:41:10PM +0100, Ingo Molnar escreveu:

Quoted 6 lines
Quoted 3 lines

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

But what do we do if we have another box that runs say on a MIPS CPU, uses some minimal distro - and copy that perf.data over to an x86 box.

There would be no problem, it would be just a matter of installing the right -debuginfo packages, for MIPS.

Or the original, unstripped FS image sent to the machine with the MIPS cpu, if there aren't -debuginfo packages.

Either one, the right DSOs would be found by the buildids.

There are other scenarios, like a binary that gets updated while a long running perf record session runs, the way to differentiate between the two DSOs wouldn't be the name, but the buildid.

Quoted 7 lines

The idea is there to be some new mode of perf.data where all the relevant DSO contents (symtabs but also sections with instructions for perf annotate to work) are copied into perf.data, during or after data capture - on the box that does the recording.

Once we have everything embedded in the perf.data, analysis passes only have to work based on that particular perf.data - no external data.

Well, we can that, additionally, but think about stripped binaries, we would lose potentially a lot because the symtabs on that small machine would have poorer symtabs than the ones in an unstriped binary (or in a -debuginfo package).

- Arnaldo

#16 lore raw
Quoted 10 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 20, 2009 at 05:41:10PM +0100, Ingo Molnar escreveu:

Quoted 6 lines
Quoted 3 lines

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

But what do we do if we have another box that runs say on a MIPS CPU, uses some minimal distro - and copy that perf.data over to an x86 box.

There would be no problem, it would be just a matter of installing the right -debuginfo packages, for MIPS.

I havent tried this - is this really possible to do on an x86 box, with a typical distro? Can i install say Fedora PowerPC debuginfo packages on an x86 box, while also having the x86 debuginfo packages there?

Quoted 14 lines

Or the original, unstripped FS image sent to the machine with the MIPS cpu, if there aren't -debuginfo packages.

Either one, the right DSOs would be found by the buildids.

There are other scenarios, like a binary that gets updated while a long running perf record session runs, the way to differentiate between the two DSOs wouldn't be the name, but the buildid.

Quoted 5 lines

The idea is there to be some new mode of perf.data where all the relevant DSO contents (symtabs but also sections with instructions for perf annotate to work) are copied into perf.data, during or after data capture - on the box that does the recording.

Quoted 7 lines
Quoted 2 lines

Once we have everything embedded in the perf.data, analysis passes only have to work based on that particular perf.data - no external data.

Well, we can that, additionally, but think about stripped binaries, we would lose potentially a lot because the symtabs on that small machine would have poorer symtabs than the ones in an unstriped binary (or in a -debuginfo package).

We should definitely use the widest and best quality information we can
- if it's available.

So even if we 'inline' any information from the box, if there's better info available at the time of analysis, we should use that too.

Basically what matters is the principle of 'what is possible'.

If a user records on a box and analyses on a different box, and we end up not doing something (and printing an error or displaying an empty profile) that could reasonably have been done, then the user will be unhappy and we might lose that user.

The user wont be unhappy about us using a big set of data sources that we can recover information from transparently. The user will be unhappy if we insist on (and force) a certain form of information source - such as debuginfo.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#17 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Arnaldo Carvalho de Melo

Em Fri, Nov 20, 2009 at 05:41:10PM +0100, Ingo Molnar escreveu:

Quoted 6 lines
Quoted 3 lines

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

But what do we do if we have another box that runs say on a MIPS CPU, uses some minimal distro - and copy that perf.data over to an x86 box.

Quoted 6 lines
Quoted 2 lines

There would be no problem, it would be just a matter of installing the right -debuginfo packages, for MIPS.

I havent tried this - is this really possible to do on an x86 box, with a typical distro? Can i install say Fedora PowerPC debuginfo packages on an x86 box, while also having the x86 debuginfo packages there?

The best option would be to allow to specify a chroot parameter, where we can specify the embedded root filesystem on out machine.

I'm not even sure embedded distros even have this separate debug package crazyness, you simply build the distro with or without debuginfo.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw
Quoted 11 lines · Peter Zijlstra
Quoted 4 lines

I havent tried this - is this really possible to do on an x86 box, with a typical distro? Can i install say Fedora PowerPC debuginfo packages on an x86 box, while also having the x86 debuginfo packages there?

The best option would be to allow to specify a chroot parameter, where we can specify the embedded root filesystem on out machine.

I'm not even sure embedded distros even have this separate debug package crazyness, you simply build the distro with or without debuginfo.

yes - we could use -R/--root (which opreport has as well), as a mandatory path prefix to all DSO/debuginfo searches.

Ingo

#20 lore raw
In reply to Ingo Molnar

Em Mon, Nov 23, 2009 at 07:51:10AM +0100, Ingo Molnar escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 9 lines

Em Fri, Nov 20, 2009 at 05:41:10PM +0100, Ingo Molnar escreveu:

Quoted 6 lines
Quoted 3 lines

So we have a mechanism that is already present in several distros (build-id), that is in the kernel build process since ~2.6.23, and that avoids using mismatching DSOs when resolving symbols.

But what do we do if we have another box that runs say on a MIPS CPU, uses some minimal distro - and copy that perf.data over to an x86 box.

Quoted 6 lines
Quoted 2 lines

There would be no problem, it would be just a matter of installing the right -debuginfo packages, for MIPS.

I havent tried this - is this really possible to do on an x86 box, with a typical distro? Can i install say Fedora PowerPC debuginfo packages on an x86 box, while also having the x86 debuginfo packages there?

I should have added "in theory", as I haven't tested this as well using the current tools, but it should :)

Quoted 35 lines
Quoted 14 lines

Or the original, unstripped FS image sent to the machine with the MIPS cpu, if there aren't -debuginfo packages.

Either one, the right DSOs would be found by the buildids.

There are other scenarios, like a binary that gets updated while a long running perf record session runs, the way to differentiate between the two DSOs wouldn't be the name, but the buildid.

Quoted 5 lines

The idea is there to be some new mode of perf.data where all the relevant DSO contents (symtabs but also sections with instructions for perf annotate to work) are copied into perf.data, during or after data capture - on the box that does the recording.

Quoted 7 lines
Quoted 2 lines

Once we have everything embedded in the perf.data, analysis passes only have to work based on that particular perf.data - no external data.

Well, we can that, additionally, but think about stripped binaries, we would lose potentially a lot because the symtabs on that small machine would have poorer symtabs than the ones in an unstriped binary (or in a -debuginfo package).

We should definitely use the widest and best quality information we can
- if it's available.

So even if we 'inline' any information from the box, if there's better info available at the time of analysis, we should use that too.

Basically what matters is the principle of 'what is possible'.

If a user records on a box and analyses on a different box, and we end up not doing something (and printing an error or displaying an empty profile) that could reasonably have been done, then the user will be unhappy and we might lose that user.

Quoted 4 lines

The user wont be unhappy about us using a big set of data sources that we can recover information from transparently. The user will be unhappy if we insist on (and force) a certain form of information source - such as debuginfo.

Sure thing, I'm thinking about how to encode the perf.data file inside an ELF section while merging all symtabs to reduce size by sharing the strings table, etc.

The dso__load routine already does that fallback from what is best (debuginfo packages) to what is available (the symtab, dynsym tables in the DSO itself), its just a matter of efficiently encoding the symtabs into the perf.data file and that will be another source of symbols if the preferred one (debuginfo) is not available.

- Arnaldo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw
In reply to Peter Zijlstra

Em Mon, Nov 23, 2009 at 08:22:21AM +0100, Peter Zijlstra escreveu:

Quoted 7 lines · Ingo Molnar
Quoted 3 lines

I havent tried this - is this really possible to do on an x86 box, with a typical distro? Can i install say Fedora PowerPC debuginfo packages on an x86 box, while also having the x86 debuginfo packages there?

The best option would be to allow to specify a chroot parameter, where we can specify the embedded root filesystem on out machine.

yeah, I'm working now on a vmlinux_path, so that the symbol machinery in perf looks at /lib/module/uname -r/build/vmlinux, /usr/lib/debug/lib/modules/uname -r/vmlinux, ./vmlinux as a default or in getenv("VMLINUX_PATH") if set. Being able to specify a SYMTAB_PREFIX_PATH also should be possible.

Quoted 2 lines

I'm not even sure embedded distros even have this separate debug package crazyness, you simply build the distro with or without debuginfo.

Whatever crazyness people usually do to find the files with matching, richer symtabs we should support :)

- Arnaldo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#26 lore raw
In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar
Quoted 4 lines

You're right, of course. With kmemtrace-user, I just copied the raw trace file from /sys/kernel. I wonder if that's a good enough reason to keep kmemtrace bits around?

Not really. If then a light-weight recording app could be made but i'd rather wait for actual usecases to pop up.

Hmm, but isn't this an actual use case?

-- Steve

#27 lore raw
Quoted 10 lines · Steven Rostedt
Quoted 7 lines · Ingo Molnar
Quoted 4 lines

You're right, of course. With kmemtrace-user, I just copied the raw trace file from /sys/kernel. I wonder if that's a good enough reason to keep kmemtrace bits around?

Not really. If then a light-weight recording app could be made but i'd rather wait for actual usecases to pop up.

Hmm, but isn't this an actual use case?

Not really - perf record is pretty lightweight and you'd want perf for hands-on stats anyway.

Ingo

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>