summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2010-05-06 15:37:55 -0700
committerColin Cross <ccross@android.com>2010-09-29 17:49:34 -0700
commite79ef44016e3dbe611c959bed493c93c3367cfbf (patch)
tree51fad4257f9018861c1cb5126ff770b5308b066e /kernel
parent9f69ebbf404cf49f9275c1310f1be8f303c87c9b (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 c445f8cc408d..f3d93ab730c6 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -147,6 +147,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));
@@ -177,6 +180,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);
@@ -187,6 +202,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);
}