zpool.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * zpool memory storage api
  3. *
  4. * Copyright (C) 2014 Dan Streetman
  5. *
  6. * This is a common frontend for the zbud and zsmalloc memory
  7. * storage pool implementations. Typically, this is used to
  8. * store compressed memory.
  9. */
  10. #ifndef _ZPOOL_H_
  11. #define _ZPOOL_H_
  12. struct zpool;
  13. struct zpool_ops {
  14. int (*evict)(struct zpool *pool, unsigned long handle);
  15. };
  16. /*
  17. * Control how a handle is mapped. It will be ignored if the
  18. * implementation does not support it. Its use is optional.
  19. * Note that this does not refer to memory protection, it
  20. * refers to how the memory will be copied in/out if copying
  21. * is necessary during mapping; read-write is the safest as
  22. * it copies the existing memory in on map, and copies the
  23. * changed memory back out on unmap. Write-only does not copy
  24. * in the memory and should only be used for initialization.
  25. * If in doubt, use ZPOOL_MM_DEFAULT which is read-write.
  26. */
  27. enum zpool_mapmode {
  28. ZPOOL_MM_RW, /* normal read-write mapping */
  29. ZPOOL_MM_RO, /* read-only (no copy-out at unmap time) */
  30. ZPOOL_MM_WO, /* write-only (no copy-in at map time) */
  31. ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
  32. };
  33. bool zpool_has_pool(char *type);
  34. struct zpool *zpool_create_pool(const char *type, const char *name,
  35. gfp_t gfp, const struct zpool_ops *ops);
  36. const char *zpool_get_type(struct zpool *pool);
  37. void zpool_destroy_pool(struct zpool *pool);
  38. int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
  39. unsigned long *handle);
  40. void zpool_free(struct zpool *pool, unsigned long handle);
  41. int zpool_shrink(struct zpool *pool, unsigned int pages,
  42. unsigned int *reclaimed);
  43. void *zpool_map_handle(struct zpool *pool, unsigned long handle,
  44. enum zpool_mapmode mm);
  45. void zpool_unmap_handle(struct zpool *pool, unsigned long handle);
  46. u64 zpool_get_total_size(struct zpool *pool);
  47. /**
  48. * struct zpool_driver - driver implementation for zpool
  49. * @type: name of the driver.
  50. * @list: entry in the list of zpool drivers.
  51. * @create: create a new pool.
  52. * @destroy: destroy a pool.
  53. * @malloc: allocate mem from a pool.
  54. * @free: free mem from a pool.
  55. * @shrink: shrink the pool.
  56. * @map: map a handle.
  57. * @unmap: unmap a handle.
  58. * @total_size: get total size of a pool.
  59. *
  60. * This is created by a zpool implementation and registered
  61. * with zpool.
  62. */
  63. struct zpool_driver {
  64. char *type;
  65. struct module *owner;
  66. atomic_t refcount;
  67. struct list_head list;
  68. void *(*create)(const char *name,
  69. gfp_t gfp,
  70. const struct zpool_ops *ops,
  71. struct zpool *zpool);
  72. void (*destroy)(void *pool);
  73. int (*malloc)(void *pool, size_t size, gfp_t gfp,
  74. unsigned long *handle);
  75. void (*free)(void *pool, unsigned long handle);
  76. int (*shrink)(void *pool, unsigned int pages,
  77. unsigned int *reclaimed);
  78. void *(*map)(void *pool, unsigned long handle,
  79. enum zpool_mapmode mm);
  80. void (*unmap)(void *pool, unsigned long handle);
  81. u64 (*total_size)(void *pool);
  82. };
  83. void zpool_register_driver(struct zpool_driver *driver);
  84. int zpool_unregister_driver(struct zpool_driver *driver);
  85. #endif