3 * The cache is base on a hash of the page address
5 * Copyright 2012 Red Hat, Inc. and/or its affiliates
8 * Orit Wasserman <owasserm@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
18 /* Page cache for storing guest pages */
19 typedef struct PageCache PageCache
;
22 * cache_init: Initialize the page cache
25 * Returns new allocated cache or NULL on error
27 * @cache_size: cache size in bytes
28 * @page_size: cache page size
29 * @errp: set *errp if the check failed, with reason
31 PageCache
*cache_init(int64_t cache_size
, size_t page_size
, Error
**errp
);
33 * cache_fini: free all cache resources
34 * @cache pointer to the PageCache struct
36 void cache_fini(PageCache
*cache
);
39 * cache_is_cached: Checks to see if the page is cached
41 * Returns %true if page is cached
43 * @cache pointer to the PageCache struct
45 * @current_age: current bitmap generation
47 bool cache_is_cached(const PageCache
*cache
, uint64_t addr
,
48 uint64_t current_age
);
51 * get_cached_data: Get the data cached for an addr
53 * Returns pointer to the data cached or NULL if not cached
55 * @cache pointer to the PageCache struct
58 uint8_t *get_cached_data(const PageCache
*cache
, uint64_t addr
);
61 * cache_insert: insert the page into the cache. the page cache
62 * will dup the data on insert. the previous value will be overwritten
64 * Returns -1 when the page isn't inserted into cache
66 * @cache pointer to the PageCache struct
68 * @pdata: pointer to the page
69 * @current_age: current bitmap generation
71 int cache_insert(PageCache
*cache
, uint64_t addr
, const uint8_t *pdata
,
72 uint64_t current_age
);