Skip to contentSkip to conversation

qga: add guest-get-memory-info (for 2.5)

RFC In review [email protected] 3 participants 8 messages Jul 31, 2015

lore
Share & tools
lore
#0 lore raw

cover qga: add guest-get-memory-info (for 2.5)

From: Marc-André Lureau <[email protected]>

This series implement a new qemu guest agent command to get memory information from the guest. This is based on ovirt-guest-agent "memory-stats" message.

I couldn't find documentation for the ovirt message, but the list of fields are summarized in this test
https://github.com/oVirt/ovirt-guest-agent/blob/master/tests/message_validator.py#L137
and according to how they are populated in the code, I adapted it to the following GuestMemoryInfo structure fields:

- mem-total: Total usable RAM.
- mem-free: Total of RAM that can be used without having to swap contents to disk.
- mem-cached: In-RAM cache.
- swap-total: Total amount of swap space available.
- swap-free: Amount of swap space that is currently unused.
- swap-in: Number of pages swapped-in per second.
- swap-out: Number of pages swapped-out per second.
- pf-major: Number of major page fault per second.
- pf-minor: Number of minor page fault per second.

Implemented on Linux and Win32 based on ovirt implementations.

Note: the "per second" value differ between Linux and Win32. On Linux, the value is computed based on the average since the last query, however on win32 this seems to be an instantaneous value (they have spikes, but often at 0). I have asked for help on SF:

http://serverfault.com/questions/709943/windows-equivalent-of-linux-vmstat-pswpin-and-pgfault

Related to RFE:
https://bugzilla.redhat.com/show_bug.cgi?id=1101915

Marc-André Lureau (3):
qga: add guest-get-memory-info json
qga: implement get-memory-info for Linux
qga: implement get-memory-info on win32

 configure            |   1 +
 qga/commands-posix.c | 102 +++++++++++++++++++++++++++++++
 qga/commands-win32.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++
 qga/main.c           |  28 +++++++++
 qga/qapi-schema.json |  48 +++++++++++++++
 5 files changed, 345 insertions(+)
Signature · 1 line
2.4.3
#1 lore raw

RFC 1/3 qga: add guest-get-memory-info json

From: Marc-André Lureau <[email protected]>

Define a new guest agent message, and document it.

---
 qga/commands-posix.c | 12 ++++++++++++
 qga/commands-win32.c |  6 ++++++
 qga/qapi-schema.json | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
qga/commands-posix.c +12 -0
index 675f4b4..eb4036e 100644
@@ -2328,8 +2328,20 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp)
     return info;
 }
 
+GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
+
 #else /* defined(__linux__) */
 
+GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
+
 void qmp_guest_suspend_disk(Error **errp)
 {
     error_setg(errp, QERR_UNSUPPORTED);
qga/commands-win32.c +6 -0
index 77d3c92..bf9cd93 100644
@@ -1332,3 +1332,9 @@ void ga_command_state_init(GAState *s, GACommandState *cs)
     }
     ga_command_state_add(cs, guest_file_init, NULL);
 }
+
+GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
qga/qapi-schema.json +48 -0

51 lines not on this page · raw message

Signature · 1 line
2.4.3
#2 lore raw

RFC 2/3 qga: implement get-memory-info for Linux

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

---
 qga/commands-posix.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 qga/main.c           | 28 ++++++++++++++++
 2 files changed, 120 insertions(+), 2 deletions(-)
qga/commands-posix.c +92 -2
index eb4036e..9534c2d 100644
@@ -28,6 +28,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/queue.h"
 #include "qemu/host-utils.h"
+#include "glib-compat.h"
 
 #ifndef CONFIG_HAS_ENVIRON
 #ifdef __APPLE__
@@ -2328,10 +2329,99 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp)
     return info;
 }
 
