[Devel] [PATCH RHEL9 COMMIT] ve/meminfo: show "MemAvailable: ..." line in CT's meminfo

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 20 11:40:40 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 388de630336f9e7723dcb503026324317b566003
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Wed Oct 20 11:40:40 2021 +0300

    ve/meminfo: show "MemAvailable: ..." line in CT's meminfo
    
    'available' memory is calculated in the same way as in
    si_mem_available(), but 'WMARK_LOW' and 'totalreserve_pages' are not
    honored as irrelevant for Containers.
    
    https://jira.sw.ru/browse/PSBM-90190
    
    Signed-off-by: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
    
    (cherry-picked from vz7 commit 50cef4107c11 ("ve/meminfo: show "MemAvailable:
    ..." line in CT's meminfo"))
    
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
    
    (cherry picked from vz8 commit f8e40396e7e0a9d6053d41941d7e8bb28bbd36c1)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 fs/proc/meminfo.c        |  1 +
 include/linux/virtinfo.h |  1 +
 mm/memcontrol.c          | 11 +++++++++++
 3 files changed, 13 insertions(+)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 87001a186504..132e73b59543 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -46,6 +46,7 @@ static int meminfo_proc_show_mi(struct seq_file *m, struct meminfo *mi)
 
 	show_val_kb(m, "MemTotal:       ", mi->si->totalram);
 	show_val_kb(m, "MemFree:        ", mi->si->freeram);
+	show_val_kb(m, "MemAvailable:	", mi->available);
 	show_val_kb(m, "Buffers:        ", 0);
 	show_val_kb(m, "Cached:         ", mi->cached);
 
diff --git a/include/linux/virtinfo.h b/include/linux/virtinfo.h
index 317d0f4d817b..c1c4d94b8b59 100644
--- a/include/linux/virtinfo.h
+++ b/include/linux/virtinfo.h
@@ -19,6 +19,7 @@ struct meminfo {
         unsigned long pages[NR_LRU_LISTS];
         unsigned long cached, dirty_pages, writeback_pages, shmem;
         unsigned long slab_reclaimable, slab_unreclaimable;
+	unsigned long available;
 };
 
 #endif /* __LINUX_VIRTINFO_H */
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 89ead3df0b59..f63f998ceccb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4180,6 +4180,17 @@ void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi)
 
 	/* locked pages are accounted per zone */
 	/* mi->locked = 0; */
+
+	/*
+	 * The way of calculating 'available' memory repeats behavior of
+	 * si_mem_available(), except 'WMARK_LOW' and 'totalreserve_pages'
+	 * are not taken into account. These values reflect reservation of
+	 * physycal memory and they are not relevant for CT.
+	 */
+	mi->available = mi->si->freeram;
+	mi->available += mi->pages[LRU_ACTIVE_FILE] +
+			 mi->pages[LRU_INACTIVE_FILE];
+	mi->available += mi->slab_reclaimable;
 }
 
 void mem_cgroup_fill_vmstat(struct mem_cgroup *memcg, unsigned long *stats)


More information about the Devel mailing list