[RHEL7,COMMIT] ve/meminfo: show "MemAvailable: ..." line in CT's meminfo

Submitted by Konstantin Khorenko on Feb. 1, 2019, 1:46 p.m.

Details

Message ID 201902011346.x11Dkd3Y012963@finist-ce7.sw.ru
State New
Series "ve/meminfo: show "MemAvailable: ..." line in CT's meminfo"
Headers show

Commit Message

Konstantin Khorenko Feb. 1, 2019, 1:46 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.1.3.vz7.83.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.1.3.vz7.83.9
------>
commit 50cef4107c1106d547f5118a202bc8e0c0467c5c
Author: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
Date:   Fri Jan 18 17:59:06 2019 +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@virtuozzo.com>
---
 fs/proc/meminfo.c        |  2 ++
 include/linux/virtinfo.h |  1 +
 mm/memcontrol.c          | 11 +++++++++++
 3 files changed, 14 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 635bd0122f6d..32512c4fa9c0 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -30,6 +30,7 @@  static int meminfo_proc_show_mi(struct seq_file *m, struct meminfo *mi)
 	seq_printf(m,
 		"MemTotal:       %8lu kB\n"
 		"MemFree:        %8lu kB\n"
+		"MemAvailable:   %8lu kB\n"
 		"Cached:         %8lu kB\n"
 		"Buffers:        %8lu kB\n"
 		"Active:         %8lu kB\n"
@@ -52,6 +53,7 @@  static int meminfo_proc_show_mi(struct seq_file *m, struct meminfo *mi)
 		,
 		K(mi->si->totalram),
 		K(mi->si->freeram),
+		K(mi->available),
 		K(mi->cached),
 		K(0L),
 		K(mi->pages[LRU_ACTIVE_ANON]   + mi->pages[LRU_ACTIVE_FILE]),
diff --git a/include/linux/virtinfo.h b/include/linux/virtinfo.h
index 8e98489910a1..ef3c4d3d2032 100644
--- a/include/linux/virtinfo.h
+++ b/include/linux/virtinfo.h
@@ -52,6 +52,7 @@  struct meminfo {
 	unsigned long pages[NR_LRU_LISTS];
 	unsigned long cached, dirty_pages, writeback_pages, locked, shmem;
 	unsigned long slab_reclaimable, slab_unreclaimable;
+	unsigned long available;
 };
 
 struct seq_file;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 339275f02d89..cc7171eaf360 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4461,6 +4461,17 @@  void mem_cgroup_fill_meminfo(struct mem_cgroup *memcg, struct meminfo *mi)
 					MEM_CGROUP_STAT_SLAB_UNRECLAIMABLE);
 	mi->cached = mem_cgroup_recursive_stat2(memcg, MEM_CGROUP_STAT_CACHE);
 	mi->shmem = mem_cgroup_recursive_stat(memcg, MEM_CGROUP_STAT_SHMEM);
+
+	/*
+	 * 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;
 }
 
 int mem_cgroup_enough_memory(struct mem_cgroup *memcg, long pages)