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

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jun 11 15:09:44 MSK 2021


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.40
------>
commit 70cbea475714c5c629da65627bda4fd88b9b86ad
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Fri Jun 11 15:09:44 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>
---
 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 9cb73ce515d5..91797e63ad32 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -48,6 +48,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 f6fb836142bf..10cb6e72d10a 100644
--- a/include/linux/virtinfo.h
+++ b/include/linux/virtinfo.h
@@ -17,6 +17,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 47d8069a026f..6e7e0495da7c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3813,6 +3813,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