+static long meminfo_value(gchar * const *col)
+{
+    int i;
+
+    g_return_val_if_fail(col && col[0], 0);
+
+    for (i = 1; col[i]; i++) {
+        if (strlen(col[i]) > 0) {
+            return g_ascii_strtoll(col[i], NULL, 10);
+        }
+    }
+
+    g_return_val_if_reached(0);
+}
+
 GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
 {
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
+    static guint64 last_time, last_swap_in, last_swap_out;
+    static guint64 last_pf_major, last_pf_minor;
+    GError *err = NULL;
+    GuestMemoryInfo *info;
+    gchar *contents = NULL;
+    gchar **lines;
+    int i;
+    guint64 time;
+
+    if (!g_file_get_contents("/proc/meminfo", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        return NULL;
+    }
+
+    info = g_new0(GuestMemoryInfo, 1);
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "MemTotal:") == 0) {
+            info->mem_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "MemAvailable:") == 0) {
+            /* available since kernel 3.2 */
+            info->mem_free = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "Cached:") == 0) {
+            info->mem_cached = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapTotal:") == 0) {
+            info->swap_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapFree:") == 0) {
+            info->swap_free = meminfo_value(col);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+    g_free(contents);
+
+    if (!g_file_get_contents("/proc/vmstat", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        g_free(info);
+        return NULL;
+    }
+
+    time = g_get_monotonic_time();
+    double elapsed = (time - last_time + 1) / (double)G_USEC_PER_SEC;
+
+#define UPDATE(Field) do {                              \
+    guint64 val = g_ascii_strtoll(col[1], NULL, 10);    \
+    info->Field = (val - last_ ##Field) / elapsed;      \
+    last_ ##Field = val;                                \
+} while (0)
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "pswpin") == 0) {
+            UPDATE(swap_in);
+        } else if (g_strcmp0(col[0], "pswpout") == 0) {
+            UPDATE(swap_out);
+        } else if (g_strcmp0(col[0], "pgfault") == 0) {
+            UPDATE(pf_minor);
+        } else if (g_strcmp0(col[0], "pgmajfault") == 0) {
+            UPDATE(pf_major);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+#undef UPDATE
+
+    last_time = time;
+    g_free(contents);
+
+    return info;
 }
 
 #else /* defined(__linux__) */
qga/main.c +28 -0
index aef007b..4790e26 100644
@@ -42,6 +42,7 @@
 #define CONFIG_FSFREEZE
 #endif
 #endif
+#include "qga-qmp-commands.h"
 
 #ifndef _WIN32
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
@@ -901,6 +902,31 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
     return handle;
 }
 
+static void initialize_memory_stats(void)
+{
+    GuestMemoryInfo *info = qmp_guest_get_memory_info(NULL);
+
+    if (!info) {
+        return;
+    }
+
+    /* just for checking at start if everything looks ok */
+    g_debug("mem-total: %" G_GUINT64_FORMAT " kB\n"
+            "mem-free: %" G_GUINT64_FORMAT " kB\n"
+            "mem-cached: %" G_GUINT64_FORMAT " kB\n"
+            "swap-total: %" G_GUINT64_FORMAT " kB\n"
+            "swap-free: %" G_GUINT64_FORMAT " kB\n"
+            "swap-in: %" G_GUINT64_FORMAT " kB\n"
+            "swap-out: %" G_GUINT64_FORMAT " kB\n"
+            "pf-major: %" G_GUINT64_FORMAT " kB\n"
+            "pf-minor: %" G_GUINT64_FORMAT " kB\n",
+            info->mem_total, info->mem_free, info->mem_cached,
+            info->swap_total, info->swap_free, info->swap_in, info->swap_out,
+            info->pf_major, info->pf_minor);
+
+    g_free(info);
+}
+
 static void ga_print_cmd(QmpCommand *cmd, void *opaque)
 {
     printf("%s\n", qmp_command_name(cmd));
@@ -1256,6 +1282,8 @@ static int run_agent(GAState *s)
     }
 #endif
 
+    initialize_memory_stats();
+
     s->main_loop = g_main_loop_new(NULL, false);
     if (!channel_init(ga_state, method, device_path)) {
         g_critical("failed to initialize guest agent channel");
Signature · 1 line
2.4.3
#3 lore raw

Re: [Qemu-devel] [RFC 2/3] qga: implement get-memory-info for Linux

Quoted 21 lines · On Fri, Jul 31, 2015 at 07:36:48PM +0200, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

---
 qga/commands-posix.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 qga/main.c           | 28 ++++++++++++++++
 2 files changed, 120 insertions(+), 2 deletions(-)
qga/commands-posix.c +1 -0
index eb4036e..9534c2d 100644
@@ -28,6 +28,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/queue.h"
 #include "qemu/host-utils.h"
+#include "glib-compat.h"
 
 #ifndef CONFIG_HAS_ENVIRON
 #ifdef __APPLE__

qga/commands-posix.c GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) · line 2332

Quoted 4 lines
qga/commands-posix.c +1 -0
@@ -2328,10 +2329,99 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp)
     return info;
 }
 
