qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 4/4] page_cache: dup memory on insert


From: Orit Wasserman
Subject: [Qemu-devel] [PATCH 4/4] page_cache: dup memory on insert
Date: Mon, 25 Feb 2013 15:19:42 +0200

From: Peter Lieven <address@hidden>

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 <address@hidden>

Signed-off-by: Peter Lieven <address@hidden>
Signed-off-by: Orit Wasserman <address@hidden>
---
 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;
 }
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]