]> git.proxmox.com Git - qemu.git/commitdiff
page_cache: dup memory on insert
authorPeter Lieven <pl@dlhnet.de>
Mon, 25 Feb 2013 17:12:04 +0000 (19:12 +0200)
committerJuan Quintela <quintela@redhat.com>
Mon, 11 Mar 2013 12:32:03 +0000 (13:32 +0100)
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 <pl@kamp.de>
Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Juan Quintela <quintela@redhat.com>
arch_init.c
include/migration/page_cache.h
page_cache.c

index 6089c5338660df0ee1a9316d2e7a9472155034dc..98e2bc6f55938e64095f247833e814376c471871 100644 (file)
@@ -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;
index 3839ac7726f0ff930c389169e7db37e6dc2693cc..87894fea9f11fe73337b9cec7c44995be011fabb 100644 (file)
@@ -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
index 809dadc7ebf4f6c65d925975569168d84c9a0cc4..938a79c9ea7999b4a46a639c35ff27bc639e6892 100644 (file)
@@ -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;
 }