ANDROID: signal: Add vendor hook for memory reaping

Add vendor hook to determine if the memory of a process that received
the SIGKILL can be reaped.

Bug: 189803002
Change-Id: Ie6802b9bf93ddffb0ceef615d7cca40c23219e57
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
This commit is contained in:
Charan Teja Reddy
2021-06-02 17:33:03 +05:30
committed by Suren Baghdasaryan
parent 3f491d10dc
commit 3bcdb496f4
5 changed files with 47 additions and 7 deletions

View File

@@ -724,6 +724,20 @@ static inline void wake_oom_reaper(struct task_struct *tsk)
}
#endif /* CONFIG_MMU */
/**
* tsk->mm has to be non NULL and caller has to guarantee it is stable (either
* under task_lock or operate on the current).
*/
static void __mark_oom_victim(struct task_struct *tsk)
{
struct mm_struct *mm = tsk->mm;
if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) {
mmgrab(tsk->signal->oom_mm);
set_bit(MMF_OOM_VICTIM, &mm->flags);
}
}
/**
* mark_oom_victim - mark the given task as OOM victim
* @tsk: task to mark
@@ -736,18 +750,13 @@ static inline void wake_oom_reaper(struct task_struct *tsk)
*/
static void mark_oom_victim(struct task_struct *tsk)
{
struct mm_struct *mm = tsk->mm;
WARN_ON(oom_killer_disabled);
/* OOM killer might race with memcg OOM */
if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE))
return;
/* oom_mm is bound to the signal struct life time. */
if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) {
mmgrab(tsk->signal->oom_mm);
set_bit(MMF_OOM_VICTIM, &mm->flags);
}
__mark_oom_victim(tsk);
/*
* Make sure that the task is woken up from uninterruptible sleep
@@ -1185,3 +1194,18 @@ void pagefault_out_of_memory(void)
out_of_memory(&oc);
mutex_unlock(&oom_lock);
}
void add_to_oom_reaper(struct task_struct *p)
{
p = find_lock_task_mm(p);
if (!p)
return;
get_task_struct(p);
if (task_will_free_mem(p)) {
__mark_oom_victim(p);
wake_oom_reaper(p);
}
task_unlock(p);
put_task_struct(p);
}