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>
This commit is contained in:
@@ -154,6 +154,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));
|
||||
@@ -185,6 +188,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);
|
||||
@@ -195,6 +210,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user