summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2011-10-09 02:20:56 +0100
committerAndy Green <andy.green@linaro.org>2011-10-09 02:20:56 +0100
commit21d71e31da9d4eee556a48989d44695fbf32954c (patch)
tree8847077307cf9a695ebce7709a67fd89fd61c4a7 /kernel
parente7ed6942e0d0ce31700a8008222c50af5d50654a (diff)
sched: Add a generic notifier when a task struct is about to be freed
This patch adds a notifier which can be used by subsystems that may be interested in when a task has completely died and is about to have it's last resource freed. The Android lowmemory killer uses this to determine when a task it has killed has finally given up its goods. Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/fork.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 8e6b6f4fb27..f65fa0627c0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -153,6 +153,9 @@ struct kmem_cache *vm_area_cachep;
/* SLAB cache for mm_struct structures (tsk->mm) */
static struct kmem_cache *mm_cachep;
+/* Notifier list called when a task struct is freed */
+static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
+
static void account_kernel_stack(struct thread_info *ti, int account)
{
struct zone *zone = page_zone(virt_to_page(ti));
@@ -184,6 +187,18 @@ static inline void put_signal_struct(struct signal_struct *sig)
free_signal_struct(sig);
}
+int task_free_register(struct notifier_block *n)
+{
+ return atomic_notifier_chain_register(&task_free_notifier, n);
+}
+EXPORT_SYMBOL(task_free_register);
+
+int task_free_unregister(struct notifier_block *n)
+{
+ return atomic_notifier_chain_unregister(&task_free_notifier, n);
+}
+EXPORT_SYMBOL(task_free_unregister);
+
void __put_task_struct(struct task_struct *tsk)
{
WARN_ON(!tsk->exit_state);
@@ -194,6 +209,7 @@ void __put_task_struct(struct task_struct *tsk)
delayacct_tsk_free(tsk);
put_signal_struct(tsk->signal);
+ atomic_notifier_call_chain(&task_free_notifier, 0, tsk);
if (!profile_handoff_task(tsk))
free_task(tsk);
}