[Devel] [PATCH RH9 13/28] ve/memcg: Account some swapped memory as used in CT in /proc/meminfo

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Oct 14 13:33:21 MSK 2021


From: Andrey Ryabinin <aryabinin at virtuozzo.com>

If swapped memory of container exceed CT's swap size (can happen
on external memory pressure) it's unaccounted in /proc/meminfo.

Fix this by adding swapped above swap size to used counter.
Ideally we should also add this to inactive anon and/or shmem, but
we don't really know what was swapped, so leave it as is.

https://jira.sw.ru/browse/PSBM-102266
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

(The logic is taken from vz7 commit 9667cb8cbee3 ("memcg, bc/vm_pages.c:
account some swapped memory as used in CT in /proc/meminfo"))

Rebased in the scope of https://jira.sw.ru/browse/PSBM-127850.

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

(cherry picked from vz8 commit 18e04c7d2b37e4af145410dc0155f5ea0de15d9c)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 fs/proc/meminfo.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 132e73b..7758c56 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -88,20 +88,25 @@ void si_meminfo_ve(struct sysinfo *si, struct ve_struct *ve)
 	css = ve_get_init_css(ve, memory_cgrp_id);
 	memcg = mem_cgroup_from_css(css);
 
+	si->sharedram = memcg_page_state(memcg, NR_SHMEM);
+
 	memtotal = READ_ONCE(memcg->memory.max);
 	memused = page_counter_read(&memcg->memory);
 	si->totalram = memtotal;
-	si->freeram = (memtotal > memused ? memtotal - memused : 0);
-
-	si->sharedram = memcg_page_state(memcg, NR_SHMEM);
 
 	swaptotal = READ_ONCE(memcg->memsw.max) - memtotal;
 	swapused = page_counter_read(&memcg->memsw) - memused;
 	si->totalswap = swaptotal;
 	/* Due to global reclaim, memory.memsw.usage can be greater than
 	 * (memory.memsw.max - memory.max). */
-	si->freeswap = (swaptotal > swapused ? swaptotal - swapused : 0);
+	if (swaptotal >= swapused) {
+		si->freeswap = swaptotal - swapused;
+	} else {
+		si->freeswap = 0;
+		memused += swapused - swaptotal;
+	}
 
+	si->freeram = (memtotal > memused ? memtotal - memused : 0);
 	si->mem_unit = PAGE_SIZE;
 
 	css_put(css);
-- 
1.8.3.1



More information about the Devel mailing list