MemAvailable was introduced in kernel version 3.10 (and it was even
backported to older kernels in some distributions) and has been
a quite popular method to estimate the available method (totally fully
amount + reclaimable amount).

Signed-off-by: Takashi Kajinami <[email protected]>
---
 include/libvirt/libvirt-host.h | 10 ++++++++++
 src/libvirt-host.c             |  2 ++
 src/util/virhostmem.c          |  3 ++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 398b40c35a..5b448e7954 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -364,6 +364,16 @@ typedef enum {
  */
 # define VIR_NODE_MEMORY_STATS_CACHED "cached"
 
+/**
+ * VIR_NODE_MEMORY_STATS_AVAILABLE:
+ *
+ * Macro for the available memory: On Linux, it is only returned in case of
+ * VIR_NODE_MEMORY_STATS_ALL_CELLS.
+ *
+ * Since: 12.3.0
+ */
+# define VIR_NODE_MEMORY_STATS_AVAILABLE "available"
+
 /**
  * virNodeMemoryStats:
  *
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index da75f5f30b..6b4345b09d 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -633,6 +633,8 @@ virNodeGetCPUStats(virConnectPtr conn,
  *     The buffers memory usage.(KB)
  * VIR_NODE_MEMORY_STATS_CACHED:
  *     The cached memory usage.(KB)
+ * VIR_NODE_MEMORY_STATS_AVAILABLE:
+ *     The available memory usage.(KB)
  *
  * Returns -1 in case of error, 0 in case of success.
  *
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index a7027af835..09a322fdea 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -136,7 +136,7 @@ virHostMemGetStatsFreeBSD(virNodeMemoryStatsPtr params,
 # define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm"
 # define SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX 8192
 
-# define LINUX_NB_MEMORY_STATS_ALL 4
+# define LINUX_NB_MEMORY_STATS_ALL 5
 # define LINUX_NB_MEMORY_STATS_CELL 2
 
 static int
@@ -159,6 +159,7 @@ virHostMemGetStatsLinux(FILE *meminfo,
         {"MemFree:",  VIR_NODE_MEMORY_STATS_FREE},
         {"Buffers:",  VIR_NODE_MEMORY_STATS_BUFFERS},
         {"Cached:",   VIR_NODE_MEMORY_STATS_CACHED},
+        {"MemAvailable:",   VIR_NODE_MEMORY_STATS_AVAILABLE},
         {NULL,        NULL}
     };
 
-- 
2.49.0

Reply via email to