Skip to contentSkip to conversation

perf: add new PERF_RECORD_MMAP2 record type

PATCH Superseded Stephane Eranian 3 participants 10 messages Aug 13, 2013 – Aug 21, 2013 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover perf: add new PERF_RECORD_MMAP2 record type

This patch series introduces a new record type for mmaps. This new record is called PERF_RECORD_MMAP2. It provides more information than the existing PERF_RECORD_MMAP. For each file-backed or shared memory segment mapping, the device major, minor and the inode numbers are recorded. This triplet may be used to disambiguate virtual file-backed mappings between processes.

The triplet could not be fitted into the existing PERF_RECORD_MMAP record without breaking backward compatibility. This is why we introduce this new record type.

To activate this new record type, the mmap2 bit must be set in perf_event_attr struct. It supersedes the mmap bit, but is distinct from mmap_data. For mmap2 data records, both mmap2 and mmap_data must be set. For code, only mmap2 must be set.

The series also provides the perf tool support for this new MMAP2 record type. Perf record activates this mode by default. The maj, min, ino are not yet exploited by perf report but will be in subsequent perf tools.

Patch is relative to tip.git

---

Stephane Eranian (2):
perf: add attr->mmap2 attribute to an event
perf tools: add attr->mmap2 support

 include/uapi/linux/perf_event.h |   22 +++++++++++++++-
 kernel/events/core.c            |   41 ++++++++++++++++++++++++++---
 tools/perf/builtin-annotate.c   |    1 +
 tools/perf/builtin-inject.c     |   15 +++++++++++
 tools/perf/builtin-mem.c        |    1 +
 tools/perf/builtin-report.c     |    1 +
 tools/perf/builtin-script.c     |    1 +
 tools/perf/util/build-id.c      |    1 +
 tools/perf/util/event.c         |   55 ++++++++++++++++++++++++++++++---------
 tools/perf/util/event.h         |   18 +++++++++++++
 tools/perf/util/evsel.c         |    5 ++--
 tools/perf/util/header.c        |    3 +++
 tools/perf/util/machine.c       |   51 +++++++++++++++++++++++++++++++++++-
 tools/perf/util/machine.h       |    1 +
 tools/perf/util/map.c           |    7 ++++-
 tools/perf/util/map.h           |    6 +++--
 tools/perf/util/session.c       |   25 +++++++++++++++++-
 tools/perf/util/tool.h          |    1 +
 18 files changed, 231 insertions(+), 24 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 perf: add attr->mmap2 attribute to an event

Adds a new PERF_RECORD_MMAP2 record type.

Used to request mmap records with more information about the mapping, including device major, minor and the inode number for mappings associated with files or shared memory segments. Works for code and data (with attr->mmap_data set).

Existing PERF_RECORD_MMAP record is unmodified by this patch.

---
 include/uapi/linux/perf_event.h |   22 ++++++++++++++++++++-
 kernel/events/core.c            |   41 +++++++++++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 5 deletions(-)
