Change in vdsm[master]: sampling: Handle numa nodes with zero memory assigned
rmohr at redhat.com
rmohr at redhat.com
Wed Jul 29 10:09:37 UTC 2015
Roman Mohr has uploaded a new change for review.
Change subject: sampling: Handle numa nodes with zero memory assigned
......................................................................
sampling: Handle numa nodes with zero memory assigned
Fix zero division when a numa node has zero memory assigned and report
a memory usage of 100% instead. One case where this can happen is when
the server is not set up correcly.
Bug-Url: https://bugzilla.redhat.com/1247058
Change-Id: I6be69e715e9b4a0cc8ded744b0bcc192a466c6c8
Signed-off-by: Roman Mohr <rmohr at redhat.com>
---
M tests/samplingTests.py
M vdsm/virt/sampling.py
2 files changed, 44 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/21/44121/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index 433cb43..1410f4c 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -349,6 +349,43 @@
expected)
+class NumaNodeMemorySampleTests(TestCaseBase):
+ def _monkeyPatchedMemorySample(self, freeMemory, totalMemory):
+ node_id, cpu_id = 0, 0
+
+ def fakeMemoryStats():
+ return {
+ 'free': freeMemory,
+ 'total': totalMemory
+ }
+
+ def fakeNumaTopology():
+ return {
+ node_id: {
+ 'cpus': [cpu_id]
+ }
+ }
+
+ return MonkeyPatchScope([(caps, 'getNumaTopology',
+ fakeNumaTopology),
+ (caps, 'getUMAHostMemoryStats',
+ fakeMemoryStats)])
+
+ def testMemoryStatsWithZeroMemory(self):
+ expected = {0: {'memPercent': 100, 'memFree': 0}}
+
+ with self._monkeyPatchedMemorySample(freeMemory=0, totalMemory=0):
+ memorySample = sampling.NumaNodeMemorySample()
+ self.assertEqual(memorySample.nodesMemSample, expected)
+
+ def testMemoryStats(self):
+ expected = {0: {'memPercent': 40, 'memFree': 600}}
+
+ with self._monkeyPatchedMemorySample(freeMemory=600, totalMemory=1000):
+ memorySample = sampling.NumaNodeMemorySample()
+ self.assertEqual(memorySample.nodesMemSample, expected)
+
+
class StatsCacheTests(TestCaseBase):
FAKE_CLOCK_STEP = 1
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index f17a5b3..4270256 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -179,8 +179,13 @@
else:
memInfo = caps.getMemoryStatsByNumaCell(int(nodeIndex))
nodeMemSample['memFree'] = memInfo['free']
- nodeMemSample['memPercent'] = 100 - \
- int(100.0 * int(memInfo['free']) / int(memInfo['total']))
+ # in case the numa node has zero memory assigned, report the whole
+ # memory as used
+ if memInfo['total'] == 0:
+ nodeMemSample['memPercent'] = 100
+ else:
+ nodeMemSample['memPercent'] = 100 - \
+ int(100.0 * int(memInfo['free']) / int(memInfo['total']))
self.nodesMemSample[nodeIndex] = nodeMemSample
--
To view, visit https://gerrit.ovirt.org/44121
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6be69e715e9b4a0cc8ded744b0bcc192a466c6c8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Roman Mohr <rmohr at redhat.com>
More information about the vdsm-patches
mailing list