[Devel] [PATCH RHEL9 COMMIT] ve/memcg: Account some swapped memory as used in CT in /proc/meminfo
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Oct 20 11:40:41 MSK 2021
The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.12
------>
commit 58a4508d74409cdef9fa62605402ce899c36c7ac
Author: Andrey Ryabinin <ryabinin.a.a at gmail.com>
Date: Wed Oct 20 11:40:41 2021 +0300
ve/memcg: Account some swapped memory as used in CT in /proc/meminfo
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 132e73b59543..7758c56b65d1 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);
More information about the Devel
mailing list