[libvirt] [PATCH v3 0/2] qemu: expand domain memory statistics

From: Derbyshev Dmitry <dderbyshev@virtuozzo.com> QEMU reports timestamp and available along with other memory statistics. This information was not saved into domain statistics. Changes since v1: * Enum numeration fixed * Macro getting "usage" field fixed Changes since v2: * previous patches were on wrong branch * qemu's stat name was "stat-available-memory" Derbyshev Dmitry (2): qemu: expand domain memory statistics with 'usable' qemu: expand domain memory statistics with 'last-update' timestamp include/libvirt/libvirt-domain.h | 11 ++++++++++- src/libvirt-domain.c | 5 +++++ src/qemu/qemu_monitor_json.c | 22 +++++++++++++--------- tools/virsh-domain-monitor.c | 4 ++++ 4 files changed, 32 insertions(+), 10 deletions(-) -- 1.9.5.msysgit.0

From: Derbyshev Dmitry <dderbyshev@virtuozzo.com> 'memtotal' in virtio drivers and qemu corresponds to 'available' in libvirt. Because of that, 'stat-available-memory' is renamed into 'usable'. Balloon statistics are not reported in hrf, so no modifications are made in qemu_monitor_text.c. Signed-off-by: Derbyshev Dmitry <dderbyshev@virtuozzo.com> --- include/libvirt/libvirt-domain.h | 8 +++++++- src/libvirt-domain.c | 3 +++ src/qemu/qemu_monitor_json.c | 2 ++ tools/virsh-domain-monitor.c | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index cba4fa5..1554198 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -604,10 +604,16 @@ typedef enum { VIR_DOMAIN_MEMORY_STAT_RSS = 7, /* + * How big the balloon can be inflated without pushing the guest system + * to swap, corresponds to 'Available' in /proc/meminfo + */ + VIR_DOMAIN_MEMORY_STAT_USABLE = 8, + + /* * The number of statistics supported by this version of the interface. * To add new statistics, add them to the enum and increase this value. */ - VIR_DOMAIN_MEMORY_STAT_NR = 8, + VIR_DOMAIN_MEMORY_STAT_NR = 9, # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_MEMORY_STAT_LAST = VIR_DOMAIN_MEMORY_STAT_NR diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 73ae369..fabd4a6 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -5986,6 +5986,9 @@ virDomainGetInterfaceParameters(virDomainPtr domain, * The amount of memory which is not being used for any purpose (in kb). * VIR_DOMAIN_MEMORY_STAT_AVAILABLE: * The total amount of memory available to the domain's OS (in kb). + * VIR_DOMAIN_MEMORY_STAT_USABLE: + * How big the balloon can be inflated without pushing the guest system + * to swap, corresponds to 'Available' in /proc/meminfo * VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON: * Current balloon value (in kb). * diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 585b882..f0c001b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1719,6 +1719,8 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon, VIR_DOMAIN_MEMORY_STAT_UNUSED, 1024); GET_BALLOON_STATS("stat-total-memory", VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 1024); + GET_BALLOON_STATS("stat-available-memory", + VIR_DOMAIN_MEMORY_STAT_USABLE, 1024); ret = got; cleanup: virJSONValueFree(cmd); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0a93949..1921ff5 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -369,6 +369,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "unused %llu\n", stats[i].val); if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_AVAILABLE) vshPrint(ctl, "available %llu\n", stats[i].val); + if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_USABLE) + vshPrint(ctl, "usable %llu\n", stats[i].val); if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON) vshPrint(ctl, "actual %llu\n", stats[i].val); if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS) -- 1.9.5.msysgit.0

From: Derbyshev Dmitry <dderbyshev@virtuozzo.com> QEMU reports timestamp along with other memory statistics, but this information is not saved into domain statistics. It could be useful to determine if the data reported is fresh or not. Balloon statistics are not reported in hrf, so no modifications are made in qemu_monitor_text.c. Signed-off-by: Derbyshev Dmitry <dderbyshev@virtuozzo.com> --- include/libvirt/libvirt-domain.h | 5 ++++- src/libvirt-domain.c | 2 ++ src/qemu/qemu_monitor_json.c | 22 ++++++++++++---------- tools/virsh-domain-monitor.c | 2 ++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 1554198..f953897 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -609,11 +609,14 @@ typedef enum { */ VIR_DOMAIN_MEMORY_STAT_USABLE = 8, + /* Timestamp of the last update of statistics */ + VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE = 9, + /* * The number of statistics supported by this version of the interface. * To add new statistics, add them to the enum and increase this value. */ - VIR_DOMAIN_MEMORY_STAT_NR = 9, + VIR_DOMAIN_MEMORY_STAT_NR = 10, # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_MEMORY_STAT_LAST = VIR_DOMAIN_MEMORY_STAT_NR diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index fabd4a6..29e0c72 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -5991,6 +5991,8 @@ virDomainGetInterfaceParameters(virDomainPtr domain, * to swap, corresponds to 'Available' in /proc/meminfo * VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON: * Current balloon value (in kb). + * VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE + * Timestamp of the last statistic * * Returns: The number of stats provided or -1 in case of failure. */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f0c001b..726ce04 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1633,10 +1633,10 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon, * rates and/or whether data has been collected since a previous cycle. * It's currently unused. */ -#define GET_BALLOON_STATS(FIELD, TAG, DIVISOR) \ - if (virJSONValueObjectHasKey(statsdata, FIELD) && \ +#define GET_BALLOON_STATS(OBJECT, FIELD, TAG, DIVISOR) \ + if (virJSONValueObjectHasKey(OBJECT, FIELD) && \ (got < nr_stats)) { \ - if (virJSONValueObjectGetNumberUlong(statsdata, FIELD, &mem) < 0) { \ + if (virJSONValueObjectGetNumberUlong(OBJECT, FIELD, &mem) < 0) { \ VIR_DEBUG("Failed to get '%s' value", FIELD); \ } else { \ /* Not being collected? No point in providing bad data */ \ @@ -1707,20 +1707,22 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon, goto cleanup; } - GET_BALLOON_STATS("stat-swap-in", + GET_BALLOON_STATS(statsdata, "stat-swap-in", VIR_DOMAIN_MEMORY_STAT_SWAP_IN, 1024); - GET_BALLOON_STATS("stat-swap-out", + GET_BALLOON_STATS(statsdata, "stat-swap-out", VIR_DOMAIN_MEMORY_STAT_SWAP_OUT, 1024); - GET_BALLOON_STATS("stat-major-faults", + GET_BALLOON_STATS(statsdata, "stat-major-faults", VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT, 1); - GET_BALLOON_STATS("stat-minor-faults", + GET_BALLOON_STATS(statsdata, "stat-minor-faults", VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT, 1); - GET_BALLOON_STATS("stat-free-memory", + GET_BALLOON_STATS(statsdata, "stat-free-memory", VIR_DOMAIN_MEMORY_STAT_UNUSED, 1024); - GET_BALLOON_STATS("stat-total-memory", + GET_BALLOON_STATS(statsdata, "stat-total-memory", VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 1024); - GET_BALLOON_STATS("stat-available-memory", + GET_BALLOON_STATS(statsdata, "stat-available-memory", VIR_DOMAIN_MEMORY_STAT_USABLE, 1024); + GET_BALLOON_STATS(data, "last-update", + VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE, 1); ret = got; cleanup: virJSONValueFree(cmd); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 1921ff5..b4ccbf6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -375,6 +375,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "actual %llu\n", stats[i].val); if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_RSS) vshPrint(ctl, "rss %llu\n", stats[i].val); + if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE) + vshPrint(ctl, "last_update %llu\n", stats[i].val); } ret = true; -- 1.9.5.msysgit.0

01.06.2016 20:07, Derbyshev Dmitriy пишет:
From: Derbyshev Dmitry <dderbyshev@virtuozzo.com>
QEMU reports timestamp and available along with other memory statistics. This information was not saved into domain statistics.
Changes since v1: * Enum numeration fixed * Macro getting "usage" field fixed Changes since v2: * previous patches were on wrong branch * qemu's stat name was "stat-available-memory"
Derbyshev Dmitry (2): qemu: expand domain memory statistics with 'usable' qemu: expand domain memory statistics with 'last-update' timestamp
include/libvirt/libvirt-domain.h | 11 ++++++++++- src/libvirt-domain.c | 5 +++++ src/qemu/qemu_monitor_json.c | 22 +++++++++++++--------- tools/virsh-domain-monitor.c | 4 ++++ 4 files changed, 32 insertions(+), 10 deletions(-)
Makes sense, looks good to me. ACK the series. Maxim

On Sat, Jun 04, 2016 at 06:41:35PM +0300, Maxim Nestratov wrote:
01.06.2016 20:07, Derbyshev Dmitriy пишет:
From: Derbyshev Dmitry <dderbyshev@virtuozzo.com>
QEMU reports timestamp and available along with other memory statistics. This information was not saved into domain statistics.
Changes since v1: * Enum numeration fixed * Macro getting "usage" field fixed Changes since v2: * previous patches were on wrong branch * qemu's stat name was "stat-available-memory"
Derbyshev Dmitry (2): qemu: expand domain memory statistics with 'usable' qemu: expand domain memory statistics with 'last-update' timestamp
include/libvirt/libvirt-domain.h | 11 ++++++++++- src/libvirt-domain.c | 5 +++++ src/qemu/qemu_monitor_json.c | 22 +++++++++++++--------- tools/virsh-domain-monitor.c | 4 ++++ 4 files changed, 32 insertions(+), 10 deletions(-)
Makes sense, looks good to me. ACK the series.
Pushed now. I've just found out that this wasn't pushed so far. Pavel

26-Jul-16 18:32, Pavel Hrdina пишет:
On Sat, Jun 04, 2016 at 06:41:35PM +0300, Maxim Nestratov wrote:
01.06.2016 20:07, Derbyshev Dmitriy пишет:
From: Derbyshev Dmitry <dderbyshev@virtuozzo.com>
QEMU reports timestamp and available along with other memory statistics. This information was not saved into domain statistics.
Changes since v1: * Enum numeration fixed * Macro getting "usage" field fixed Changes since v2: * previous patches were on wrong branch * qemu's stat name was "stat-available-memory"
Derbyshev Dmitry (2): qemu: expand domain memory statistics with 'usable' qemu: expand domain memory statistics with 'last-update' timestamp
include/libvirt/libvirt-domain.h | 11 ++++++++++- src/libvirt-domain.c | 5 +++++ src/qemu/qemu_monitor_json.c | 22 +++++++++++++--------- tools/virsh-domain-monitor.c | 4 ++++ 4 files changed, 32 insertions(+), 10 deletions(-)
Makes sense, looks good to me. ACK the series. Pushed now. I've just found out that this wasn't pushed so far.
Pavel
Yeah, and in fact the work has been continued in another patchset version though no one replied to this one. It even reached v7 https://www.redhat.com/archives/libvir-list/2016-July/msg00428.html and should be adapted now because these two are pushed. Anyway, thanks for pushing. Maxim

On Tue, Jul 26, 2016 at 09:32:30PM +0300, Maxim Nestratov wrote:
26-Jul-16 18:32, Pavel Hrdina пишет:
On Sat, Jun 04, 2016 at 06:41:35PM +0300, Maxim Nestratov wrote:
01.06.2016 20:07, Derbyshev Dmitriy пишет: Makes sense, looks good to me. ACK the series. Pushed now. I've just found out that this wasn't pushed so far.
Pavel
Yeah, and in fact the work has been continued in another patchset version though no one replied to this one. It even reached v7 https://www.redhat.com/archives/libvir-list/2016-July/msg00428.html and should be adapted now because these two are pushed. Anyway, thanks for pushing.
Maxim
Good to know, I've somehow missed that series. I'll take a look at it. Pavel
participants (3)
-
Derbyshev Dmitriy
-
Maxim Nestratov
-
Pavel Hrdina