anolis: oom: notify the victim's memcg's oom event when system OOM occur

ANBZ: #12923

When a system OOM occur, and select a victim to kill,
it's better to notify the victim's memcg's OOM event,
thus, the container's cgroup OOM event watcher would
be notified and mark the container's exit reason as
"OOM".

Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>
Acked-by: Xu Yu <xuyu@linux.alibaba.com>
Reviewed-by: Xunlei Pang <xlpang@linux.alibaba.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/4359
This commit is contained in:
Fupan Li 2023-03-10 15:34:46 +08:00 committed by hr567
parent 3eab841c4b
commit 49bf6507e7
3 changed files with 15 additions and 2 deletions

View File

@ -118,6 +118,7 @@ long oom_badness(struct task_struct *p,
extern bool out_of_memory(struct oom_control *oc);
extern void exit_oom_victim(void);
extern void mem_cgroup_oom_notify(struct mem_cgroup *memcg);
extern int register_oom_notifier(struct notifier_block *nb);
extern int unregister_oom_notifier(struct notifier_block *nb);

View File

@ -187,7 +187,6 @@ struct mem_cgroup_event {
};
static void mem_cgroup_threshold(struct mem_cgroup *memcg);
static void mem_cgroup_oom_notify(struct mem_cgroup *memcg);
static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value);
static int memory_min_show(struct seq_file *m, void *v);
@ -5683,7 +5682,7 @@ static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg)
return 0;
}
static void mem_cgroup_oom_notify(struct mem_cgroup *memcg)
void mem_cgroup_oom_notify(struct mem_cgroup *memcg)
{
struct mem_cgroup *iter;

View File

@ -1021,6 +1021,9 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
struct mem_cgroup *oom_group;
static DEFINE_RATELIMIT_STATE(oom_global_rs, DEFAULT_RATELIMIT_INTERVAL,
DEFAULT_RATELIMIT_BURST);
#ifdef CONFIG_MEMCG
struct mem_cgroup *memcg;
#endif
/*
* If the task is already exiting, don't alarm the sysadmin or kill
@ -1042,6 +1045,16 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
else if (!is_memcg_oom(oc) && __ratelimit(&oom_global_rs))
dump_global_header(oc, victim);
#ifdef CONFIG_MEMCG
rcu_read_lock();
memcg = mem_cgroup_from_task(victim);
if (memcg != NULL && memcg != root_mem_cgroup && !is_memcg_oom(oc)) {
css_get(&memcg->css);
mem_cgroup_oom_notify(memcg);
css_put(&memcg->css);
}
rcu_read_unlock();
#endif
/*
* Do we need to kill the entire memory cgroup?
* Or even one of the ancestor memory cgroups?