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.43
------>
commit 07bc4e8af16f5f1ce5da1b0a45fcab561ff4d797
Author: Andrey Ryabinin <[email protected]>
Date:   Tue Mar 31 18:45:02 2020 +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 <[email protected]>
    Signed-off-by: Konstantin Khorenko <[email protected]>
    
    (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 <[email protected]>
---
 fs/proc/meminfo.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 91797e63ad32..04ad51a4a698 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -90,24 +90,29 @@ 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);
-
        /* bufferram, totalhigh and freehigh left 0 */
 }
 
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to