From: Andrey Ryabinin <aryabi...@virtuozzo.com>

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>

(cherry picked from vz8 commit 43e606413dfbabf139af6f31737b159b8d6d87b3)
Signed-off-by: Andrey Zhadchenko <andrey.zhadche...@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 ff7b277..e91b514 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -546,10 +546,16 @@ static ssize_t lstats_write(struct file *file, const char 
__user *buf,
 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;
        long badness;
 
+       rcu_read_lock();
+       memcg = mem_cgroup_from_task(task);
+       totalpages = mem_cgroup_total_pages(memcg);
+       rcu_read_unlock();
+
        badness = oom_badness(task, totalpages, NULL);
        /*
         * Special case OOM_SCORE_ADJ_MIN for all others scale the
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 55313db..84bacc5 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -931,6 +931,17 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec 
*lruvec,
        return READ_ONCE(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);
-- 
1.8.3.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to