[Devel] [PATCH RHEL8 COMMIT] ve/memcg: Make virtualization of /proc/meminfo view inside CT recursive

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 24 17:25:10 MSK 2021


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.32
------>
commit 47f1b6c1d8e510989300576422742a528eedf169
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Mon May 24 17:25:10 2021 +0300

    ve/memcg: Make virtualization of /proc/meminfo view inside CT recursive
    
    When we read /proc/meminfo inside container we expect to see not only
    stats for container root cgroup but an agregated stats for all container
    cgroups, so let's make in recursive like in VZ7.
    
    Note: In VZ7 this was done via virtinfo subsystem which is dropped.
    
    To_merge: 38a2f168a441 ("ve/proc: virtualize /proc/meminfo in a Container")
    
    https://jira.sw.ru/browse/PSBM-127780
    
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 fs/proc/meminfo.c          |  4 +---
 include/linux/memcontrol.h |  8 ++++++++
 mm/memcontrol.c            | 24 ++++++++++++++++++------
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 6e09d006e264..9cb73ce515d5 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -110,9 +110,7 @@ void si_meminfo_ve(struct sysinfo *si, struct ve_struct *ve)
 	/* bufferram, totalhigh and freehigh left 0 */
 }
 
-extern void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi);
-
-void fill_meminfo_ve(struct meminfo *mi, struct ve_struct *ve)
+static void fill_meminfo_ve(struct meminfo *mi, struct ve_struct *ve)
 {
 	struct cgroup_subsys_state *css;
 
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index d4d49160ee40..c2ed042104ef 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -30,6 +30,7 @@
 #include <linux/vmstat.h>
 #include <linux/writeback.h>
 #include <linux/page-flags.h>
+#include <linux/virtinfo.h>
 
 struct mem_cgroup;
 struct page;
@@ -877,6 +878,8 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,
 void mem_cgroup_split_huge_fixup(struct page *head);
 #endif
 
+void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi);
+
 #else /* CONFIG_MEMCG */
 
 #define MEM_CGROUP_ID_SHIFT	0
@@ -1272,6 +1275,11 @@ static inline
 void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx)
 {
 }
+
+static void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi)
+{
+}
+
 #endif /* CONFIG_MEMCG */
 
 /* idx can be of type enum memcg_stat_item or node_stat_item */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c0f825a4c43e..c783e6cbc177 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3783,6 +3783,18 @@ void mem_cgroup_get_nr_pages(struct mem_cgroup *memcg, int nid,
 	}
 }
 
+static unsigned long mem_page_state_recursive(struct mem_cgroup *memcg,
+					      int idx)
+{
+	struct mem_cgroup *iter;
+	unsigned long val = 0;
+
+	for_each_mem_cgroup_tree(iter, memcg)
+		val += memcg_page_state(iter, idx);
+
+	return val;
+}
+
 void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi)
 {
 	int nid;
@@ -3791,12 +3803,12 @@ void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi)
 	for_each_online_node(nid)
 		mem_cgroup_get_nr_pages(memcg, nid, mi->pages);
 
-	mi->slab_reclaimable = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE);
-	mi->slab_unreclaimable = memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE);
-	mi->cached = memcg_page_state(memcg, MEMCG_CACHE);
-	mi->shmem = memcg_page_state(memcg, NR_SHMEM);
-	mi->dirty_pages = memcg_page_state(memcg, NR_FILE_DIRTY);
-	mi->writeback_pages = memcg_page_state(memcg, NR_WRITEBACK);
+	mi->slab_reclaimable = mem_page_state_recursive(memcg, NR_SLAB_RECLAIMABLE);
+	mi->slab_unreclaimable = mem_page_state_recursive(memcg, NR_SLAB_UNRECLAIMABLE);
+	mi->cached = mem_page_state_recursive(memcg, MEMCG_CACHE);
+	mi->shmem = mem_page_state_recursive(memcg, NR_SHMEM);
+	mi->dirty_pages = mem_page_state_recursive(memcg, NR_FILE_DIRTY);
+	mi->writeback_pages = mem_page_state_recursive(memcg, NR_WRITEBACK);
 
 	/* locked pages are accounted per zone */
 	/* mi->locked = 0; */


More information about the Devel mailing list