Change in vdsm[master]: API: Add free memory to stats

omasad at redhat.com omasad at redhat.com
Sun Jun 30 12:44:52 UTC 2013


ofri masad has uploaded a new change for review.

Change subject: API: Add free memory to stats
......................................................................

API: Add free memory to stats

currently, only memAvailable is exposed by API. But this api is a
calculated value and so it may return negative value in case ksm
is up and pages are shred among VMs.

The new "memFree" returns the true free memory on the host.
i.e. 'MemFree' + 'Cached' + 'Buffers' (from meminfo)

Change-Id: I0e5ebf8b40b728424ba92bf8131fff51b45893bd
Bug-Url: https://bugzilla.redhat.com/977758
Signed-off-by: Ofri Masad <omasad at redhat.com>
---
M vdsm/API.py
M vdsm_api/vdsmapi-schema.json
2 files changed, 16 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/53/16253/1

diff --git a/vdsm/API.py b/vdsm/API.py
index dd28e32..b020ae6 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1163,6 +1163,7 @@
             stats[var] = utils.convertToStr(decStats[var])
         stats['memAvailable'] = self._memAvailable() / Mbytes
         stats['memCommitted'] = self._memCommitted() / Mbytes
+        stats['memFree'] = self._memFree() / Mbytes
         stats['swapTotal'], stats['swapFree'] = _readSwapTotalFree()
         stats['vmCount'], stats['vmActive'], stats['vmMigrating'] = \
             self._countVms()
@@ -1417,6 +1418,14 @@
         return freeOrCached + resident - memCommitted - \
             config.getint('vars', 'host_mem_reserve') * Mbytes
 
+    def _memFree(self):
+        """
+        Return the actual free mem on host.
+        """
+        meminfo = utils.readMemInfo()
+        return (meminfo['MemFree'] +
+                        meminfo['Cached'] + meminfo['Buffers']) * Kbytes
+
     def _memShared(self):
         """
         Return an approximation of memory shared by VMs thanks to KSM.
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index 569d7e9..7c13413 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -1531,6 +1531,8 @@
 #
 # @memAvailable:    Amount of memory available to run virtual machines (bytes)
 #
+# @memFree:         Amount of free memory on host (bytes)
+#
 # @memShared:       Approximate amount of memory that is shared by VMs due to
 #                   the KSM feature (in bytes)
 #
@@ -1573,11 +1575,11 @@
            'elapsedTime': 'uint', 'memUsed': 'uint',
            'anonHugePages': 'uint', 'cpuLoad': 'float',
            'diskStats': 'PathStatsMap', 'thpState': 'THPStates',
-           'memAvailable': 'int', 'memShared': 'int', 'memCommitted': 'int',
-           'swapTotal': 'int', 'swapFree': 'int','vmCount': 'int',
-           'vmActive': 'int', 'vmMigrating': 'int', 'dateTime': 'str',
-           'ksmState': 'bool', 'ksmPages': 'int', 'ksmCpu': 'float',
-           'netConfigDirty': 'bool', 'generationID': 'UUID',
+           'memAvailable': 'int', 'memFree': 'int', 'memShared': 'int', 
+           'memCommitted': 'int', 'swapTotal': 'int', 'swapFree': 'int',
+           'vmCount': 'int', 'vmActive': 'int', 'vmMigrating': 'int', 
+           'dateTime': 'str', 'ksmState': 'bool', 'ksmPages': 'int', 
+           'ksmCpu': 'float', 'netConfigDirty': 'bool', 'generationID': 'UUID',
            'momStatus': 'MOMStatus'}}
 
 ##


-- 
To view, visit http://gerrit.ovirt.org/16253
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e5ebf8b40b728424ba92bf8131fff51b45893bd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: ofri masad <omasad at redhat.com>


More information about the vdsm-patches mailing list