[RHEL8,COMMIT] proc, memcg: use memcg limits for showing oom_score inside CT

Submitted by Konstantin Khorenko on Dec. 21, 2020, 4:42 p.m.

Details

Message ID 202012211642.0BLGgxNb226679@finist-co8.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Dec. 21, 2020, 4:42 p.m.
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.3
------>
commit 58b2cd949131965c57ddd7f584144645cf97fafe
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Mon Dec 21 19:42:59 2020 +0300

    proc,memcg: use memcg limits for showing oom_score inside CT
    
    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 <aryabinin@virtuozzo.com>
---
 fs/proc/base.c             |  8 +++++++-
 include/linux/memcontrol.h | 11 +++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7639d1e45842..7c0fd93ba7d1 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -526,8 +526,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 8f85eb2dc9db..917e6ab9b1ab 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -596,6 +596,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);