2012-06-17 19:52:06 +00:00
|
|
|
From ed10eeda69cfac7525fd30348923e8bfe1cb5e97 Mon Sep 17 00:00:00 2001
|
2011-11-20 00:01:55 +00:00
|
|
|
From: Thomas Gleixner <tglx@linutronix.de>
|
2012-06-17 19:52:06 +00:00
|
|
|
Date: Mon, 6 Jun 2011 12:20:33 +0200
|
|
|
|
Subject: [126/254] sched-mmdrop-delayed.patch
|
2011-11-20 00:01:55 +00:00
|
|
|
|
|
|
|
Needs thread context (pgd_lock) -> ifdeffed. workqueues wont work with
|
|
|
|
RT
|
|
|
|
|
|
|
|
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
|
|
|
|
---
|
|
|
|
include/linux/mm_types.h | 4 ++++
|
|
|
|
include/linux/sched.h | 12 ++++++++++++
|
|
|
|
kernel/fork.c | 15 ++++++++++++++-
|
2012-06-04 21:20:09 +00:00
|
|
|
kernel/sched/core.c | 21 +++++++++++++++++++--
|
2011-11-20 00:01:55 +00:00
|
|
|
4 files changed, 49 insertions(+), 3 deletions(-)
|
|
|
|
|
2012-06-17 19:52:06 +00:00
|
|
|
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
|
|
|
|
index e70ea9b..8574996 100644
|
|
|
|
--- a/include/linux/mm_types.h
|
|
|
|
+++ b/include/linux/mm_types.h
|
2011-11-20 00:01:55 +00:00
|
|
|
@@ -12,6 +12,7 @@
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/page-debug-flags.h>
|
|
|
|
+#include <linux/rcupdate.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/mmu.h>
|
|
|
|
|
2012-06-04 21:20:09 +00:00
|
|
|
@@ -392,6 +393,9 @@ struct mm_struct {
|
2011-11-20 00:01:55 +00:00
|
|
|
#ifdef CONFIG_CPUMASK_OFFSTACK
|
|
|
|
struct cpumask cpumask_allocation;
|
|
|
|
#endif
|
|
|
|
+#ifdef CONFIG_PREEMPT_RT_BASE
|
|
|
|
+ struct rcu_head delayed_drop;
|
|
|
|
+#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void mm_init_cpumask(struct mm_struct *mm)
|
2012-06-17 19:52:06 +00:00
|
|
|
diff --git a/include/linux/sched.h b/include/linux/sched.h
|
|
|
|
index 0fbffda..a198e77 100644
|
|
|
|
--- a/include/linux/sched.h
|
|
|
|
+++ b/include/linux/sched.h
|
|
|
|
@@ -2324,12 +2324,24 @@ extern struct mm_struct * mm_alloc(void);
|
2011-11-20 00:01:55 +00:00
|
|
|
|
|
|
|
/* mmdrop drops the mm and the page tables */
|
|
|
|
extern void __mmdrop(struct mm_struct *);
|
|
|
|
+
|
|
|
|
static inline void mmdrop(struct mm_struct * mm)
|
|
|
|
{
|
|
|
|
if (unlikely(atomic_dec_and_test(&mm->mm_count)))
|
|
|
|
__mmdrop(mm);
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef CONFIG_PREEMPT_RT_BASE
|
|
|
|
+extern void __mmdrop_delayed(struct rcu_head *rhp);
|
|
|
|
+static inline void mmdrop_delayed(struct mm_struct *mm)
|
|
|
|
+{
|
|
|
|
+ if (atomic_dec_and_test(&mm->mm_count))
|
|
|
|
+ call_rcu(&mm->delayed_drop, __mmdrop_delayed);
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+# define mmdrop_delayed(mm) mmdrop(mm)
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* mmput gets rid of the mappings and all user-space */
|
|
|
|
extern void mmput(struct mm_struct *);
|
|
|
|
/* Grab a reference to a task's mm, if it is not already going away */
|
2012-06-17 19:52:06 +00:00
|
|
|
diff --git a/kernel/fork.c b/kernel/fork.c
|
|
|
|
index e13be8a..e6cf9db 100644
|
|
|
|
--- a/kernel/fork.c
|
|
|
|
+++ b/kernel/fork.c
|
|
|
|
@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(__put_task_struct);
|
2011-11-20 00:01:55 +00:00
|
|
|
#else
|
|
|
|
void __put_task_struct_cb(struct rcu_head *rhp)
|
|
|
|
{
|
|
|
|
- struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
|
|
|
|
+ struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
|
|
|
|
|
|
|
|
__put_task_struct(tsk);
|
|
|
|
|
2012-06-17 19:52:06 +00:00
|
|
|
@@ -574,6 +574,19 @@ void __mmdrop(struct mm_struct *mm)
|
2011-11-20 00:01:55 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__mmdrop);
|
|
|
|
|
|
|
|
+#ifdef CONFIG_PREEMPT_RT_BASE
|
|
|
|
+/*
|
|
|
|
+ * RCU callback for delayed mm drop. Not strictly rcu, but we don't
|
|
|
|
+ * want another facility to make this work.
|
|
|
|
+ */
|
|
|
|
+void __mmdrop_delayed(struct rcu_head *rhp)
|
|
|
|
+{
|
|
|
|
+ struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
|
|
|
|
+
|
|
|
|
+ __mmdrop(mm);
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Decrement the use count and release all resources for an mm.
|
|
|
|
*/
|
2012-06-17 19:52:06 +00:00
|
|
|
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
|
|
|
|
index 22a962b..9f07282 100644
|
|
|
|
--- a/kernel/sched/core.c
|
|
|
|
+++ b/kernel/sched/core.c
|
|
|
|
@@ -1934,8 +1934,12 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
|
2012-06-04 21:20:09 +00:00
|
|
|
finish_arch_post_lock_switch();
|
2011-11-20 00:01:55 +00:00
|
|
|
|
|
|
|
fire_sched_in_preempt_notifiers(current);
|
|
|
|
+ /*
|
|
|
|
+ * We use mmdrop_delayed() here so we don't have to do the
|
|
|
|
+ * full __mmdrop() when we are the last user.
|
|
|
|
+ */
|
|
|
|
if (mm)
|
|
|
|
- mmdrop(mm);
|
|
|
|
+ mmdrop_delayed(mm);
|
|
|
|
if (unlikely(prev_state == TASK_DEAD)) {
|
|
|
|
/*
|
|
|
|
* Remove function-return probe instances associated with this
|
2012-06-17 19:52:06 +00:00
|
|
|
@@ -5075,6 +5079,8 @@ static int migration_cpu_stop(void *data)
|
2011-11-20 00:01:55 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
|
|
|
|
+static DEFINE_PER_CPU(struct mm_struct *, idle_last_mm);
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Ensures that the idle task is using init_mm right before its cpu goes
|
|
|
|
* offline.
|
2012-06-04 21:20:09 +00:00
|
|
|
@@ -5087,7 +5093,12 @@ void idle_task_exit(void)
|
2011-11-20 00:01:55 +00:00
|
|
|
|
|
|
|
if (mm != &init_mm)
|
|
|
|
switch_mm(mm, &init_mm, current);
|
|
|
|
- mmdrop(mm);
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Defer the cleanup to an alive cpu. On RT we can neither
|
|
|
|
+ * call mmdrop() nor mmdrop_delayed() from here.
|
|
|
|
+ */
|
|
|
|
+ per_cpu(idle_last_mm, smp_processor_id()) = mm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-17 19:52:06 +00:00
|
|
|
@@ -5408,6 +5419,12 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
|
2011-11-20 00:01:55 +00:00
|
|
|
migrate_nr_uninterruptible(rq);
|
|
|
|
calc_global_load_remove(rq);
|
|
|
|
break;
|
|
|
|
+ case CPU_DEAD:
|
|
|
|
+ if (per_cpu(idle_last_mm, cpu)) {
|
|
|
|
+ mmdrop(per_cpu(idle_last_mm, cpu));
|
|
|
|
+ per_cpu(idle_last_mm, cpu) = NULL;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|