[libvirt] [PATCH 0/2] 'deflate-on-oom' attribute for mememory balloon

This patch-set adds support for the new feature that has been added to the QEMU virtio memory balloon a month ago. This feature lets a guest OS deflate balloon on OOM. With 'deflate-on-oom' enabled virtio balloon will release it's memory if possible right before an OOM termination of processes. QEMU commit with the complete feature description: http://git.qemu.org/?p=qemu.git;a=commit;h=e3816255bf4b6377bb405331e2ee0dc14... Dmitry Andreev (2): conf: introduce 'deflate-on-oom' attribute for memballoon device qemu: add support of optional 'deflate-on-oom' attribute docs/formatdomain.html.in | 10 +++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 23 ++++++++++++++++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 4 ++++ .../qemuxml2argv-balloon-device-deflate-off.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate-off.xml | 25 ++++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.xml | 25 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 ++++ 10 files changed, 143 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml -- 1.8.3.1

Excessive memory balloon inflation can cause invocation of OOM-killer, when Linux is under severe memory pressure. QEMU memballoon device has a feature to release some memory at the last moment before some process will be get killed by OOM-killer. Introduced attribute allows to enable or disable this feature. --- docs/formatdomain.html.in | 10 ++++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 23 +++++++++++++++++++++++ src/conf/domain_conf.h | 1 + 4 files changed, 39 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a8bd48e..fa68e7b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5954,6 +5954,16 @@ qemu-kvm -net nic,model=? /dev/null <li>'xen' — default with Xen</li> </ul> </dd> + <dt><code>deflate-on-oom</code></dt> + <dd> + <p> + The optional <code>deflate-on-oom</code> attribute allows to + enable/disable (values "on"/"off", respectively) the ability of the + QEMU virtio memory balloon to release some memory at the last moment + before a guest's process get killed by OOM-killer. + <span class="since">Since 1.3.1, QEMU and KVM only</span> + </p> + </dd> <dt><code>period</code></dt> <dd> <p> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4804c69..9587849 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3415,6 +3415,11 @@ <value>none</value> </choice> </attribute> + <optional> + <attribute name="deflate-on-oom"> + <ref name="virOnOff"/> + </attribute> + </optional> <interleave> <optional> <ref name="alias"/> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5200c27..b332097 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11312,6 +11312,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, unsigned int flags) { char *model; + char *deflate; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; unsigned int period = 0; @@ -11332,6 +11333,13 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, goto error; } + if ((deflate = virXMLPropString(node, "deflate-on-oom")) && + (def->deflate = virTristateSwitchTypeFromString(deflate)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid deflate-on-oom attribute value '%s'"), deflate); + goto error; + } + ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -11350,6 +11358,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, cleanup: VIR_FREE(model); + VIR_FREE(deflate); ctxt->node = save; return def; @@ -17223,6 +17232,15 @@ virDomainMemballoonDefCheckABIStability(virDomainMemballoonDefPtr src, return false; } + if (src->deflate != dst->deflate) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target balloon deflate-on-oom attribute value " + "%s does not match source %s"), + virTristateSwitchTypeToString(dst->deflate), + virTristateSwitchTypeToString(src->deflate)); + return false; + } + if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) return false; @@ -20390,6 +20408,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); + const char *deflate = virTristateSwitchTypeToString(def->deflate); virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; int indent = virBufferGetIndent(buf, false); @@ -20400,6 +20419,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf, } virBufferAsprintf(buf, "<memballoon model='%s'", model); + + if (def->deflate > 0 && deflate) + virBufferAsprintf(buf, " deflate-on-oom='%s'", deflate); + virBufferAdjustIndent(&childrenBuf, indent + 2); if (def->period) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cec681a..707ffb2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1634,6 +1634,7 @@ struct _virDomainMemballoonDef { int model; virDomainDeviceInfo info; int period; /* seconds between collections */ + int deflate; /* enum virTristateSwitch */ }; struct _virDomainNVRAMDef { -- 1.8.3.1

