[Devel] [PATCH RH8 1/2] ve/memcg: make virtualization of /proc/meminfo view inside CT recursive

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon May 17 16:46:51 MSK 2021


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.

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 6e09d006e2646..9cb73ce515d57 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 d4d49160ee406..c2ed042104ef3 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 c0f825a4c43eb..c783e6cbc1779 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; */
-- 
2.30.2



More information about the Devel mailing list