On Wed, Nov 18, 2015 at 01:04:32PM +0000, 张强 wrote: > Hi all, > I’m studying the source code, and I saw this in domain.py around line 164: > … > curmem = stats['rss'] > totalmem = stats['actual'] > except libvirt.libvirtError, err: > logging.error("Error reading mem stats: %s", err) > > pcentCurrMem = curmem * 100.0 / totalmem > pcentCurrMem = max(0.0, min(pcentCurrMem, 100.0)) > … > > But using this algorithm, I’m always getting results that are greater than 100: > >>> dom.memoryStats() > {'actual': 16777216L, 'rss': 17062900L} > > 17062900 * 100 / 16777216 = 101.7028… > > Is this normal? The VIR_DOMAIN_MEMORY_STAT_RSS statistic returned for qemu/KVM guests is the resident set size (RSS) of the qemu process. Of course that includes all the overhead of qemu, such as host-side structures used when emulating devices. Plus the guest RAM, which is just a regular malloc-style allocation inside qemu and so also contributes to the RSS. The 'actual' field seems to come from the libvirt VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON statistic which is found by sending the query-balloon monitor command to the guest. The returned value is the guest's get_current_ram_size() (or less if the balloon is "inflated", but for the majority of guests the balloon is never used). Given all that, it seems reasonable that rss > actual, and so you'd get a number > 100%. Sometimes. It also seems to me that if the guest RAM had been allocated but not accessed, you might see rss < actual. rss / actual seems like a fairly meaningless number from a virt-manager point of view. Rich. References: libvirt.git/src/qemu/qemu_driver.c qemuGetProcessInfo & qemuDomainMemoryStats. libvirt.git/src/qemu/qemu_monitor_json.c qemuMonitorJSONGetBalloonInfo. qemu.git/hw/virtio/virtio-balloon.c virtio_balloon_stat -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list