Skip to contentSkip to conversation

Disable virtio-balloon memory stats interface

PATCH In review Adam Litke 3 participants 9 messages Sep 8, 2010 – Sep 14, 2010

lore
Share & tools
lore

Adam Litke

author
#0 lore raw

PATCH 1/1 Disable virtio-balloon memory stats interface

The addition of memory stats reporting to the virtio balloon causes the 'info balloon' command to become asynchronous. This is a regression because in some cases it can hang the user monitor.

Disable this feature until a better interface for asynchronous commands can be worked out.

---
 hw/virtio-balloon.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
hw/virtio-balloon.c +11 -1
index 9fe3886..dcdada6 100644
@@ -190,7 +190,17 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
 
 static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)
 {
-    f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    /*
+     * The addition of memory stats reporting to the virtio balloon causes
+     * the 'info balloon' command to become asynchronous.  This is a regression
+     * because in some cases it can hang the user monitor.
+     *
+     * Disable this feature until a better interface for asynchronous commands
+     * can be worked out.
+     *
+     * -aglitke
+     */
+    /* f |= (1 << VIRTIO_BALLOON_F_STATS_VQ); */
     return f;
 }
 
Signature · 1 line
1.6.1.3
#1 lore raw
Quoted 22 lines · Adam Litke

The addition of memory stats reporting to the virtio balloon causes the 'info balloon' command to become asynchronous. This is a regression because in some cases it can hang the user monitor.

Disable this feature until a better interface for asynchronous commands can be worked out.

---
 hw/virtio-balloon.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
hw/virtio-balloon.c +1 -1
index 9fe3886..dcdada6 100644
@@ -190,7 +190,17 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
 
 static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)
 {
-    f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    /*

hw/virtio-balloon.c static void virtio_balloon_set_config(VirtIODevice *vdev, · line 203

Quoted 10 lines
hw/virtio-balloon.c +10 -0
+     * The addition of memory stats reporting to the virtio balloon causes
+     * the 'info balloon' command to become asynchronous.  This is a regression
+     * because in some cases it can hang the user monitor.
+     *
+     * Disable this feature until a better interface for asynchronous commands
+     * can be worked out.
+     *
+     * -aglitke
+     */
+    /* f |= (1 << VIRTIO_BALLOON_F_STATS_VQ); */

This field is guest-visible, won't this cause problems on migration?

Isn't it better to disable it on the "info balloon" side, so the guest knows that the host may start requesting stat info eventually? I suggest doing this:

---

hw/virtio-balloon.c +7 -1
index 1e4dfdd..92e9057 100644
@@ -30,6 +30,10 @@
 #include <sys/mman.h>
 #endif
 
+/* Disable guest-provided stats by now (bz#623903, bz#626544) */
+#define ENABLE_GUEST_STATS   0
+
+
 typedef struct VirtIOBalloon
 {
     VirtIODevice vdev;
@@ -84,12 +88,14 @@ static QObject *get_stats_qobject(VirtIOBalloon *dev)
                                   VIRTIO_BALLOON_PFN_SHIFT);
 
     stat_put(dict, "actual", actual);
+#if ENABLE_GUEST_STATS
     stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
     stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
     stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
     stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
     stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
     stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
+#endif
 
     return QOBJECT(dict);
 }
@@ -215,7 +221,7 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
         }
         dev->stats_callback = cb;
         dev->stats_opaque_callback_data = cb_data; 
-        if (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ)) {
+        if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) {
             virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
             virtio_notify(&dev->vdev, dev->svq);
         } else {
Signature · 1 line
Eduardo
author
#2 lore raw
Quoted 28 lines · Eduardo Habkost
Quoted 27 lines · Adam Litke

The addition of memory stats reporting to the virtio balloon causes the 'info balloon' command to become asynchronous. This is a regression because in some cases it can hang the user monitor.

Disable this feature until a better interface for asynchronous commands can be worked out.

---
 hw/virtio-balloon.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
hw/virtio-balloon.c +6 -1
index 9fe3886..dcdada6 100644
@@ -190,7 +190,17 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,
 
 static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f)
 {
-    f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    /*
+     * The addition of memory stats reporting to the virtio balloon causes
+     * the 'info balloon' command to become asynchronous.  This is a regression
+     * because in some cases it can hang the user monitor.
+     *
+     * Disable this feature until a better interface for asynchronous commands
Quoted 8 lines

hw/virtio-balloon.c static void virtio_balloon_set_config(VirtIODevice *vdev, · line 203

Quoted 5 lines
hw/virtio-balloon.c +5 -0
+     * can be worked out.
+     *
+     * -aglitke
+     */
+    /* f |= (1 << VIRTIO_BALLOON_F_STATS_VQ); */

This field is guest-visible, won't this cause problems on migration?

I haven't followed migration very closely, but isn't this a common problem whenever one migrates a vm to a newer version of qemu that has more features. I thought that virtio feature negotiation would ensure that stats have been disabled at the device level and would remain disabled post migration. Please correct me if I am mistaken.

Quoted 3 lines

Isn't it better to disable it on the "info balloon" side, so the guest knows that the host may start requesting stat info eventually? I suggest doing this:

While I think this method would also work, I would really like to use the feature bit if possible, since that is what the mechanism is designed for.

Quoted 41 lines

---

hw/virtio-balloon.c +7 -1
index 1e4dfdd..92e9057 100644
@@ -30,6 +30,10 @@
 #include <sys/mman.h>
 #endif
 
+/* Disable guest-provided stats by now (bz#623903, bz#626544) */
+#define ENABLE_GUEST_STATS   0
+
+
 typedef struct VirtIOBalloon
 {
     VirtIODevice vdev;
@@ -84,12 +88,14 @@ static QObject *get_stats_qobject(VirtIOBalloon *dev)
                                   VIRTIO_BALLOON_PFN_SHIFT);
 
     stat_put(dict, "actual", actual);
+#if ENABLE_GUEST_STATS
     stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
     stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
     stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
     stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
     stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
     stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
+#endif
 
     return QOBJECT(dict);
 }
