From: Jan Dakinevich <jan.dakinev...@virtuozzo.com>

'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.dakinev...@virtuozzo.com>

(cherry-picked from vz7 commit 50cef4107c11 ("ve/meminfo: show "MemAvailable:
..." line in CT's meminfo"))

Signed-off-by: Andrey Zhadchenko <andrey.zhadche...@virtuozzo.com>

(cherry picked from vz8 commit f8e40396e7e0a9d6053d41941d7e8bb28bbd36c1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadche...@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 87001a1..132e73b 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 317d0f4..c1c4d94 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 995e41a..8db8c4c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4090,6 +4090,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)
-- 
1.8.3.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to