page_cache.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Page cache for QEMU
  3. * The cache is base on a hash of the page address
  4. *
  5. * Copyright 2012 Red Hat, Inc. and/or its affiliates
  6. *
  7. * Authors:
  8. * Orit Wasserman <owasserm@redhat.com>
  9. *
  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.
  12. *
  13. */
  14. #ifndef PAGE_CACHE_H
  15. #define PAGE_CACHE_H
  16. /* Page cache for storing guest pages */
  17. typedef struct PageCache PageCache;
  18. /**
  19. * cache_init: Initialize the page cache
  20. *
  21. *
  22. * Returns new allocated cache or NULL on error
  23. *
  24. * @cache_size: cache size in bytes
  25. * @page_size: cache page size
  26. * @errp: set *errp if the check failed, with reason
  27. */
  28. PageCache *cache_init(uint64_t cache_size, size_t page_size, Error **errp);
  29. /**
  30. * cache_fini: free all cache resources
  31. * @cache pointer to the PageCache struct
  32. */
  33. void cache_fini(PageCache *cache);
  34. /**
  35. * cache_is_cached: Checks to see if the page is cached
  36. *
  37. * Returns %true if page is cached
  38. *
  39. * @cache pointer to the PageCache struct
  40. * @addr: page addr
  41. * @current_age: current bitmap generation
  42. */
  43. bool cache_is_cached(const PageCache *cache, uint64_t addr,
  44. uint64_t current_age);
  45. /**
  46. * get_cached_data: Get the data cached for an addr
  47. *
  48. * Returns pointer to the data cached or NULL if not cached
  49. *
  50. * @cache pointer to the PageCache struct
  51. * @addr: page addr
  52. */
  53. uint8_t *get_cached_data(const PageCache *cache, uint64_t addr);
  54. /**
  55. * cache_insert: insert the page into the cache. the page cache
  56. * will dup the data on insert. the previous value will be overwritten
  57. *
  58. * Returns -1 when the page isn't inserted into cache
  59. *
  60. * @cache pointer to the PageCache struct
  61. * @addr: page address
  62. * @pdata: pointer to the page
  63. * @current_age: current bitmap generation
  64. */
  65. int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
  66. uint64_t current_age);
  67. #endif