include/uapi/linux/perf_event.h +21 -1
index d80d223..1eec8f5 100644
@@ -275,8 +275,9 @@ struct perf_event_attr {
 
 				exclude_callchain_kernel : 1, /* exclude kernel callchains */
 				exclude_callchain_user   : 1, /* exclude user callchains */
+				mmap2          :  1, /* include mmap with inode data     */
 
-				__reserved_1   : 41;
+				__reserved_1   : 40;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
@@ -638,6 +639,25 @@ enum perf_event_type {
 	 */
 	PERF_RECORD_SAMPLE			= 9,
 
+	/*
+	 * The MMAP2 records are an augmented version of MMAP, they add
+	 * maj, min, ino numbers to be used to uniquely identify each mapping
+	 *
+	 * struct {
+	 *	struct perf_event_header	header;
+	 *
+	 *	u32				pid, tid;
+	 *	u64				addr;
+	 *	u64				len;
+	 *	u64				pgoff;
+	 *	u32				maj;
+	 *	u32				min;
+	 *	u64				ino;
+	 *	char				filename[];
+	 * };
+	 */
+	PERF_RECORD_MMAP2			= 10,
+
 	PERF_RECORD_MAX,			/* non-ABI */
 };
 
kernel/events/core.c +37 -4

107 lines not on this page · raw message

Signature · 1 line
1.7.9.5
maintainer
#2 lore raw

Re: [PATCH v1 1/2] perf: add attr->mmap2 attribute to an event

Quoted 9 lines · Stephane Eranian
include/uapi/linux/perf_event.h +5 -0
@@ -638,6 +639,25 @@ enum perf_event_type {
 	 */
 	PERF_RECORD_SAMPLE			= 9,
 
+	/*
+	 * The MMAP2 records are an augmented version of MMAP, they add
+	 * maj, min, ino numbers to be used to uniquely identify each mapping
+	 *
+	 * struct {

include/uapi/linux/perf_event.h enum perf_event_type { · line 656

Quoted 10 lines
include/uapi/linux/perf_event.h +10 -0
+	 *	struct perf_event_header	header;
+	 *
+	 *	u32				pid, tid;
+	 *	u64				addr;
+	 *	u64				len;
+	 *	u64				pgoff;
+	 *	u32				maj;
+	 *	u32				min;
+	 *	u64				ino;
+	 *	char				filename[];

Did you forget the sample_id stuff?

		struct sample_id		sample_id;
Quoted 6 lines
include/uapi/linux/perf_event.h +4 -0
+	 * };
+	 */
+	PERF_RECORD_MMAP2			= 10,
+
 	PERF_RECORD_MAX,			/* non-ABI */
 };
#3 lore raw

Re: [PATCH v1 1/2] perf: add attr->mmap2 attribute to an event

Quoted 24 lines · Peter Zijlstra
Quoted 9 lines · Stephane Eranian
include/uapi/linux/perf_event.h +5 -0
@@ -638,6 +639,25 @@ enum perf_event_type {
       */
      PERF_RECORD_SAMPLE                      = 9,
 
+     /*
+      * The MMAP2 records are an augmented version of MMAP, they add
+      * maj, min, ino numbers to be used to uniquely identify each mapping
+      *
+      * struct {

include/uapi/linux/perf_event.h enum perf_event_type { · line 656

Quoted 10 lines
include/uapi/linux/perf_event.h +10 -0
+      *      struct perf_event_header        header;
+      *
+      *      u32                             pid, tid;
+      *      u64                             addr;
+      *      u64                             len;
+      *      u64                             pgoff;
+      *      u32                             maj;
+      *      u32                             min;
+      *      u64                             ino;
+      *      char                            filename[];

Did you forget the sample_id stuff?

Quoted 2 lines
                struct sample_id                sample_id;

Ok, will add that and the i_generation field.

#4 lore raw

Re: [PATCH v1 1/2] perf: add attr->mmap2 attribute to an event

Quoted 25 lines · Stephane Eranian
Quoted 24 lines · Peter Zijlstra
Quoted 9 lines · Stephane Eranian
include/uapi/linux/perf_event.h +5 -0
@@ -638,6 +639,25 @@ enum perf_event_type {
       */
      PERF_RECORD_SAMPLE                      = 9,
 
+     /*
+      * The MMAP2 records are an augmented version of MMAP, they add
+      * maj, min, ino numbers to be used to uniquely identify each mapping
+      *
+      * struct {

include/uapi/linux/perf_event.h enum perf_event_type { · line 656

Quoted 10 lines
include/uapi/linux/perf_event.h +10 -0
+      *      struct perf_event_header        header;
+      *
+      *      u32                             pid, tid;
+      *      u64                             addr;
+      *      u64                             len;
+      *      u64                             pgoff;
+      *      u32                             maj;
+      *      u32                             min;
+      *      u64                             ino;
+      *      char                            filename[];

Did you forget the sample_id stuff?

Quoted 3 lines
Quoted 2 lines
                struct sample_id                sample_id;

Ok, will add that and the i_generation field.

Added that now, works fine. Except it won't be availa when synthesizing MMAP records from /proc/PID/maps because it is not displayed there. There is not much we can do about this. And of course, there is not i_generation for kernel level ELF images.

#5 lore raw

Re: [PATCH v1 1/2] perf: add attr->mmap2 attribute to an event

In reply to Peter Zijlstra
Quoted 25 lines · Peter Zijlstra
Quoted 9 lines · Stephane Eranian
include/uapi/linux/perf_event.h +5 -0
@@ -638,6 +639,25 @@ enum perf_event_type {
       */
      PERF_RECORD_SAMPLE                      = 9,
 
+     /*
+      * The MMAP2 records are an augmented version of MMAP, they add
+      * maj, min, ino numbers to be used to uniquely identify each mapping
+      *
+      * struct {

include/uapi/linux/perf_event.h enum perf_event_type { · line 656

Quoted 10 lines
include/uapi/linux/perf_event.h +10 -0
+      *      struct perf_event_header        header;
+      *
+      *      u32                             pid, tid;
+      *      u64                             addr;
+      *      u64                             len;
+      *      u64                             pgoff;
+      *      u32                             maj;
+      *      u32                             min;
+      *      u64                             ino;
+      *      char                            filename[];

Did you forget the sample_id stuff?

Quoted 2 lines
                struct sample_id                sample_id;

This is added automatically by the kernel if attr->sample_id_all is set. I checked the perf tool. It enables this when you're sampling on more than one event. So everything works as expected. I assume you comment was about adding the sample_id in the description of the struct. I will add that.

Quoted 7 lines
Quoted 7 lines
include/uapi/linux/perf_event.h +4 -0
+      * };
+      */
+     PERF_RECORD_MMAP2                       = 10,
+
      PERF_RECORD_MAX,                        /* non-ABI */
 };
#6 lore raw

PATCH 2/2 perf tools: add attr->mmap2 support

In reply to Stephane Eranian

This patch adds support for the new PERF_RECORD_MMAP2 record type exposed by the kernel. This is an extended PERF_RECORD_MMAP record. It adds for each file-backed mapping the device major, minor number and the inode number. This triplet uniquely identifies the source of a file-backed mapping. It can be used to detect identical virtual mappings between processes for instance.

The patch will prefer MMAP2 over MMAP.

---
 tools/perf/builtin-annotate.c |    1 +
 tools/perf/builtin-inject.c   |   15 +++++++++++
 tools/perf/builtin-mem.c      |    1 +
 tools/perf/builtin-report.c   |    1 +
 tools/perf/builtin-script.c   |    1 +
 tools/perf/util/build-id.c    |    1 +
 tools/perf/util/event.c       |   55 ++++++++++++++++++++++++++++++++---------
 tools/perf/util/event.h       |   18 ++++++++++++++
 tools/perf/util/evsel.c       |    5 ++--
 tools/perf/util/header.c      |    3 +++
 tools/perf/util/machine.c     |   51 +++++++++++++++++++++++++++++++++++++-
 tools/perf/util/machine.h     |    1 +
 tools/perf/util/map.c         |    7 +++++-
 tools/perf/util/map.h         |    6 +++--
 tools/perf/util/session.c     |   25 ++++++++++++++++++-
 tools/perf/util/tool.h        |    1 +
 16 files changed, 173 insertions(+), 19 deletions(-)
tools/perf/builtin-annotate.c +1 -0
index db491e9..61e1781 100644
@@ -276,6 +276,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		.tool = {
 			.sample	= process_sample_event,
 			.mmap	= perf_event__process_mmap,
+			.mmap2	= perf_event__process_mmap2,
 			.comm	= perf_event__process_comm,
 			.exit	= perf_event__process_exit,
 			.fork	= perf_event__process_fork,
tools/perf/builtin-inject.c +15 -0
index f012a98..4aeed15 100644
@@ -123,6 +123,19 @@ static int perf_event__repipe_mmap(struct perf_tool *tool,
 	return err;
 }
 
+static int perf_event__repipe_mmap2(struct perf_tool *tool,
+				   union perf_event *event,
+				   struct perf_sample *sample,
+				   struct machine *machine)
+{
+	int err;
+
+	err = perf_event__process_mmap2(tool, event, sample, machine);
+	perf_event__repipe(tool, event, sample, machine);
+
+	return err;
+}
+
 static int perf_event__repipe_fork(struct perf_tool *tool,
 				   union perf_event *event,
 				   struct perf_sample *sample,
@@ -337,6 +350,7 @@ static int __cmd_inject(struct perf_inject *inject)
 
 	if (inject->build_ids || inject->sched_stat) {
 		inject->tool.mmap	  = perf_event__repipe_mmap;
+		inject->tool.mmap2	  = perf_event__repipe_mmap2;
 		inject->tool.fork	  = perf_event__repipe_fork;
 		inject->tool.tracing_data = perf_event__repipe_tracing_data;
 	}
@@ -388,6 +402,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 		.tool = {
 			.sample		= perf_event__repipe_sample,
 			.mmap		= perf_event__repipe,
+			.mmap2		= perf_event__repipe,
 			.comm		= perf_event__repipe,
 			.fork		= perf_event__repipe,
 			.exit		= perf_event__repipe,
tools/perf/builtin-mem.c +1 -0
index a8ff6d2..33022ff 100644
@@ -192,6 +192,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
 		.tool = {
 			.sample		= process_sample_event,
 			.mmap		= perf_event__process_mmap,
+			.mmap2		= perf_event__process_mmap2,
 			.comm		= perf_event__process_comm,
 			.lost		= perf_event__process_lost,
 			.fork		= perf_event__process_fork,
tools/perf/builtin-report.c +1 -0
index d785d89..ac1dd18 100644
@@ -746,6 +746,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		.tool = {
 			.sample		 = process_sample_event,
 			.mmap		 = perf_event__process_mmap,
+			.mmap2		 = perf_event__process_mmap2,
 			.comm		 = perf_event__process_comm,
 			.exit		 = perf_event__process_exit,
 			.fork		 = perf_event__process_fork,
tools/perf/builtin-script.c +1 -0
index cd616ff..fe40b93 100644
@@ -520,6 +520,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 static struct perf_tool perf_script = {
 	.sample		 = process_sample_event,
 	.mmap		 = perf_event__process_mmap,
+	.mmap2		 = perf_event__process_mmap2,
 	.comm		 = perf_event__process_comm,
 	.exit		 = perf_event__process_exit,
 	.fork		 = perf_event__process_fork,
tools/perf/util/build-id.c +1 -0
index 3a0f508..8127f65 100644
@@ -64,6 +64,7 @@ static int perf_event__exit_del_thread(struct perf_tool *tool __maybe_unused,
 struct perf_tool build_id__mark_dso_hit_ops = {
 	.sample	= build_id__mark_dso_hit,
 	.mmap	= perf_event__process_mmap,
+	.mmap2	= perf_event__process_mmap2,
 	.fork	= perf_event__process_fork,
 	.exit	= perf_event__exit_del_thread,
 	.attr		 = perf_event__process_attr,
tools/perf/util/event.c +43 -12

105 lines not on this page · raw message

tools/perf/util/event.h +18 -0
index 6119a64..747622f 100644
@@ -27,6 +27,18 @@ struct mmap_event {
 	char filename[PATH_MAX];
 };
 
+struct mmap2_event {
+	struct perf_event_header header;
+	u32 pid, tid;
+	u64 start;
+	u64 len;
+	u64 pgoff;
+	u32 maj;
+	u32 min;
+	u64 ino;
+	char filename[PATH_MAX];
+};
+
 struct comm_event {
 	struct perf_event_header header;
 	u32 pid, tid;
@@ -168,6 +180,7 @@ union perf_event {
 	struct perf_event_header	header;
 	struct ip_event			ip;
 	struct mmap_event		mmap;
+	struct mmap2_event		mmap2;
 	struct comm_event		comm;
 	struct fork_event		fork;
 	struct lost_event		lost;
@@ -217,6 +230,10 @@ int perf_event__process_mmap(struct perf_tool *tool,
 			     union perf_event *event,
 			     struct perf_sample *sample,
 			     struct machine *machine);
+int perf_event__process_mmap2(struct perf_tool *tool,
+			     union perf_event *event,
+			     struct perf_sample *sample,
+			     struct machine *machine);
 int perf_event__process_fork(struct perf_tool *tool,
 			     union perf_event *event,
 			     struct perf_sample *sample,
@@ -245,6 +262,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
 
 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
+size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
 
tools/perf/util/evsel.c +3 -2
index 960394e..2bc0e4d 100644
@@ -598,8 +598,9 @@ void perf_evsel__config(struct perf_evsel *evsel,
 	if (opts->sample_weight)
 		attr->sample_type	|= PERF_SAMPLE_WEIGHT;
 
-	attr->mmap = track;
-	attr->comm = track;
+	attr->mmap  = track;
+	attr->mmap2 = track;
+	attr->comm  = track;
 
 	/*
 	 * XXX see the function comment above
tools/perf/util/header.c +3 -0
index f558f83..72ec25c 100644
@@ -1348,6 +1348,9 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp)
 
 		fprintf(fp, ", precise_ip = %d", evsel->attr.precise_ip);
 
+		fprintf(fp, ", attr_mmap2 = %d", evsel->attr.mmap2);
+		fprintf(fp, ", attr_mmap  = %d", evsel->attr.mmap);
+		fprintf(fp, ", attr_mmap_data = %d", evsel->attr.mmap_data);
 		if (evsel->ids) {
 			fprintf(fp, ", id = {");
 			for (j = 0, id = evsel->id; j < evsel->ids; j++, id++) {
tools/perf/util/machine.c +50 -1

69 lines not on this page · raw message

tools/perf/util/machine.h +1 -0
index 5bb6244..195631a 100644
@@ -44,6 +44,7 @@ int machine__process_exit_event(struct machine *machine, union perf_event *event
 int machine__process_fork_event(struct machine *machine, union perf_event *event);
 int machine__process_lost_event(struct machine *machine, union perf_event *event);
 int machine__process_mmap_event(struct machine *machine, union perf_event *event);
+int machine__process_mmap2_event(struct machine *machine, union perf_event *event);
 int machine__process_event(struct machine *machine, union perf_event *event);
 
 typedef void (*machine__process_t)(struct machine *machine, void *data);
tools/perf/util/map.c +6 -1
index 9e8304c..948e988 100644
@@ -48,7 +48,8 @@ void map__init(struct map *map, enum map_type type,
 }
 
 struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
-		     u64 pgoff, u32 pid, char *filename,
+		     u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
+		     char *filename,
 		     enum map_type type)
 {
 	struct map *map = malloc(sizeof(*map));
@@ -62,6 +63,10 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
 		vdso = is_vdso_map(filename);
 		no_dso = is_no_dso_memory(filename);
 
+		map->maj = d_maj;
+		map->min = d_min;
+		map->ino = ino;
+
 		if (anon) {
 			snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid);
 			filename = newfilename;
tools/perf/util/map.h +4 -2
index 2cc93cb..782fbaa 100644
@@ -36,6 +36,8 @@ struct map {
 	bool			erange_warned;
 	u32			priv;
 	u64			pgoff;
+	u32			maj, min; /* only valid from MMAP2 record */
+	u64			ino;      /* only valid from MMAP2 record */
 
 	/* ip -> dso rip */
 	u64			(*map_ip)(struct map *, u64);
@@ -88,8 +90,8 @@ typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
 void map__init(struct map *map, enum map_type type,
 	       u64 start, u64 end, u64 pgoff, struct dso *dso);
 struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
-		     u64 pgoff, u32 pid, char *filename,
-		     enum map_type type);
+		     u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
+		     char *filename, enum map_type type);
 struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
 void map__delete(struct map *map);
 struct map *map__clone(struct map *map);
tools/perf/util/session.c +24 -1
index dedaeb2..dd84077 100644
@@ -351,6 +351,25 @@ static void perf_event__mmap_swap(union perf_event *event,
 	}
 }
 
+static void perf_event__mmap2_swap(union perf_event *event,
+				  bool sample_id_all)
+{
+	event->mmap2.pid   = bswap_32(event->mmap2.pid);
+	event->mmap2.tid   = bswap_32(event->mmap2.tid);
+	event->mmap2.start = bswap_64(event->mmap2.start);
+	event->mmap2.len   = bswap_64(event->mmap2.len);
+	event->mmap2.pgoff = bswap_64(event->mmap2.pgoff);
+	event->mmap2.maj   = bswap_32(event->mmap2.maj);
+	event->mmap2.min   = bswap_32(event->mmap2.min);
+	event->mmap2.ino   = bswap_64(event->mmap2.ino);
+
+	if (sample_id_all) {
+		void *data = &event->mmap2.filename;
+
+		data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
+		swap_sample_id_all(event, data);
+	}
+}
 static void perf_event__task_swap(union perf_event *event, bool sample_id_all)
 {
 	event->fork.pid	 = bswap_32(event->fork.pid);
@@ -455,6 +474,7 @@ typedef void (*perf_event__swap_op)(union perf_event *event,
 
 static perf_event__swap_op perf_event__swap_ops[] = {
 	[PERF_RECORD_MMAP]		  = perf_event__mmap_swap,
+	[PERF_RECORD_MMAP2]		  = perf_event__mmap2_swap,
 	[PERF_RECORD_COMM]		  = perf_event__comm_swap,
 	[PERF_RECORD_FORK]		  = perf_event__task_swap,
 	[PERF_RECORD_EXIT]		  = perf_event__task_swap,
@@ -849,7 +869,8 @@ static struct machine *
 	     (cpumode == PERF_RECORD_MISC_GUEST_USER))) {
 		u32 pid;
 
-		if (event->header.type == PERF_RECORD_MMAP)
+		if (event->header.type == PERF_RECORD_MMAP
+		    || event->header.type == PERF_RECORD_MMAP2)
 			pid = event->mmap.pid;
 		else
 			pid = event->ip.pid;
@@ -975,6 +996,8 @@ static int perf_session_deliver_event(struct perf_session *session,
 						    sample, evsel, machine);
 	case PERF_RECORD_MMAP:
 		return tool->mmap(tool, event, sample, machine);
+	case PERF_RECORD_MMAP2:
+		return tool->mmap2(tool, event, sample, machine);
 	case PERF_RECORD_COMM:
 		return tool->comm(tool, event, sample, machine);
 	case PERF_RECORD_FORK:
tools/perf/util/tool.h +1 -0
index 62b16b6..4385816 100644
@@ -29,6 +29,7 @@ struct perf_tool {
 	event_sample	sample,
 			read;
 	event_op	mmap,
+			mmap2,
 			comm,
 			fork,
 			exit,
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v1 2/2] perf tools: add attr->mmap2 support

Quoted 7 lines · Stephane Eranian

This patch adds support for the new PERF_RECORD_MMAP2 record type exposed by the kernel. This is an extended PERF_RECORD_MMAP record. It adds for each file-backed mapping the device major, minor number and the inode number. This triplet uniquely identifies the source of a file-backed mapping. It can be used to detect identical virtual mappings between processes for instance.

Can you also add the generation number please?
That would make it even more unique.

-Andi

#8 lore raw

Re: [PATCH v1 2/2] perf tools: add attr->mmap2 support

Quoted 9 lines · Andi Kleen
Quoted 7 lines · Stephane Eranian

This patch adds support for the new PERF_RECORD_MMAP2 record type exposed by the kernel. This is an extended PERF_RECORD_MMAP record. It adds for each file-backed mapping the device major, minor number and the inode number. This triplet uniquely identifies the source of a file-backed mapping. It can be used to detect identical virtual mappings between processes for instance.

Quoted 3 lines

Can you also add the generation number please?
That would make it even more unique.

I assume you're talkng about inode->i_generation, right? I could add that one easily. I am surprised to see:

mm/shmem.c:
static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
umode_t mode, dev_t dev, unsigned
long flags)

{
                inode->i_generation = get_seconds();
}

I am assuming that the uniqueness for SHM is coming from the SHMID and therefore a poor quality i_generation is sufficient here.

#9 lore raw

Re: [PATCH v1 2/2] perf tools: add attr->mmap2 support

Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Andi Kleen
Quoted 7 lines · Stephane Eranian

This patch adds support for the new PERF_RECORD_MMAP2 record type exposed by the kernel. This is an extended PERF_RECORD_MMAP record. It adds for each file-backed mapping the device major, minor number and the inode number. This triplet uniquely identifies the source of a file-backed mapping. It can be used to detect identical virtual mappings between processes for instance.

Quoted 4 lines
Quoted 3 lines

Can you also add the generation number please?
That would make it even more unique.

I assume you're talkng about inode->i_generation, right?

Yes.

Quoted 7 lines

I could add that one easily. I am surprised to see:

mm/shmem.c:
static struct inode *shmem_get_inode(struct super_block *sb, const struct inode *dir,
umode_t mode, dev_t dev, unsigned
long flags)

Quoted 5 lines
{
                inode->i_generation = get_seconds();
}

I am assuming that the uniqueness for SHM is coming from the SHMID and therefore a poor quality i_generation is sufficient here.

Yes that's odd. But most file system should have a sensible generation number.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only