Skip to content

Commit

Permalink
page_cache: dup memory on insert
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Orit Wasserman <[email protected]>

Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
  • Loading branch information
plieven authored and Juan Quintela committed Mar 11, 2013
1 parent 32a1c08 commit ee0b44a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions arch_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion include/migration/page_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion page_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ee0b44a

Please sign in to comment.