diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b76cf26ac8..e0ab4b16a5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16643,28 +16643,32 @@ virDomainDefFormatInternal(virDomainDefPtr def,
}
/* add memtune only if there are any */
- if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
- def->mem.swap_hard_limit)
+ if ((def->mem.hard_limit &&
+ def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
+ (def->mem.soft_limit &&
+ def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
+ (def->mem.swap_hard_limit &&
+ def->mem.hard_limit != VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) ||
+ def->mem.min_guarantee) {
virBufferAddLit(buf, " \n");
- if (def->mem.hard_limit) {
- virBufferAsprintf(buf, " "
- "%llu\n", def->mem.hard_limit);
- }
- if (def->mem.soft_limit) {
- virBufferAsprintf(buf, " "
- "%llu\n", def->mem.soft_limit);
- }
- if (def->mem.min_guarantee) {
- virBufferAsprintf(buf, " "
- "%llu\n", def->mem.min_guarantee);
- }
- if (def->mem.swap_hard_limit) {
- virBufferAsprintf(buf, " "
- "%llu\n", def->mem.swap_hard_limit);
- }
- if (def->mem.hard_limit || def->mem.soft_limit || def->mem.min_guarantee ||
- def->mem.swap_hard_limit)
+ if (def->mem.hard_limit) {
+ virBufferAsprintf(buf, " "
+ "%llu\n", def->mem.hard_limit);
+ }
+ if (def->mem.soft_limit) {
+ virBufferAsprintf(buf, " "
+ "%llu\n", def->mem.soft_limit);
+ }
+ if (def->mem.min_guarantee) {
+ virBufferAsprintf(buf, " "
+ "%llu\n", def->mem.min_guarantee);
+ }
+ if (def->mem.swap_hard_limit) {
+ virBufferAsprintf(buf, " "
+ "%llu\n", def->mem.swap_hard_limit);
+ }
virBufferAddLit(buf, " \n");
+ }
if (def->mem.hugepage_backed || def->mem.nosharepages || def->mem.locked) {
virBufferAddLit(buf, " \n");
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args
new file mode 100644
index 0000000000..8bef546466
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.args
@@ -0,0 +1,6 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 -S -M pc -m 214 -smp 1 -nographic -monitor \
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
+-hda /dev/HostVG/QEMUGuest1 -net none -serial \
+none -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml
new file mode 100644
index 0000000000..526129b767
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-memtune-unlimited.xml
@@ -0,0 +1,29 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 214
+ 219136
+
+ 9007199254740991
+
+ 1
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f9abf1bb49..f75e457c65 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1126,6 +1126,7 @@ mymain(void)
QEMU_CAPS_KVM, QEMU_CAPS_CPU_HOST);
DO_TEST("memtune", QEMU_CAPS_NAME);
+ DO_TEST("memtune-unlimited", QEMU_CAPS_NAME);
DO_TEST("blkiotune", QEMU_CAPS_NAME);
DO_TEST("blkiotune-device", QEMU_CAPS_NAME);
DO_TEST("cputune", QEMU_CAPS_NAME);
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml
new file mode 100644
index 0000000000..1d29fa79c1
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune-unlimited.xml
@@ -0,0 +1,27 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 219136
+ 219136
+ 1
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index ceaaf6a591..2a9849ce92 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -247,6 +247,7 @@ mymain(void)
DO_TEST("encrypted-disk");
DO_TEST_DIFFERENT("memtune");
+ DO_TEST_DIFFERENT("memtune-unlimited");
DO_TEST("blkiotune");
DO_TEST("blkiotune-device");
DO_TEST("cputune");