Skip to contentSkip to conversation

virtio-balloon: improve balloon statistics

PATCH In review Denis V. Lunev 2 participants 9 messages Feb 24, 2016 – Mar 1, 2016

lore
Share & tools
lore
#0 lore raw

v3 cover virtio-balloon: improve balloon statistics

New counter from the Linux kernel + generic framework to pass currently unknown counters via QMP for debug purposes.

CC Igor Redko <[email protected]>
CC Michael S. Tsirkin <[email protected]>

Changes from v2:
- put "export unknown counters" code under ifdef

Changes from v1:
- removed !err in patch 1 by suggestion from Eric

#1 lore raw

PATCH v3 1/2 virtio-balloon: export all balloon statistics

From: Igor Redko <[email protected]>

We are making experiments with different autoballooning strategies based on the guest behavior. Thus we need to experiment with different guest statistics. For now every counter change requires QEMU recompilation and dances with Libvirt.

This patch introduces transport for unrecognized counters in virtio-balloon. This transport can be used for measuring benefits from using new balloon counters, before submitting any patches. Current alternative is 'guest-exec' transport which isn't made for such delicate matters and can influence test results.

Originally all counters with tag >= VIRTIO_BALLOON_S_NR were ignored. Instead of this we keep first (VIRTIO_BALLOON_S_NR + 32) counters from the queue and pass unrecognized ones with the following names: 'x-stat-XXXX', where XXXX is a tag number in hex. Defined counters are reported with their regular names.

---
 configure                          | 12 ++++++++++++
 hw/virtio/virtio-balloon.c         | 32 ++++++++++++++++++++++++++------
 include/hw/virtio/virtio-balloon.h |  3 ++-
 3 files changed, 40 insertions(+), 7 deletions(-)
configure +12 -0
index 0aa249b..a51b85c 100755
@@ -314,6 +314,7 @@ vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
+unknown_balloon_stats="no"
 
 # parse CC options first
 for opt do
@@ -1141,6 +1142,10 @@ for opt do
   ;;
   --enable-jemalloc) jemalloc="yes"
   ;;
+  --enable-unknown-balloon-stats) unknown_balloon_stats="yes"
+  ;;
+  --disable-unknown-balloon-stats) unknown_balloon_stats="no"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1363,6 +1368,8 @@ disabled with --disable-FEATURE, default is enabled if available:
   numa            libnuma support
   tcmalloc        tcmalloc support
   jemalloc        jemalloc support
+  unknown-balloon-stats  report unknown balloon statistics counters
+  ;;
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -4776,6 +4783,7 @@ echo "bzip2 support     $bzip2"
 echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
+echo "unknown balloon stat counters support  $unknown_balloon_stats"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5324,6 +5332,10 @@ if test "$rdma" = "yes" ; then
   echo "CONFIG_RDMA=y" >> $config_host_mak
 fi
 
+if test "$unknown_balloon_stats" = "yes" ; then
+  echo "CONFIG_UNKNOWN_BALLOON_STATS=y" >> $config_host_mak
+fi
+
 # Hold two types of flag:
 #   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
 #                                     a thread we have a handle to
hw/virtio/virtio-balloon.c +26 -6
index a382f43..6629145 100644
@@ -66,8 +66,7 @@ static const char *balloon_stat_names[] = {
  */
 static inline void reset_stats(VirtIOBalloon *dev)
 {
-    int i;
-    for (i = 0; i < VIRTIO_BALLOON_S_NR; dev->stats[i++] = -1);
+    dev->stats_cnt = 0;
 }
 
 static bool balloon_stats_supported(const VirtIOBalloon *s)
@@ -133,12 +132,22 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name,
     if (err) {
         goto out_end;
     }
-    for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) {
-        visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], &err);
+    for (i = 0; i < s->stats_cnt; i++) {
+        if (s->stats[i].tag < VIRTIO_BALLOON_S_NR) {
+            visit_type_uint64(v, balloon_stat_names[s->stats[i].tag],
+                              &s->stats[i].val, &err);
+        } else {
+#if defined(CONFIG_UNKNOWN_BALLOON_STATS)
+            gchar *str = g_strdup_printf("x-stat-%04x", s->stats[i].tag);
+            visit_type_uint64(v, str, &s->stats[i].val, &err);
+            g_free(str);
+#endif
+        }
         if (err) {
             break;
         }
     }
+
     error_propagate(errp, err);
     err = NULL;
     visit_end_struct(v, &err);
@@ -273,10 +282,21 @@ static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
            == sizeof(stat)) {
         uint16_t tag = virtio_tswap16(vdev, stat.tag);
         uint64_t val = virtio_tswap64(vdev, stat.val);
+        int i;
 
         offset += sizeof(stat);
-        if (tag < VIRTIO_BALLOON_S_NR)
-            s->stats[tag] = val;
+        for (i = 0; i < s->stats_cnt; i++) {
+            if (s->stats[i].tag == tag) {
+                break;
+            }
+        }
+        if (i < ARRAY_SIZE(s->stats)) {
+            s->stats[i].tag = tag;
+            s->stats[i].val = val;
+            if (s->stats_cnt <= i) {
+                s->stats_cnt = i + 1;
+            }
+        }
     }
     s->stats_vq_offset = offset;
 
