From patchwork Mon Feb 25 11:52:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 222912 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 5EBA42C029E for ; Mon, 25 Feb 2013 22:53:23 +1100 (EST) Received: from localhost ([::1]:49874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9wcT-0002KN-GD for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 06:53:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9wcG-0002FE-EU for qemu-devel@nongnu.org; Mon, 25 Feb 2013 06:53:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9wc3-0008Oh-N8 for qemu-devel@nongnu.org; Mon, 25 Feb 2013 06:53:08 -0500 Received: from ssl.dlhnet.de ([91.198.192.8]:52685 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9wc3-0008OS-FJ for qemu-devel@nongnu.org; Mon, 25 Feb 2013 06:52:55 -0500 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id A3DF114DA8C; Mon, 25 Feb 2013 12:52:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7TuDSCcx647q; Mon, 25 Feb 2013 12:52:54 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id 37E2714D7F1; Mon, 25 Feb 2013 12:52:54 +0100 (CET) Message-ID: <512B5096.7030901@dlhnet.de> Date: Mon, 25 Feb 2013 12:52:54 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: Orit Wasserman Subject: [Qemu-devel] [PATCH] 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 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. Signed-off-by: Peter Lieven --- 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 a6c3a15..e670d91 100644 --- a/page_cache.c +++ b/page_cache.c @@ -158,7 +158,7 @@ void cache_insert(PageCache *cache, uint64_t addr, uint8_t *pdata) g_free(it->it_data); } - it->it_data = pdata; + it->it_data = g_memdup(pdata, cache->page_size); it->it_age = ++cache->max_item_age; it->it_addr = addr; }