On 12/14/2015 06:35 AM, Dmitry Andreev wrote:
Excessive memory balloon inflation can cause invocation of OOM-killer, when Linux is under severe memory pressure. QEMU memballoon device has a feature to release some memory at the last moment before some process will be get killed by OOM-killer.
Introduced attribute allows to enable or disable this feature. --- docs/formatdomain.html.in | 10 ++++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 23 +++++++++++++++++++++++ src/conf/domain_conf.h | 1 + 4 files changed, 39 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a8bd48e..fa68e7b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5954,6 +5954,16 @@ qemu-kvm -net nic,model=? /dev/null <li>'xen' — default with Xen</li> </ul> </dd> + <dt><code>deflate-on-oom</code></dt> + <dd> + <p> + The optional <code>deflate-on-oom</code> attribute allows to + enable/disable (values "on"/"off", respectively) the ability of the + QEMU virtio memory balloon to release some memory at the last moment + before a guest's process get killed by OOM-killer. + <span class="since">Since 1.3.1, QEMU and KVM only</span> + </p> + </dd> <dt><code>period</code></dt> <dd> <p> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4804c69..9587849 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3415,6 +3415,11 @@ <value>none</value> </choice> </attribute> + <optional> + <attribute name="deflate-on-oom">
Typically don't want those "-", either use some sort of single word or other attributes to have "_" This will of course have ramifications throughout the code. I'll only mention it here though.
+ <ref name="virOnOff"/> + </attribute> + </optional> <interleave> <optional> <ref name="alias"/> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5200c27..b332097 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11312,6 +11312,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, unsigned int flags) { char *model; + char *deflate; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; unsigned int period = 0; @@ -11332,6 +11333,13 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, goto error; }
+ if ((deflate = virXMLPropString(node, "deflate-on-oom")) && + (def->deflate = virTristateSwitchTypeFromString(deflate)) < 0) {
Since you're not using/allowing "default", then the comparison should be <= 0 yes, there are some others that are not correct it seems.
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid deflate-on-oom attribute value '%s'"), deflate); + goto error; + } + ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -11350,6 +11358,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
cleanup: VIR_FREE(model); + VIR_FREE(deflate);
ctxt->node = save; return def; @@ -17223,6 +17232,15 @@ virDomainMemballoonDefCheckABIStability(virDomainMemballoonDefPtr src, return false; }
+ if (src->deflate != dst->deflate) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target balloon deflate-on-oom attribute value " + "%s does not match source %s"), + virTristateSwitchTypeToString(dst->deflate), + virTristateSwitchTypeToString(src->deflate)); + return false; + } + if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) return false;
@@ -20390,6 +20408,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); + const char *deflate = virTristateSwitchTypeToString(def->deflate); virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; int indent = virBufferGetIndent(buf, false);
@@ -20400,6 +20419,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf, }
virBufferAsprintf(buf, "<memballoon model='%s'", model); + + if (def->deflate > 0 && deflate)
This would be use of def->deflate != VIR_TRISTATE_SWITCH_ABSENT
+ virBufferAsprintf(buf, " deflate-on-oom='%s'", deflate);
The 'deflate' isn't required - see other examples. Looks OK otherwise. John
+ virBufferAdjustIndent(&childrenBuf, indent + 2);
if (def->period) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cec681a..707ffb2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1634,6 +1634,7 @@ struct _virDomainMemballoonDef { int model; virDomainDeviceInfo info; int period; /* seconds between collections */ + int deflate; /* enum virTristateSwitch */ };
struct _virDomainNVRAMDef {

On 17.12.2015 23:25, John Ferlan wrote:
On 12/14/2015 06:35 AM, Dmitry Andreev wrote:
Excessive memory balloon inflation can cause invocation of OOM-killer, when Linux is under severe memory pressure. QEMU memballoon device has a feature to release some memory at the last moment before some process will be get killed by OOM-killer.
Introduced attribute allows to enable or disable this feature. --- docs/formatdomain.html.in | 10 ++++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 23 +++++++++++++++++++++++ src/conf/domain_conf.h | 1 + 4 files changed, 39 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a8bd48e..fa68e7b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5954,6 +5954,16 @@ qemu-kvm -net nic,model=? /dev/null <li>'xen' — default with Xen</li> </ul> </dd> + <dt><code>deflate-on-oom</code></dt> + <dd> + <p> + The optional <code>deflate-on-oom</code> attribute allows to + enable/disable (values "on"/"off", respectively) the ability of the + QEMU virtio memory balloon to release some memory at the last moment + before a guest's process get killed by OOM-killer. + <span class="since">Since 1.3.1, QEMU and KVM only</span> + </p> + </dd> <dt><code>period</code></dt> <dd> <p> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4804c69..9587849 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3415,6 +3415,11 @@ <value>none</value> </choice> </attribute> + <optional> + <attribute name="deflate-on-oom">
Typically don't want those "-", either use some sort of single word or other attributes to have "_"
Is it OK to use 'deflation' or 'deflate' word? Can't choose the name by myself.
This will of course have ramifications throughout the code. I'll only mention it here though.
+ <ref name="virOnOff"/> + </attribute> + </optional> <interleave> <optional> <ref name="alias"/> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5200c27..b332097 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11312,6 +11312,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, unsigned int flags) { char *model; + char *deflate; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; unsigned int period = 0; @@ -11332,6 +11333,13 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, goto error; }
+ if ((deflate = virXMLPropString(node, "deflate-on-oom")) && + (def->deflate = virTristateSwitchTypeFromString(deflate)) < 0) {
Since you're not using/allowing "default", then the comparison should be <= 0
yes, there are some others that are not correct it seems.
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid deflate-on-oom attribute value '%s'"), deflate); + goto error; + } + ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -11350,6 +11358,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
cleanup: VIR_FREE(model); + VIR_FREE(deflate);
ctxt->node = save; return def; @@ -17223,6 +17232,15 @@ virDomainMemballoonDefCheckABIStability(virDomainMemballoonDefPtr src, return false; }
+ if (src->deflate != dst->deflate) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target balloon deflate-on-oom attribute value " + "%s does not match source %s"), + virTristateSwitchTypeToString(dst->deflate), + virTristateSwitchTypeToString(src->deflate)); + return false; + } + if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) return false;
@@ -20390,6 +20408,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); + const char *deflate = virTristateSwitchTypeToString(def->deflate); virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; int indent = virBufferGetIndent(buf, false);
@@ -20400,6 +20419,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf, }
virBufferAsprintf(buf, "<memballoon model='%s'", model); + + if (def->deflate > 0 && deflate)
This would be use of def->deflate != VIR_TRISTATE_SWITCH_ABSENT
+ virBufferAsprintf(buf, " deflate-on-oom='%s'", deflate);
The 'deflate' isn't required - see other examples.
Looks OK otherwise.
John
+ virBufferAdjustIndent(&childrenBuf, indent + 2);
if (def->period) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cec681a..707ffb2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1634,6 +1634,7 @@ struct _virDomainMemballoonDef { int model; virDomainDeviceInfo info; int period; /* seconds between collections */ + int deflate; /* enum virTristateSwitch */ };
struct _virDomainNVRAMDef {

On 12/18/2015 08:20 AM, Dmitry Andreev wrote:
On 17.12.2015 23:25, John Ferlan wrote:
On 12/14/2015 06:35 AM, Dmitry Andreev wrote:
Excessive memory balloon inflation can cause invocation of OOM-killer, when Linux is under severe memory pressure. QEMU memballoon device has a feature to release some memory at the last moment before some process will be get killed by OOM-killer.
Introduced attribute allows to enable or disable this feature. --- docs/formatdomain.html.in | 10 ++++++++++ docs/schemas/domaincommon.rng | 5 +++++ src/conf/domain_conf.c | 23 +++++++++++++++++++++++ src/conf/domain_conf.h | 1 + 4 files changed, 39 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a8bd48e..fa68e7b 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5954,6 +5954,16 @@ qemu-kvm -net nic,model=? /dev/null <li>'xen' — default with Xen</li> </ul> </dd> + <dt><code>deflate-on-oom</code></dt> + <dd> + <p> + The optional <code>deflate-on-oom</code> attribute allows to + enable/disable (values "on"/"off", respectively) the ability of the + QEMU virtio memory balloon to release some memory at the last moment + before a guest's process get killed by OOM-killer. + <span class="since">Since 1.3.1, QEMU and KVM only</span> + </p> + </dd> <dt><code>period</code></dt> <dd> <p> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4804c69..9587849 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3415,6 +3415,11 @@ <value>none</value> </choice> </attribute> + <optional> + <attribute name="deflate-on-oom">
Typically don't want those "-", either use some sort of single word or other attributes to have "_"
Is it OK to use 'deflation' or 'deflate' word? Can't choose the name by myself.
How about 'autodeflate' ? I think that describes the feature adequately. John
This will of course have ramifications throughout the code. I'll only mention it here though.
+ <ref name="virOnOff"/> + </attribute> + </optional> <interleave> <optional> <ref name="alias"/> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5200c27..b332097 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11312,6 +11312,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, unsigned int flags) { char *model; + char *deflate; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; unsigned int period = 0; @@ -11332,6 +11333,13 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, goto error; }
+ if ((deflate = virXMLPropString(node, "deflate-on-oom")) && + (def->deflate = virTristateSwitchTypeFromString(deflate)) < 0) {
Since you're not using/allowing "default", then the comparison should be <= 0
yes, there are some others that are not correct it seems.
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid deflate-on-oom attribute value '%s'"), deflate); + goto error; + } + ctxt->node = node; if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -11350,6 +11358,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
cleanup: VIR_FREE(model); + VIR_FREE(deflate);
ctxt->node = save; return def; @@ -17223,6 +17232,15 @@ virDomainMemballoonDefCheckABIStability(virDomainMemballoonDefPtr src, return false; }
+ if (src->deflate != dst->deflate) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target balloon deflate-on-oom attribute value " + "%s does not match source %s"), + virTristateSwitchTypeToString(dst->deflate), + virTristateSwitchTypeToString(src->deflate)); + return false; + } + if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) return false;
@@ -20390,6 +20408,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); + const char *deflate = virTristateSwitchTypeToString(def->deflate); virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; int indent = virBufferGetIndent(buf, false);
@@ -20400,6 +20419,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf, }
virBufferAsprintf(buf, "<memballoon model='%s'", model); + + if (def->deflate > 0 && deflate)
This would be use of def->deflate != VIR_TRISTATE_SWITCH_ABSENT
+ virBufferAsprintf(buf, " deflate-on-oom='%s'", deflate);
The 'deflate' isn't required - see other examples.
Looks OK otherwise.
John
+ virBufferAdjustIndent(&childrenBuf, indent + 2);
if (def->period) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cec681a..707ffb2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1634,6 +1634,7 @@ struct _virDomainMemballoonDef { int model; virDomainDeviceInfo info; int period; /* seconds between collections */ + int deflate; /* enum virTristateSwitch */ };
struct _virDomainNVRAMDef {

xml: <devices> <memballoon model='virtio' deflate-on-oom='on'/> </devices> qemu: qemu -device virtio-balloon-pci,...,deflate-on-oom=on --- src/qemu/qemu_command.c | 4 ++++ .../qemuxml2argv-balloon-device-deflate-off.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate-off.xml | 25 ++++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.xml | 25 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 ++++ 6 files changed, 104 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d2f37e4..227ba8a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5708,6 +5708,10 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error; + if (dev->deflate > 0) + virBufferAsprintf(&buf, ",deflate-on-oom=%s", + virTristateSwitchTypeToString(dev->deflate)); + if (virBufferCheckError(&buf) < 0) goto error; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args new file mode 100644 index 0000000..1e64c1a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args @@ -0,0 +1,23 @@ +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 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=off diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml new file mode 100644 index 0000000..5e536a1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + </disk> + <memballoon model='virtio' deflate-on-oom='off'> + <address type='pci' domain='0' bus='0' slot='18' function='0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args new file mode 100644 index 0000000..18a2df9 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args @@ -0,0 +1,23 @@ +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 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=on diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml new file mode 100644 index 0000000..efecbc6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + </disk> + <memballoon model='virtio' deflate-on-oom='on'> + <address type='pci' domain='0' bus='0' slot='18' function='0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 37f806e..42a6aed 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1194,6 +1194,10 @@ mymain(void) QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_BOOTINDEX, QEMU_CAPS_VIRTIO_S390); DO_TEST("balloon-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-deflate", + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-deflate-off", + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-auto", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-period", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); -- 1.8.3.1

On 12/14/2015 06:35 AM, Dmitry Andreev wrote:
xml: <devices> <memballoon model='virtio' deflate-on-oom='on'/> </devices>
qemu: qemu -device virtio-balloon-pci,...,deflate-on-oom=on
Little light on the commit message Next question to be asked - how about being able to enable/disable for the running domain?! If the memory period/seconds can be adjusted dynamically I begin to wonder whether the feature is available for the running domain and perhaps through something for a setmem option?
--- src/qemu/qemu_command.c | 4 ++++ .../qemuxml2argv-balloon-device-deflate-off.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate-off.xml | 25 ++++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.args | 23 ++++++++++++++++++++ .../qemuxml2argv-balloon-device-deflate.xml | 25 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 4 ++++ 6 files changed, 104 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml
Nice - tests. obvious updates as a result of comments in 1/2... Just making sure - all the address types support in qemu_command.c can support this feature, right? PCI, CCW, MMIO Your tests only show PCI. Of course I have to ask - since as you note in your cover this feature was added to QEMU "a month ago" - why is there no capabilities check? What happens when (and it will happen) this is run on a host that doesn't have that capability for the balloon driver? You'll need to add some sort of capabilities or version check. If qemu didn't create one for this feature, then that really needs to be done. John
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d2f37e4..227ba8a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5708,6 +5708,10 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) goto error;
+ if (dev->deflate > 0) + virBufferAsprintf(&buf, ",deflate-on-oom=%s", + virTristateSwitchTypeToString(dev->deflate)); + if (virBufferCheckError(&buf) < 0) goto error;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args new file mode 100644 index 0000000..1e64c1a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.args @@ -0,0 +1,23 @@ +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 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=off diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml new file mode 100644 index 0000000..5e536a1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate-off.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + </disk> + <memballoon model='virtio' deflate-on-oom='off'> + <address type='pci' domain='0' bus='0' slot='18' function='0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args new file mode 100644 index 0000000..18a2df9 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.args @@ -0,0 +1,23 @@ +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 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-ide0-0-0,format=raw \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x12,deflate-on-oom=on diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml new file mode 100644 index 0000000..efecbc6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-deflate.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + </disk> + <memballoon model='virtio' deflate-on-oom='on'> + <address type='pci' domain='0' bus='0' slot='18' function='0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 37f806e..42a6aed 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1194,6 +1194,10 @@ mymain(void) QEMU_CAPS_DEVICE, QEMU_CAPS_CHARDEV, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_BOOTINDEX, QEMU_CAPS_VIRTIO_S390); DO_TEST("balloon-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-deflate", + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-deflate-off", + QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-auto", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-period", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
participants (2)
-
Dmitry Andreev
-
John Ferlan