+static long meminfo_value(gchar * const *col)

Don't we need to use uint64 here not long, since we're assigning to struct fields which are uint64 and on 32-bit host using long might result in wraparound.

Quoted 127 lines
qga/commands-posix.c +90 -2
+{
+    int i;
+
+    g_return_val_if_fail(col && col[0], 0);
+
+    for (i = 1; col[i]; i++) {
+        if (strlen(col[i]) > 0) {
+            return g_ascii_strtoll(col[i], NULL, 10);
+        }
+    }
+
+    g_return_val_if_reached(0);
+}
+
 GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
 {
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
+    static guint64 last_time, last_swap_in, last_swap_out;
+    static guint64 last_pf_major, last_pf_minor;
+    GError *err = NULL;
+    GuestMemoryInfo *info;
+    gchar *contents = NULL;
+    gchar **lines;
+    int i;
+    guint64 time;
+
+    if (!g_file_get_contents("/proc/meminfo", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        return NULL;
+    }
+
+    info = g_new0(GuestMemoryInfo, 1);
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "MemTotal:") == 0) {
+            info->mem_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "MemAvailable:") == 0) {
+            /* available since kernel 3.2 */
+            info->mem_free = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "Cached:") == 0) {
+            info->mem_cached = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapTotal:") == 0) {
+            info->swap_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapFree:") == 0) {
+            info->swap_free = meminfo_value(col);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+    g_free(contents);
+
+    if (!g_file_get_contents("/proc/vmstat", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        g_free(info);
+        return NULL;
+    }
+
+    time = g_get_monotonic_time();
+    double elapsed = (time - last_time + 1) / (double)G_USEC_PER_SEC;
+
+#define UPDATE(Field) do {                              \
+    guint64 val = g_ascii_strtoll(col[1], NULL, 10);    \
+    info->Field = (val - last_ ##Field) / elapsed;      \
+    last_ ##Field = val;                                \
+} while (0)
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "pswpin") == 0) {
+            UPDATE(swap_in);
+        } else if (g_strcmp0(col[0], "pswpout") == 0) {
+            UPDATE(swap_out);
+        } else if (g_strcmp0(col[0], "pgfault") == 0) {
+            UPDATE(pf_minor);
+        } else if (g_strcmp0(col[0], "pgmajfault") == 0) {
+            UPDATE(pf_major);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+#undef UPDATE
+
+    last_time = time;
+    g_free(contents);
+
+    return info;
 }
 
 #else /* defined(__linux__) */
qga/main.c +15 -0
index aef007b..4790e26 100644
@@ -42,6 +42,7 @@
 #define CONFIG_FSFREEZE
 #endif
 #endif
+#include "qga-qmp-commands.h"
 
 #ifndef _WIN32
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
@@ -901,6 +902,31 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
     return handle;
 }
 
+static void initialize_memory_stats(void)
+{
+    GuestMemoryInfo *info = qmp_guest_get_memory_info(NULL);
+
+    if (!info) {
+        return;
+    }
+
+    /* just for checking at start if everything looks ok */
+    g_debug("mem-total: %" G_GUINT64_FORMAT " kB\n"
+            "mem-free: %" G_GUINT64_FORMAT " kB\n"
+            "mem-cached: %" G_GUINT64_FORMAT " kB\n"
+            "swap-total: %" G_GUINT64_FORMAT " kB\n"
+            "swap-free: %" G_GUINT64_FORMAT " kB\n"

qga/main.c int64_t ga_get_fd_handle(GAState *s, Error **errp) · line 928

Quoted 10 lines
qga/main.c +10 -0
+            "swap-in: %" G_GUINT64_FORMAT " kB\n"
+            "swap-out: %" G_GUINT64_FORMAT " kB\n"
+            "pf-major: %" G_GUINT64_FORMAT " kB\n"
+            "pf-minor: %" G_GUINT64_FORMAT " kB\n",
+            info->mem_total, info->mem_free, info->mem_cached,
+            info->swap_total, info->swap_free, info->swap_in, info->swap_out,
+            info->pf_major, info->pf_minor);
+
+    g_free(info);
+}

Wouldn't we be better off just adding a proper unit test for the code. We could copy a few same /proc/meminfo commands from various different Linux architectures and versions and then test parsing of them.

qga/main.c static int run_agent(GAState *s) · line 1289

