zpool.h 3.1 KB

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