[Kimchi-devel] [PATCH 3/3 - v3] Change memory multipliers/divisors by bitwise operators

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu Nov 19 02:52:04 UTC 2015


In Kimchi memory manipulation code, memory values are most of the time
multiplied or divided by 1024. This patch changes these operations,
replacing by << 10 or >> 10, as standard.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/model/vms.py                | 4 ++--
 src/wok/plugins/kimchi/tests/test_livemigration.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py
index 9ddeaf2..5623879 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -833,7 +833,7 @@ class VMModel(object):
 
             if maxMem is None:
                 max_mem_xml = E.maxMemory(
-                    str(host_mem * 1024),
+                    str(host_mem << 10),
                     unit='Kib',
                     slots=str(slots))
                 root.insert(0, max_mem_xml)
@@ -881,7 +881,7 @@ class VMModel(object):
 
         # Check slot spaces:
         total_slots = int(xpath_get_text(xml, './maxMemory/@slots')[0])
-        needed_slots = (new_mem - old_mem) / 1024
+        needed_slots = (new_mem - old_mem) >> 10
         used_slots = len(xpath_get_text(xml, './devices/memory'))
         if needed_slots > (total_slots - used_slots):
             raise OperationFailed('KCHVM0045E')
diff --git a/src/wok/plugins/kimchi/tests/test_livemigration.py b/src/wok/plugins/kimchi/tests/test_livemigration.py
index 34c0b7e..607eb36 100644
--- a/src/wok/plugins/kimchi/tests/test_livemigration.py
+++ b/src/wok/plugins/kimchi/tests/test_livemigration.py
@@ -102,7 +102,7 @@ class LiveMigrationTests(unittest.TestCase):
                   'disks': [],
                   'cdrom': UBUNTU_ISO,
                   'memory': 2048,
-                  'max_memory': 4096*1024}
+                  'max_memory': 4096 << 10}
         self.inst.templates_create(params)
         params = {'name': u'template_test_vm_migrate_nonshared',
                   'disks': [{'name': 'test_vm_migrate.img', 'size': 1}],
-- 
2.1.0




More information about the Kimchi-devel mailing list