From d3f5d0703517564892641bfa374e712c8fe0c25d Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Tue, 21 Dec 2010 11:36:14 -0800 Subject: [PATCH] Revert "Revert "sched: Add a generic notifier when a task struct is about to be freed"" This reverts commit d534322cb6066ae0db4790ceacba3e1a95b1ee7c. --- include/linux/sched.h | 3 +++ kernel/fork.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index ba3494e52d17..6e3dd4fef93c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1679,6 +1679,9 @@ static inline void put_task_struct(struct task_struct *t) extern void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st); extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st); +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 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); } -- 2.34.1