From patchwork Mon Feb 25 13:19:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 222922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 833742C029C for ; Tue, 26 Feb 2013 01:29:35 +1100 (EST) Received: from localhost ([::1]:47919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9z3d-0006rJ-Mg for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 09:29:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9z3U-0006pj-VD for qemu-devel@nongnu.org; Mon, 25 Feb 2013 09:29:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9z3P-00085e-26 for qemu-devel@nongnu.org; Mon, 25 Feb 2013 09:29:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9xxC-0001xa-Cm for qemu-devel@nongnu.org; Mon, 25 Feb 2013 08:18:50 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1PDIitf018098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Feb 2013 08:18:45 -0500 Received: from dhcp-1-120.tlv.redhat.com (vpn-200-236.tlv.redhat.com [10.35.200.236]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1PDIXfS004585; Mon, 25 Feb 2013 08:18:43 -0500 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Mon, 25 Feb 2013 15:19:42 +0200 Message-Id: <1361798382-6515-5-git-send-email-owasserm@redhat.com> In-Reply-To: <1361798382-6515-1-git-send-email-owasserm@redhat.com> References: <1361798382-6515-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, pl@kamp.de, Peter Lieven , Orit Wasserman Subject: [Qemu-devel] [PATCH 4/4] page_cache: dup memory on insert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Lieven The page cache frees all data on finish, on resize and if there is collision on insert. So it should be the caches responsibility to dup the data that is stored in the cache. From: Peter Lieven Signed-off-by: Peter Lieven Signed-off-by: Orit Wasserman --- arch_init.c | 3 +-- include/migration/page_cache.h | 3 ++- page_cache.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch_init.c b/arch_init.c index 8da868b..97bcc29 100644 --- a/arch_init.c +++ b/arch_init.c @@ -293,8 +293,7 @@ static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, if (!cache_is_cached(XBZRLE.cache, current_addr)) { if (!last_stage) { - cache_insert(XBZRLE.cache, current_addr, - g_memdup(current_data, TARGET_PAGE_SIZE)); + cache_insert(XBZRLE.cache, current_addr, current_data); } acct_info.xbzrle_cache_miss++; return -1; diff --git a/include/migration/page_cache.h b/include/migration/page_cache.h index 3839ac7..87894fe 100644 --- a/include/migration/page_cache.h +++ b/include/migration/page_cache.h @@ -57,7 +57,8 @@ bool cache_is_cached(const PageCache *cache, uint64_t addr); uint8_t *get_cached_data(const PageCache *cache, uint64_t addr); /** - * cache_insert: insert the page into the cache. the previous value will be overwritten + * cache_insert: insert the page into the cache. the page cache + * will dup the data on insert. the previous value will be overwritten * * @cache pointer to the PageCache struct * @addr: page address diff --git a/page_cache.c b/page_cache.c index 07da547..daac506 100644 --- a/page_cache.c +++ b/page_cache.c @@ -159,7 +159,7 @@ void cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata) cache->num_items++; } - it->it_data = pdata; + it->it_data = g_memdup(pdata, cache->page_size); it->it_age = ++cache->max_item_age; it->it_addr = addr; }