[Devel] [PATCH RHEL10 COMMIT] ve/proc: Fix meminfo swap	calculations on cgroup-v2
    Konstantin Khorenko 
    khorenko at virtuozzo.com
       
    Fri Oct 10 20:18:03 MSK 2025
    
    
  
The commit is pushed to "branch-rh10-6.12.0-55.13.1.2.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-55.13.1.2.10.vz10
------>
commit 7318b8eee387b89511c7adcac0f865fb020dd7b0
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Mon Oct 6 12:45:57 2025 +0800
    ve/proc: Fix meminfo swap calculations on cgroup-v2
    
    The memsw counter in cgroup-v2 is reused by swap counter and does not
    include memory usage, we should use it directly instead of subtracting
    memory from memsw.
    
    While on it let's reorder loading memused, memtotal, swapused and
    swaptotal before doing any calculations or corrections on them, and also
    fix comment style.
    
    Fixes: 6992eead25249 ("ve/proc: virtualize /proc/meminfo in a Container")
    
    https://virtuozzo.atlassian.net/browse/VSTOR-105819
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Feature: procfs: virtualize /proc/meminfo
---
 mm/show_mem.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/mm/show_mem.c b/mm/show_mem.c
index be4985e672dc4..0453e3c635eb2 100644
--- a/mm/show_mem.c
+++ b/mm/show_mem.c
@@ -106,13 +106,23 @@ void si_meminfo_ve(struct sysinfo *si, struct ve_struct *ve)
 
 	memtotal = READ_ONCE(memcg->memory.max);
 	memused = page_counter_read(&memcg->memory);
-	si->totalram = memtotal;
 
-	swaptotal = READ_ONCE(memcg->memsw.max) - memtotal;
-	swapused = page_counter_read(&memcg->memsw) - memused;
+	if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
+		swaptotal = READ_ONCE(memcg->swap.max);
+		swapused = page_counter_read(&memcg->swap);
+	} else {
+		swaptotal = READ_ONCE(memcg->memsw.max) - memtotal;
+		swapused = page_counter_read(&memcg->memsw) - memused;
+	}
+
+	si->totalram = memtotal;
 	si->totalswap = swaptotal;
-	/* Due to global reclaim, memory.memsw.usage can be greater than
-	 * (memory.memsw.max - memory.max). */
+
+	/*
+	 * Due to global reclaim, memory.memsw.usage can be greater than
+	 * (memory.memsw.max - memory.max), and we show this "excess" swap
+	 * usage as if it's memory usage.
+	 */
 	if (swaptotal >= swapused) {
 		si->freeswap = swaptotal - swapused;
 	} else {
    
    
More information about the Devel
mailing list