Change in vdsm[ovirt-3.6]: sampling: Handle numa nodes with zero memory assigned
rmohr at redhat.com
rmohr at redhat.com
Fri Aug 7 10:10:04 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>
Reviewed-on: https://gerrit.ovirt.org/44121
Continuous-Integration: Jenkins CI
Reviewed-by: Francesco Romani <fromani at redhat.com>
(cherry picked from commit bd5c78f548cb52f1b7ff2ddeababe9ef95e055ef)
---
M tests/samplingTests.py
M vdsm/virt/sampling.py
2 files changed, 52 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/50/44550/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index 433cb43..5216b7d 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -349,6 +349,52 @@
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 testMemoryStatsWithZeroMemoryAsString(self):
+ expected = {0: {'memPercent': 100, 'memFree': '0'}}
+
+ with self._monkeyPatchedMemorySample(freeMemory='0', totalMemory='0'):
+ memorySample = sampling.NumaNodeMemorySample()
+ self.assertEqual(memorySample.nodesMemSample, expected)
+
+ def testMemoryStatsWithZeroMemoryAsInt(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..8619a80 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -179,8 +179,12 @@
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
+ nodeMemSample['memPercent'] = 100
+ if int(memInfo['total']) != 0:
+ nodeMemSample['memPercent'] = 100 - \
+ int(100.0 * int(memInfo['free']) / int(memInfo['total']))
self.nodesMemSample[nodeIndex] = nodeMemSample
--
To view, visit https://gerrit.ovirt.org/44550
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6be69e715e9b4a0cc8ded744b0bcc192a466c6c8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Roman Mohr <rmohr at redhat.com>
More information about the vdsm-patches
mailing list