include/hw/virtio/virtio-balloon.h +2 -1
index 35f62ac..5c8730e 100644
@@ -36,7 +36,8 @@ typedef struct VirtIOBalloon {
     VirtQueue *ivq, *dvq, *svq;
     uint32_t num_pages;
     uint32_t actual;
-    uint64_t stats[VIRTIO_BALLOON_S_NR];
+    VirtIOBalloonStatModern stats[VIRTIO_BALLOON_S_NR + 32];
+    uint16_t stats_cnt;
     VirtQueueElement *stats_vq_elem;
     size_t stats_vq_offset;
     QEMUTimer *stats_timer;
Signature · 1 line
2.1.4
#2 lore raw

PATCH v3 2/2 virtio-balloon: add 'available' counter

In reply to Denis V. Lunev

The patch for the kernel part is in linux-next already:
commit ac88e7c908b920866e529862f2b2f0129b254ab2
Author: Igor Redko <[email protected]>
Date: Thu Feb 18 09:23:01 2016 +1100

virtio_balloon: export 'available' memory to balloon statistics

Add a new field, VIRTIO_BALLOON_S_AVAIL, to virtio_balloon memory statistics protocol, corresponding to 'Available' in /proc/meminfo.

CC Igor Redko <[email protected]>
CC Michael S. Tsirkin <[email protected]>
---
 hw/virtio/virtio-balloon.c                      | 1 +
 include/standard-headers/linux/virtio_balloon.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +1 -0
index 6629145..3193f44 100644
@@ -53,6 +53,7 @@ static const char *balloon_stat_names[] = {
    [VIRTIO_BALLOON_S_MINFLT] = "stat-minor-faults",
    [VIRTIO_BALLOON_S_MEMFREE] = "stat-free-memory",
    [VIRTIO_BALLOON_S_MEMTOT] = "stat-total-memory",
+   [VIRTIO_BALLOON_S_AVAIL] = "stat-available-memory",
    [VIRTIO_BALLOON_S_NR] = NULL
 };
 
include/standard-headers/linux/virtio_balloon.h +2 -1
index 2e2a6dc..0df7c2e 100644
@@ -51,7 +51,8 @@ struct virtio_balloon_config {
 #define VIRTIO_BALLOON_S_MINFLT   3   /* Number of minor faults */
 #define VIRTIO_BALLOON_S_MEMFREE  4   /* Total amount of free memory */
 #define VIRTIO_BALLOON_S_MEMTOT   5   /* Total amount of memory */
-#define VIRTIO_BALLOON_S_NR       6
+#define VIRTIO_BALLOON_S_AVAIL    6   /* Amount of available memory in guest */
+#define VIRTIO_BALLOON_S_NR       7
 
 /*
  * Memory statistics structure.
Signature · 1 line
2.1.4
#3 lore raw
In reply to Denis V. Lunev
Quoted 1 line · Denis V. Lunev

New counter from the Linux kernel +

It is in AKPM's linux-next kernel but I will revert it there if the suggested interface extension is not submitted
to the Virtio ABI committee soon.

Quoted 12 lines

generic framework to pass currently unknown counters via QMP for debug purposes.

CC Igor Redko <[email protected]>
CC Michael S. Tsirkin <[email protected]>

Changes from v2:
- put "export unknown counters" code under ifdef

Changes from v1:
- removed !err in patch 1 by suggestion from Eric

#4 lore raw
Quoted 7 lines · Michael S. Tsirkin
Quoted 1 line · Denis V. Lunev

New counter from the Linux kernel +

It is in AKPM's linux-next kernel but I will revert it there if the suggested interface extension is not submitted
to the Virtio ABI committee soon.

can you pls pinpoint the contact and procedure then.

#6 lore raw
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Denis V. Lunev
Quoted 7 lines · Michael S. Tsirkin
Quoted 1 line · Denis V. Lunev

New counter from the Linux kernel +

It is in AKPM's linux-next kernel but I will revert it there if the suggested interface extension is not submitted
to the Virtio ABI committee soon.

can you pls pinpoint the contact and procedure then.

https://www.oasis-open.org/committees/comments/index.php?wg_abbrev=virtio

done with comment submission.

Can we proceed with this version if you do not like v2?

Den

#7 lore raw
In reply to Denis V. Lunev
Quoted 7 lines · Denis V. Lunev

New counter from the Linux kernel + generic framework to pass currently unknown counters via QMP for debug purposes.

CC Igor Redko <[email protected]>
CC Michael S. Tsirkin <[email protected]>
Quoted 7 lines

Changes from v2:
- put "export unknown counters" code under ifdef

Changes from v1:
- removed !err in patch 1 by suggestion from Eric

any decision on this?

#8 lore raw
Quoted 8 lines · Denis V. Lunev
Quoted 7 lines · Denis V. Lunev

New counter from the Linux kernel + generic framework to pass currently unknown counters via QMP for debug purposes.

CC Igor Redko <[email protected]>
CC Michael S. Tsirkin <[email protected]>
Quoted 8 lines
Quoted 7 lines

Changes from v2:
- put "export unknown counters" code under ifdef

Changes from v1:
- removed !err in patch 1 by suggestion from Eric

any decision on this?

Thanks, I will queue this up.

Signature · 1 line
MST