Use memcg's limits of task to show /proc/<pid>/oom_score. Note: in vz7 we had different behavior. It showed 'oom_score' based on 've->memcg' limits of process reading oom_score. Now we look at memcg of <pid> process and don't care about the current one. It seems more correct behaviour.
Signed-off-by: Andrey Ryabinin <aryabi...@virtuozzo.com> --- fs/proc/base.c | 8 +++++++- include/linux/memcontrol.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 85fee7396e90..cb417426dd92 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -525,8 +525,14 @@ static const struct file_operations proc_lstats_operations = { static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { - unsigned long totalpages = totalram_pages + total_swap_pages; + unsigned long totalpages; unsigned long points = 0; + struct mem_cgroup *memcg; + + rcu_read_lock(); + memcg = mem_cgroup_from_task(task); + totalpages = mem_cgroup_total_pages(memcg); + rcu_read_unlock(); points = oom_badness(task, NULL, NULL, totalpages, NULL) * 1000 / totalpages; diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index eb8634128a81..c26041c681f2 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -581,6 +581,17 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec, return mz->lru_zone_size[zone_idx][lru]; } +static inline unsigned long mem_cgroup_total_pages(struct mem_cgroup *memcg) +{ + unsigned long ram, ram_swap; + extern long total_swap_pages; + + ram = min_t(unsigned long, totalram_pages, memcg->memory.max); + ram_swap = min_t(unsigned long, memcg->memsw.max, ram + total_swap_pages); + + return ram_swap; +} + void mem_cgroup_handle_over_high(void); unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg); -- 2.26.2 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel