From: San Mehat Date: Thu, 6 May 2010 22:37:55 +0000 (-0700) Subject: sched: Add a generic notifier when a task struct is about to be freed X-Git-Tag: firefly_0821_release~11606 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9e6cb2f4dbe36af72558f60f418cc03df0173628;p=firefly-linux-kernel-4.4.55.git 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 --- diff --git a/include/linux/sched.h b/include/linux/sched.h index e48311e8c923..30473ee9628b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1724,6 +1724,9 @@ extern cputime_t task_utime(struct task_struct *p); extern cputime_t task_stime(struct task_struct *p); extern cputime_t task_gtime(struct task_struct *p); +extern int task_free_register(struct notifier_block *n); +extern int task_free_unregister(struct notifier_block *n); + /* * Per process flags */ diff --git a/kernel/fork.c b/kernel/fork.c index 166b8c49257c..2cfa6dcfd44f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -138,6 +138,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)); @@ -156,6 +159,18 @@ void free_task(struct task_struct *tsk) } EXPORT_SYMBOL(free_task); +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); @@ -165,6 +180,7 @@ void __put_task_struct(struct task_struct *tsk) exit_creds(tsk); delayacct_tsk_free(tsk); + atomic_notifier_call_chain(&task_free_notifier, 0, tsk); if (!profile_handoff_task(tsk)) free_task(tsk); }