Re: How to diagnose memory leak in kvm-qemu-0.14.0?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2011 at 5:44 PM, Steve Kemp <steve@xxxxxxxxxxxxxx> wrote:
>
>  I'm running the most recent release of KVM, version 0.14.0
>  on a host kernel 2.6.32.15, and seem to be able to trigger
>  a leak of memory pretty easily.
>
>  Inside a guest the following one-liner will cause the KVM
>  process on the host to gradually increase its memory
>  consumption:
>
>    while true; do
>      wget http://mirror.bytemark.co.uk/misc/test-files/500M; cp 500M new; rm 500M new; sleep 10 ;
>    done

You are exercising both networking and storage.  Have you cut the test
down to just wget vs cp/rm?  Also why the sleep 10?

If you are building qemu-kvm from source you might like to enable
tracing to track memory allocations in qemu-kvm.  For full information
see qemu-kvm/docs/tracing.txt.  There are several trace events of
interest:
$ cd qemu-kvm
$ $EDITOR trace-events
# qemu-malloc.c
disable qemu_malloc(size_t size, void *ptr) "size %zu ptr %p"
disable qemu_realloc(void *ptr, size_t size, void *newptr) "ptr %p
size %zu newptr %p"
disable qemu_free(void *ptr) "ptr %p"

# osdep.c
disable qemu_memalign(size_t alignment, size_t size, void *ptr)
"alignment %zu size %zu ptr %p"
disable qemu_vmalloc(size_t size, void *ptr) "size %zu ptr %p"
disable qemu_vfree(void *ptr) "ptr %p"
^--- remove the "disable" property from these memory allocation events
$ ./configure --enable-trace-backend=simple [...]
$ make
$ # run the VM, reproduce the leak, shut the VM down
$ scripts/simpletrace.py trace-events trace-<pid>  # where <pid> was
the process ID

It is fairly easy to write a script that correlates mallocs and frees,
printing out memory allocations that were never freed at the end.
There is a Python API for processing trace files, here is an
explanation of how ot use it:
http://blog.vmsplice.net/2011/03/how-to-write-trace-analysis-scripts-for.html

If you have SystemTap installed you may wish to use the "dtrace"
backend instead of "simple".  You can then use SystemTap scripts on
the probes.  SystemTap is more powerful, it should allow you to
extract call stacks when probes are fired but I'm not experienced with
it.

Feel free to contact me on #qemu (oftc) or #kvm (freenode) IRC if you
want some pointers, my nick is stefanha.

Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux