Re: [RFC] perf: mmap2 not covering VM_CLONE regions
From: Peter Zijlstra
Date: Thu Oct 03 2013 - 05:04:26 EST
On Thu, Oct 03, 2013 at 10:55:28AM +0200, Stephane Eranian wrote:
> I don't know the MM code but I assume that that vm_mm struct is
> allocated dynamically
> and maybe you already grabbing a lock while doing this. Could we
> leverage that lock
> to increment a global generation number?
Sure; something like so.. I just don't like global state nor adding to
mm_struct for just this.
---
include/linux/mm_types.h | 1 +
kernel/fork.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index d9851eeb6e1d..3877b1e72a5b 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -436,6 +436,7 @@ struct mm_struct {
int first_nid;
#endif
struct uprobes_state uprobes_state;
+ u64 mm_id;
};
/* first nid will either be a valid NID or one of these values */
diff --git a/kernel/fork.c b/kernel/fork.c
index 086fe73ad6bd..b315f6227629 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -523,6 +523,8 @@ static void mm_init_aio(struct mm_struct *mm)
#endif
}
+static u64 global_mm_id;
+
static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
{
atomic_set(&mm->mm_users, 1);
@@ -537,6 +539,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)
spin_lock_init(&mm->page_table_lock);
mm_init_aio(mm);
mm_init_owner(mm, p);
+ mm->mm_id = 0;
if (likely(!mm_alloc_pgd(mm))) {
mm->def_flags = 0;
@@ -1422,6 +1425,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
*/
write_lock_irq(&tasklist_lock);
+ if (p->mm && !p->mm->mm_id)
+ p->mm->mm_id = ++global_mm_id;
+
/* CLONE_PARENT re-uses the old parent */
if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
p->real_parent = current->real_parent;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/