[PATCH 10/16] LXC from native: migrate memory tuning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/lxc/lxc_native.c                             | 26 ++++++++++++++++
 tests/lxcconf2xmldata/lxcconf2xml-memtune.config | 12 ++++++++
 tests/lxcconf2xmldata/lxcconf2xml-memtune.xml    | 38 ++++++++++++++++++++++++
 tests/lxcconf2xmltest.c                          |  1 +
 4 files changed, 77 insertions(+)
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-memtune.config
 create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-memtune.xml

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7cb5125..582924e 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -767,6 +767,29 @@ lxcCreateIdmap(virDomainDefPtr def, virPropertiesPtr properties)
     return 0;
 }
 
+static void
+lxcSetMemTune(virDomainDefPtr def, virPropertiesPtr properties)
+{
+    char *value = NULL;
+
+    if ((value = virPropertiesLookup(properties,
+                "lxc.cgroup.memory.limit_in_bytes")) && STRNEQ(value, "-1")) {
+        unsigned long long size = lxcConvertSize(value, 0) / 1024;
+        def->mem.max_balloon = size;
+        def->mem.hard_limit = size;
+    }
+
+    if ((value = virPropertiesLookup(properties,
+                "lxc.cgroup.memory.soft_limit_in_bytes")) &&
+            STRNEQ(value, "-1"))
+       def->mem.soft_limit = lxcConvertSize(value, 0) / 1024;
+
+    if ((value = virPropertiesLookup(properties,
+                "lxc.cgroup.memory.memsw.limit_in_bytes")) &&
+            STRNEQ(value, "-1"))
+       def->mem.swap_hard_limit = lxcConvertSize(value, 0) / 1024;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config,
                      const char *fstab,
@@ -862,6 +885,9 @@ lxcParseConfigString(const char *config,
     if (lxcCreateIdmap(vmdef, properties) < 0)
         goto error;
 
+    /* lxc.cgroup.memory.* */
+    lxcSetMemTune(vmdef, properties);
+
     goto cleanup;
 
 error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-memtune.config b/tests/lxcconf2xmldata/lxcconf2xml-memtune.config
new file mode 100644
index 0000000..ef01e23
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-memtune.config
@@ -0,0 +1,12 @@
+lxc.mount.entry = /etc/resolv.conf etc/resolv.conf none bind,ro 0 0
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
+lxc.mount = /var/lib/lxc/migrate_test/fstab
+
+# 1GiB
+lxc.cgroup.memory.limit_in_bytes = 1073741824
+# 128MiB
+lxc.cgroup.memory.soft_limit_in_bytes = 134217728
+# 2GiB
+lxc.cgroup.memory.memsw.limit_in_bytes = 2147483648
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml b/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
new file mode 100644
index 0000000..4e4698e
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
@@ -0,0 +1,38 @@
+<domain type='lxc'>
+  <name>migrate_test</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>0</currentMemory>
+  <memtune>
+    <hard_limit unit='KiB'>1048576</hard_limit>
+    <soft_limit unit='KiB'>131072</soft_limit>
+    <swap_hard_limit unit='KiB'>2097152</swap_hard_limit>
+  </memtune>
+  <vcpu placement='static' current='0'>1</vcpu>
+  <os>
+    <type>exe</type>
+    <init>/sbin/init</init>
+  </os>
+  <features>
+    <privnet/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/var/lib/lxc/migrate_test/rootfs'/>
+      <target dir='/'/>
+    </filesystem>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/etc/resolv.conf'/>
+      <target dir='/etc/resolv.conf'/>
+      <readonly/>
+    </filesystem>
+    <filesystem type='ram' accessmode='passthrough'>
+      <source usage='2017885' units='KiB'/>
+      <target dir='/run'/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index 6793c29..bf5b06e 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -111,6 +111,7 @@ mymain(void)
     DO_TEST("physnetwork");
     DO_TEST("macvlannetwork");
     DO_TEST("idmap");
+    DO_TEST("memtune");
 
     return ret;
 }
-- 
1.8.5.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]