Quoted 13 lines
qga/main.c +3 -0
+
 static void ga_print_cmd(QmpCommand *cmd, void *opaque)
 {
     printf("%s\n", qmp_command_name(cmd));
@@ -1256,6 +1282,8 @@ static int run_agent(GAState *s)
     }
 #endif
 
+    initialize_memory_stats();
+
     s->main_loop = g_main_loop_new(NULL, false);
     if (!channel_init(ga_state, method, device_path)) {
         g_critical("failed to initialize guest agent channel");

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#4 lore raw

Re: [Qemu-devel] [RFC 2/3] qga: implement get-memory-info for Linux

----- Original Message -----

Quoted 27 lines · On Fri, Jul 31, 2015 at 07:36:48PM +0200, [email protected] wrote:
Quoted 26 lines

From: Marc-André Lureau <[email protected]>

---
 qga/commands-posix.c | 94
 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 qga/main.c           | 28 ++++++++++++++++
 2 files changed, 120 insertions(+), 2 deletions(-)
qga/commands-posix.c +1 -0
index eb4036e..9534c2d 100644
@@ -28,6 +28,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/queue.h"
 #include "qemu/host-utils.h"
+#include "glib-compat.h"
 
 #ifndef CONFIG_HAS_ENVIRON
 #ifdef __APPLE__
@@ -2328,10 +2329,99 @@ GuestMemoryBlockInfo
 *qmp_guest_get_memory_block_info(Error **errp)
     return info;
 }
 
Quoted 5 lines

qga/commands-posix.c GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) · line 2332

Quoted 1 line
qga/commands-posix.c +1 -0
+static long meminfo_value(gchar * const *col)

Don't we need to use uint64 here not long, since we're assigning to struct fields which are uint64 and on 32-bit host using long might result in wraparound.

Yes, thanks

Quoted 136 lines
Quoted 136 lines
qga/commands-posix.c +90 -2
+{
+    int i;
+
+    g_return_val_if_fail(col && col[0], 0);
+
+    for (i = 1; col[i]; i++) {
+        if (strlen(col[i]) > 0) {
+            return g_ascii_strtoll(col[i], NULL, 10);
+        }
+    }
+
+    g_return_val_if_reached(0);
+}
+
 GuestMemoryInfo *qmp_guest_get_memory_info(Error **errp)
 {
-    error_setg(errp, QERR_UNSUPPORTED);
-    return NULL;
+    static guint64 last_time, last_swap_in, last_swap_out;
+    static guint64 last_pf_major, last_pf_minor;
+    GError *err = NULL;
+    GuestMemoryInfo *info;
+    gchar *contents = NULL;
+    gchar **lines;
+    int i;
+    guint64 time;
+
+    if (!g_file_get_contents("/proc/meminfo", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        return NULL;
+    }
+
+    info = g_new0(GuestMemoryInfo, 1);
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "MemTotal:") == 0) {
+            info->mem_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "MemAvailable:") == 0) {
+            /* available since kernel 3.2 */
+            info->mem_free = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "Cached:") == 0) {
+            info->mem_cached = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapTotal:") == 0) {
+            info->swap_total = meminfo_value(col);
+        } else if (g_strcmp0(col[0], "SwapFree:") == 0) {
+            info->swap_free = meminfo_value(col);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+    g_free(contents);
+
+    if (!g_file_get_contents("/proc/vmstat", &contents, NULL, &err)) {
+        error_setg(errp, "unable to read meminfo: %s", err->message);
+        g_clear_error(&err);
+        g_free(info);
+        return NULL;
+    }
+
+    time = g_get_monotonic_time();
+    double elapsed = (time - last_time + 1) / (double)G_USEC_PER_SEC;
+
+#define UPDATE(Field) do {                              \
+    guint64 val = g_ascii_strtoll(col[1], NULL, 10);    \
+    info->Field = (val - last_ ##Field) / elapsed;      \
+    last_ ##Field = val;                                \
+} while (0)
+
+    lines = g_strsplit(contents, "\n", -1);
+    for (i = 0; lines[i]; i++) {
+        gchar **col = g_strsplit(lines[i], " ", -1);
+        if (g_strcmp0(col[0], "pswpin") == 0) {
+            UPDATE(swap_in);
+        } else if (g_strcmp0(col[0], "pswpout") == 0) {
+            UPDATE(swap_out);
+        } else if (g_strcmp0(col[0], "pgfault") == 0) {
+            UPDATE(pf_minor);
+        } else if (g_strcmp0(col[0], "pgmajfault") == 0) {
+            UPDATE(pf_major);
+        }
+        g_strfreev(col);
+    }
+    g_strfreev(lines);
+
+#undef UPDATE
+
+    last_time = time;
+    g_free(contents);
+
+    return info;
 }
 

