qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Orit Wasserman <owasserm@redhat.com>
To: "Gonglei (Arei)" <arei.gonglei@huawei.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"qemu-stable@nongnu.org" <qemu-stable@nongnu.org>,
	Peter Maydell <peter.maydell@linaro.org>,
	"anthony@codemonkey.ws" <anthony@codemonkey.ws>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Cc: "chenliang (T)" <chenliang88@huawei.com>,
	Luonengjun <luonengjun@huawei.com>,
	"Huangweidong (Hardware)" <huangweidong@huawei.com>
Subject: Re: [Qemu-devel] [PATCH v2] migration:fix free XBZRLE decoded_buf wrong
Date: Tue, 21 Jan 2014 14:24:08 +0200	[thread overview]
Message-ID: <52DE66E8.4040003@redhat.com> (raw)
In-Reply-To: <33183CC9F5247A488A2544077AF19020815BB9E1@SZXEMA503-MBS.china.huawei.com>

On 01/21/2014 02:11 PM, Gonglei (Arei) wrote:
> Hi,
>
> This is an update of my patch.
> Modifications in v2:
> * Removing excess check for g_free
> * The structure of XBZRLE is divided into two halves.One is for
> * src side, another is for dest side.
>

What is the benefit of splitting the structure?
decode_buf is only allocated (and freed) in the destination any way.

Orit

> Signed-off-by: chenliang <chenliang88@huawei.com>
> ---
>   arch_init.c                   |   23 ++++++++++++++---------
>   include/migration/migration.h |    1 +
>   migration.c                   |    1 +
>   3 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index 77912e7..9a28a43 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -164,17 +164,15 @@ static struct {
>       uint8_t *encoded_buf;
>       /* buffer for storing page content */
>       uint8_t *current_buf;
> -    /* buffer used for XBZRLE decoding */
> -    uint8_t *decoded_buf;
>       /* Cache for XBZRLE */
>       PageCache *cache;
>   } XBZRLE = {
>       .encoded_buf = NULL,
>       .current_buf = NULL,
> -    .decoded_buf = NULL,
>       .cache = NULL,
>   };
> -
> +/* buffer used for XBZRLE decoding */
> +static uint8_t *xbzrle_decoded_buf = NULL;
>
>   int64_t xbzrle_cache_resize(int64_t new_size)
>   {
> @@ -602,6 +600,12 @@ uint64_t ram_bytes_total(void)
>       return total;
>   }
>
> +void free_xbzrle_decoded_buf(void)
> +{
> +    g_free(xbzrle_decoded_buf);
> +    xbzrle_decoded_buf = NULL;
> +}
> +
>   static void migration_end(void)
>   {
>       if (migration_bitmap) {
> @@ -615,8 +619,9 @@ static void migration_end(void)
>           g_free(XBZRLE.cache);
>           g_free(XBZRLE.encoded_buf);
>           g_free(XBZRLE.current_buf);
> -        g_free(XBZRLE.decoded_buf);
>           XBZRLE.cache = NULL;
> +        XBZRLE.encoded_buf = NULL;
> +        XBZRLE.current_buf = NULL;
>       }
>   }
>
> @@ -807,8 +812,8 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
>       unsigned int xh_len;
>       int xh_flags;
>
> -    if (!XBZRLE.decoded_buf) {
> -        XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
> +    if (!xbzrle_decoded_buf) {
> +        xbzrle_decoded_buf = g_malloc(TARGET_PAGE_SIZE);
>       }
>
>       /* extract RLE header */
> @@ -825,10 +830,10 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
>           return -1;
>       }
>       /* load data and decode */
> -    qemu_get_buffer(f, XBZRLE.decoded_buf, xh_len);
> +    qemu_get_buffer(f, xbzrle_decoded_buf, xh_len);
>
>       /* decode RLE */
> -    ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host,
> +    ret = xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host,
>                                  TARGET_PAGE_SIZE);
>       if (ret == -1) {
>           fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index bfa3951..3e1e6c7 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -109,6 +109,7 @@ MigrationState *migrate_get_current(void);
>   uint64_t ram_bytes_remaining(void);
>   uint64_t ram_bytes_transferred(void);
>   uint64_t ram_bytes_total(void);
> +void free_xbzrle_decoded_buf(void);
>
>   void acct_update_position(QEMUFile *f, size_t size, bool zero);
>
> diff --git a/migration.c b/migration.c
> index 7235c23..3d46804 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -105,6 +105,7 @@ static void process_incoming_migration_co(void *opaque)
>
>       ret = qemu_loadvm_state(f);
>       qemu_fclose(f);
> +    free_xbzrle_decoded_buf();
>       if (ret < 0) {
>           fprintf(stderr, "load of migration failed\n");
>           exit(EXIT_FAILURE);
>

  reply	other threads:[~2014-01-21 12:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 12:11 [Qemu-devel] [PATCH v2] migration:fix free XBZRLE decoded_buf wrong Gonglei (Arei)
2014-01-21 12:24 ` Orit Wasserman [this message]
2014-01-21 12:58   ` Gonglei (Arei)
2014-01-22  5:51     ` Orit Wasserman
2014-01-21 13:04   ` Peter Maydell
2014-01-21 13:46 ` Eric Blake
2014-01-23  2:51   ` Gonglei (Arei)

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=52DE66E8.4040003@redhat.com \
    --to=owasserm@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=arei.gonglei@huawei.com \
    --cc=chenliang88@huawei.com \
    --cc=huangweidong@huawei.com \
    --cc=luonengjun@huawei.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).