All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Steve Kemp <steve@bytemark.co.uk>
Cc: kvm@vger.kernel.org
Subject: Re: How to diagnose memory leak in kvm-qemu-0.14.0?
Date: Fri, 20 May 2011 15:32:34 +0100	[thread overview]
Message-ID: <BANLkTinZoJmP3uNw9L1-Be82Xy-A3gXeMg@mail.gmail.com> (raw)
In-Reply-To: <20110520134731.GK27422@bytemark.co.uk>

On Fri, May 20, 2011 at 2:47 PM, Steve Kemp <steve@bytemark.co.uk> wrote:
> On Fri May 20, 2011 at 14:16:05 +0100, Stefan Hajnoczi wrote:
>
>> >  I've had a quick read of hw/virtio-blk.c but didn't see anything
>> >  glaringly obvious.  I'll need to trace through the code, drink more
>> >  coffee, or get lucky to narrow it down further.
>>
>> Enabling the memory allocation trace events and adding the
>> __builtin_return_address() to them should provide enough information
>> to catch the caller who is leaking memory.
>
>  I'm trying to do that at the moment.  So far the only thing I've
>  done is add a trace on virtio_blk_alloc_request - I'm noticing
>  a leak there pretty easily.
>
>  I see *two* request structures be allocated all the time, one
>  is used and freed, the other is ignored.  That seems pretty
>  conclusively wrong to me, but I'm trying to understand how that
>  happens:
>
>  virtio_blk_alloc_request 0.000 req=0x91e08f0  -> Allocation 1
>  virtio_blk_alloc_request 77.659 req=0x9215650  -> Allocation 2

Are you sure this isn't the temporary one that is allocated but freed
immediately once the virtqueue is empty:

static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
{
    VirtIOBlockReq *req = virtio_blk_alloc_request(s);

    if (req != NULL) {
        if (!virtqueue_pop(s->vq, &req->elem)) {
            qemu_free(req);  <--- virtqueue empty, we're done
            return NULL;
        }
    }

    return req;
}

>  virtio_blk_rw_complete 449.469 req=0x91e08f0 ret=0x0 -> First is used.
>  virtio_blk_req_complete 1.955 req=0x91e08f0 status=0x0 -> First is freed.
>
>  second is never seen again.

Sounds scary 8).

Stefan

  reply	other threads:[~2011-05-20 14:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-18 16:44 How to diagnose memory leak in kvm-qemu-0.14.0? Steve Kemp
2011-05-19  8:40 ` Stefan Hajnoczi
2011-05-19  8:50   ` Stefan Hajnoczi
2011-05-19 11:00   ` Steve Kemp
2011-05-19 11:57   ` Steve Kemp
2011-05-20 11:01     ` Stefan Hajnoczi
2011-05-20 11:47       ` Steve Kemp
2011-05-20 13:16         ` Stefan Hajnoczi
2011-05-20 13:47           ` Steve Kemp
2011-05-20 14:32             ` Stefan Hajnoczi [this message]
2011-05-20 14:52               ` Steve Kemp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTinZoJmP3uNw9L1-Be82Xy-A3gXeMg@mail.gmail.com \
    --to=stefanha@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=steve@bytemark.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.