#else /* defined(__linux__) */

qga/main.c +22 -0
index aef007b..4790e26 100644
@@ -42,6 +42,7 @@
 #define CONFIG_FSFREEZE
 #endif
 #endif
+#include "qga-qmp-commands.h"
 
 #ifndef _WIN32
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
@@ -901,6 +902,31 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
     return handle;
 }
 
+static void initialize_memory_stats(void)
+{
+    GuestMemoryInfo *info = qmp_guest_get_memory_info(NULL);
+
+    if (!info) {
+        return;
+    }
+
+    /* just for checking at start if everything looks ok */
+    g_debug("mem-total: %" G_GUINT64_FORMAT " kB\n"
+            "mem-free: %" G_GUINT64_FORMAT " kB\n"
+            "mem-cached: %" G_GUINT64_FORMAT " kB\n"
+            "swap-total: %" G_GUINT64_FORMAT " kB\n"
+            "swap-free: %" G_GUINT64_FORMAT " kB\n"
+            "swap-in: %" G_GUINT64_FORMAT " kB\n"
+            "swap-out: %" G_GUINT64_FORMAT " kB\n"
+            "pf-major: %" G_GUINT64_FORMAT " kB\n"
+            "pf-minor: %" G_GUINT64_FORMAT " kB\n",
+            info->mem_total, info->mem_free, info->mem_cached,
+            info->swap_total, info->swap_free, info->swap_in,
 info->swap_out,
+            info->pf_major, info->pf_minor);
Quoted 8 lines

qga/main.c int64_t ga_get_fd_handle(GAState *s, Error **errp) · line 929

Quoted 3 lines
qga/main.c +3 -0
+
+    g_free(info);
+}

Wouldn't we be better off just adding a proper unit test for the code. We could copy a few same /proc/meminfo commands from various different Linux architectures and versions and then test parsing of them.

Sure, but a debug dump is still useful, doesn't hurt much. It doesn' look like there are unit tests for qga. It'd something worth to look at.

Quoted 23 lines

qga/main.c static int run_agent(GAState *s) · line 1289

Quoted 13 lines
qga/main.c +1 -0
+
 static void ga_print_cmd(QmpCommand *cmd, void *opaque)
 {
     printf("%s\n", qmp_command_name(cmd));
qga/main.c +2 -0
@@ -1256,6 +1282,8 @@ static int run_agent(GAState *s)
     }
 #endif
 