@@ -215,7 +221,7 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
         }
         dev->stats_callback = cb;
         dev->stats_opaque_callback_data = cb_data; 
-        if (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ)) {
+        if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) {
             virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
             virtio_notify(&dev->vdev, dev->svq);
         } else {
Signature · 2 lines
Thanks,
Adam
#3 lore raw
Quoted 2 lines · Adam Litke
Quoted 1 line · Eduardo Habkost

On Wed, Sep 08, 2010 at 09:21:16AM -0500, Adam Litke wrote:

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 14 lines

static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f) {

(quoted diff) +11 -1
-    f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    /*
+     * The addition of memory stats reporting to the virtio balloon causes
+     * the 'info balloon' command to become asynchronous.  This is a regression
+     * because in some cases it can hang the user monitor.
+     *
+     * Disable this feature until a better interface for asynchronous commands
+     * can be worked out.
+     *
+     * -aglitke
+     */
+    /* f |= (1 << VIRTIO_BALLOON_F_STATS_VQ); */
Quoted 7 lines
Quoted 1 line

This field is guest-visible, won't this cause problems on migration?

I haven't followed migration very closely, but isn't this a common problem whenever one migrates a vm to a newer version of qemu that has more features. I thought that virtio feature negotiation would ensure that stats have been disabled at the device level and would remain disabled post migration. Please correct me if I am mistaken.

If this is the case, then it's another reason to keep the feature bit
enabled: the feature bit just let the guest know that the host may request balloon stats at any moment, and it's better to keep that capability in case the guest is migrated, isn't it?

Also, what happens if we try to migrate from a qemu version that had the feature bit set to a qemu version without this feature bit?

I don't know the details either, but even if this works gracefully for migration in both directions, it sound much simpler to not change the guest-visible machine model and just change the "info balloon" behavior.

Quoted 8 lines
Quoted 4 lines

Isn't it better to disable it on the "info balloon" side, so the guest knows that the host may start requesting stat info eventually? I suggest doing this:

While I think this method would also work, I would really like to use the feature bit if possible, since that is what the mechanism is designed for.

My point is that if we can avoid making guest-visible changes easily, we should do that. It doesn't matter for the guest what the "info balloon" command does.

Signature · 1 line
Eduardo
#4 lore raw
Quoted 33 lines · Eduardo Habkost
Quoted 2 lines · Adam Litke
Quoted 1 line · Eduardo Habkost

On Wed, Sep 08, 2010 at 09:21:16AM -0500, Adam Litke wrote:

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 14 lines

static uint32_t virtio_balloon_get_features(VirtIODevice *vdev, uint32_t f) {

(quoted diff) +11 -1
-    f |= (1 << VIRTIO_BALLOON_F_STATS_VQ);
+    /*
+     * The addition of memory stats reporting to the virtio balloon causes
+     * the 'info balloon' command to become asynchronous.  This is a regression
+     * because in some cases it can hang the user monitor.
+     *
+     * Disable this feature until a better interface for asynchronous commands
+     * can be worked out.
+     *
+     * -aglitke
+     */
+    /* f |= (1 << VIRTIO_BALLOON_F_STATS_VQ); */
Quoted 7 lines
Quoted 1 line

This field is guest-visible, won't this cause problems on migration?

I haven't followed migration very closely, but isn't this a common problem whenever one migrates a vm to a newer version of qemu that has more features. I thought that virtio feature negotiation would ensure that stats have been disabled at the device level and would remain disabled post migration. Please correct me if I am mistaken.

If this is the case, then it's another reason to keep the feature bit
enabled: the feature bit just let the guest know that the host may request balloon stats at any moment, and it's better to keep that capability in case the guest is migrated, isn't it?

Quoted 6 lines

Also, what happens if we try to migrate from a qemu version that had the feature bit set to a qemu version without this feature bit?

I don't know the details either, but even if this works gracefully for migration in both directions, it sound much simpler to not change the guest-visible machine model and just change the "info balloon" behavior.

It looks worse than that: by disabling this feature you will break migration from older qemu versions that had the old "info balloon" behavior.

This is the incoming virtio migration code:

int virtio_load(VirtIODevice *vdev, QEMUFile *f) {
[...]
uint32_t supported_features =
vdev->binding->get_features(vdev->binding_opaque);
[...]

    qemu_get_8s(f, &vdev->status);
    qemu_get_8s(f, &vdev->isr);
    qemu_get_be16s(f, &vdev->queue_sel);
    qemu_get_be32s(f, &features);
    if (features & ~supported_features) {
        fprintf(stderr, "Features 0x%x unsupported. Allowed features: 0x%x\n",
                features, supported_features);
        return -1;
    }

[...]

To make things worse: virtio_net_load() doesn't check the return value of virtio_load(), so it will probably crash in an unpredictable way.

I keep my suggestion: if all we need is to change the way "info balloon" behaves, then we can simply change the "info balloon" behavior, intead of changing the guest-visible machine model.

Signature · 1 line
Eduardo
#5 lore raw
Quoted 3 lines · On Tue, 14 Sep 2010 12:42:00 -0300 Eduardo Habkost <[email protected]> wrote:

I keep my suggestion: if all we need is to change the way "info balloon" behaves, then we can simply change the "info balloon" behavior, intead of changing the guest-visible machine model.

Adam, what problems do you see with this solution?

We need to resolve this asap for 0.13.

author
#6 lore raw
Quoted 8 lines · Luiz Capitulino
Quoted 3 lines · On Tue, 14 Sep 2010 12:42:00 -0300 Eduardo Habkost <[email protected]> wrote:

I keep my suggestion: if all we need is to change the way "info balloon" behaves, then we can simply change the "info balloon" behavior, intead of changing the guest-visible machine model.

Adam, what problems do you see with this solution?

I have been sufficiently convinced that the feature bits won't work nicely in the face of migration.

Quoted 1 line

We need to resolve this asap for 0.13.

Let's go ahead with Eduardo's patch then.

Signature · 2 lines
Thanks,
Adam
author Acked-by
#8 lore raw
In reply to Eduardo Habkost

Ok, I can see how this will work better for the migration case.

Quoted 47 lines · Eduardo Habkost

This field is guest-visible, won't this cause problems on migration?

Isn't it better to disable it on the "info balloon" side, so the guest knows that the host may start requesting stat info eventually? I suggest doing this:

---

hw/virtio-balloon.c +7 -1
index 1e4dfdd..92e9057 100644
@@ -30,6 +30,10 @@
 #include <sys/mman.h>
 #endif
 
+/* Disable guest-provided stats by now (bz#623903, bz#626544) */
+#define ENABLE_GUEST_STATS   0
+
+
 typedef struct VirtIOBalloon
 {
     VirtIODevice vdev;
@@ -84,12 +88,14 @@ static QObject *get_stats_qobject(VirtIOBalloon *dev)
                                   VIRTIO_BALLOON_PFN_SHIFT);
 
     stat_put(dict, "actual", actual);
+#if ENABLE_GUEST_STATS
     stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
     stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
     stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
     stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
     stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
     stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
+#endif
 
     return QOBJECT(dict);
 }
@@ -215,7 +221,7 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
         }
         dev->stats_callback = cb;
         dev->stats_opaque_callback_data = cb_data; 
-        if (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ)) {
+        if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) {
             virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
             virtio_notify(&dev->vdev, dev->svq);
         } else {
Signature · 2 lines
Thanks,
Adam
#7 lore raw
In reply to Adam Litke
Quoted 8 lines · On Tue, 14 Sep 2010 10:59:56 -0500 Adam Litke <[email protected]> wrote:
Quoted 7 lines · Luiz Capitulino
Quoted 3 lines · On Tue, 14 Sep 2010 12:42:00 -0300 Eduardo Habkost <[email protected]> wrote:

I keep my suggestion: if all we need is to change the way "info balloon" behaves, then we can simply change the "info balloon" behavior, intead of changing the guest-visible machine model.

Quoted 8 lines
Quoted 1 line

Adam, what problems do you see with this solution?

I have been sufficiently convinced that the feature bits won't work nicely in the face of migration.

Quoted 1 line

We need to resolve this asap for 0.13.

Let's go ahead with Eduardo's patch then.

Ok, Eduardo can you send your patch again? As a new thread, so that it's easier to Anthony's scripts.