+    initialize_memory_stats();
+
     s->main_loop = g_main_loop_new(NULL, false);
     if (!channel_init(ga_state, method, device_path)) {
         g_critical("failed to initialize guest agent channel");

Regards,
Daniel
--

|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#5 lore raw

RFC 3/3 qga: implement get-memory-info on win32

In reply to [email protected]

From: Marc-André Lureau <[email protected]>

---
 configure            |   1 +
 qga/commands-win32.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 163 insertions(+), 2 deletions(-)
configure +1 -0
index c5c4b82..82ee185 100755
@@ -734,6 +734,7 @@ if test "$mingw32" = "yes" ; then
   local_statedir=
   confsuffix=""
   libs_qga="-lws2_32 -lwinmm -lpowrprof -liphlpapi -lnetapi32 $libs_qga"
+  libs_qga="-lole32 -loleaut32 -lwbemuuid -lpsapi $libs_qga"
 fi
 
 werror=""
qga/commands-win32.c +162 -2

176 lines not on this page · raw message

Signature · 1 line
2.4.3
#6 lore raw
In reply to [email protected]
Quoted 22 lines · On Fri, Jul 31, 2015 at 07:36:46PM +0200, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

This series implement a new qemu guest agent command to get memory information from the guest. This is based on ovirt-guest-agent "memory-stats" message.

I couldn't find documentation for the ovirt message, but the list of fields are summarized in this test
https://github.com/oVirt/ovirt-guest-agent/blob/master/tests/message_validator.py#L137
and according to how they are populated in the code, I adapted it to the following GuestMemoryInfo structure fields:

- mem-total: Total usable RAM.
- mem-free: Total of RAM that can be used without having to swap contents to disk.
- mem-cached: In-RAM cache.
- swap-total: Total amount of swap space available.
- swap-free: Amount of swap space that is currently unused.
- swap-in: Number of pages swapped-in per second.
- swap-out: Number of pages swapped-out per second.
- pf-major: Number of major page fault per second.
- pf-minor: Number of minor page fault per second.

Quoted 1 line

Implemented on Linux and Win32 based on ovirt implementations.

Interesting, currently the libvirt virDomainGetMemoryStats() API is backed by data we obtain from the virtio-balloon driver via QEMU monitor. For Linux at least this provides equiv of your mem-total, mem-free, swap-in, swap-out pf-major and pf-minor. So it lacks mem-cached, swap-total and swap-free I'm unclear in the Windows balloon driver supports this data or not too.

Quoted 9 lines

Note: the "per second" value differ between Linux and Win32. On Linux, the value is computed based on the average since the last query, however on win32 this seems to be an instantaneous value (they have spikes, but often at 0). I have asked for help on SF:

http://serverfault.com/questions/709943/windows-equivalent-of-linux-vmstat-pswpin-and-pgfault

Related to RFE:
https://bugzilla.redhat.com/show_bug.cgi?id=1101915

I wonder if we would be better off extending the balloon driver to fill in the gaps we have there vs this guest agent impl. With the balloon agent we set things up so that the guest device periodically pushes the updated stats to QEMU. So when we're querying QEMU for the stats we don't actually block waiting on the guest OS at all, QEMU can answer directly. This feels more appealing that querying the guest agent where we have no reasonable expectation of prompt response. With a large enough number of guests, I think the balloon driver push approach will scale better than a guest agent approach.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#7 lore raw

Hi

----- Original Message -----

Quoted 24 lines · On Fri, Jul 31, 2015 at 07:36:46PM +0200, [email protected] wrote:
Quoted 23 lines

From: Marc-André Lureau <[email protected]>

This series implement a new qemu guest agent command to get memory information from the guest. This is based on ovirt-guest-agent "memory-stats" message.

I couldn't find documentation for the ovirt message, but the list of fields are summarized in this test
https://github.com/oVirt/ovirt-guest-agent/blob/master/tests/message_validator.py#L137
and according to how they are populated in the code, I adapted it to the following GuestMemoryInfo structure fields:

- mem-total: Total usable RAM.
- mem-free: Total of RAM that can be used without having to swap contents to disk.
- mem-cached: In-RAM cache.
- swap-total: Total amount of swap space available.
- swap-free: Amount of swap space that is currently unused.
- swap-in: Number of pages swapped-in per second.
- swap-out: Number of pages swapped-out per second.
- pf-major: Number of major page fault per second.
- pf-minor: Number of minor page fault per second.

Quoted 7 lines
Quoted 1 line

Implemented on Linux and Win32 based on ovirt implementations.

Interesting, currently the libvirt virDomainGetMemoryStats() API is backed by data we obtain from the virtio-balloon driver via QEMU monitor. For Linux at least this provides equiv of your mem-total, mem-free, swap-in, swap-out pf-major and pf-minor. So it lacks mem-cached, swap-total and swap-free I'm unclear in the Windows balloon driver supports this data or not too.

Ah, I should have thought about it! However, many guests don't have a balloon driver. So it could still be useful as a fallback imho

Quoted 10 lines
Quoted 9 lines

Note: the "per second" value differ between Linux and Win32. On Linux, the value is computed based on the average since the last query, however on win32 this seems to be an instantaneous value (they have spikes, but often at 0). I have asked for help on SF:

http://serverfault.com/questions/709943/windows-equivalent-of-linux-vmstat-pswpin-and-pgfault

Related to RFE:
https://bugzilla.redhat.com/show_bug.cgi?id=1101915

Quoted 9 lines

I wonder if we would be better off extending the balloon driver to fill in the gaps we have there vs this guest agent impl. With the balloon agent we set things up so that the guest device periodically pushes the updated stats to QEMU. So when we're querying QEMU for the stats we don't actually block waiting on the guest OS at all, QEMU can answer directly. This feels more appealing that querying the guest agent where we have no reasonable expectation of prompt response. With a large enough number of guests, I think the balloon driver push approach will scale better than a guest agent approach.

I see, I think it really depends on the use case. Clearly for debugging, it doesn't need to be push-based. For load-balancing, I don't know either.

Please Jiri give some details on how these fields are used by ovirt. Thanks