1 /* SPDX-License-Identifier: GPL-2.0 */
3 * zpool memory storage api
5 * Copyright (C) 2014 Dan Streetman
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.
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.
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) */
33 ZPOOL_MM_DEFAULT
= ZPOOL_MM_RW
36 bool zpool_has_pool(char *type
);
38 struct zpool
*zpool_create_pool(const char *type
, const char *name
, gfp_t gfp
);
40 const char *zpool_get_type(struct zpool
*pool
);
42 void zpool_destroy_pool(struct zpool
*pool
);
44 bool zpool_malloc_support_movable(struct zpool
*pool
);
46 int zpool_malloc(struct zpool
*pool
, size_t size
, gfp_t gfp
,
47 unsigned long *handle
);
49 void zpool_free(struct zpool
*pool
, unsigned long handle
);
51 void *zpool_map_handle(struct zpool
*pool
, unsigned long handle
,
52 enum zpool_mapmode mm
);
54 void zpool_unmap_handle(struct zpool
*pool
, unsigned long handle
);
56 u64
zpool_get_total_pages(struct zpool
*pool
);
60 * struct zpool_driver - driver implementation for zpool
61 * @type: name of the driver.
62 * @list: entry in the list of zpool drivers.
63 * @create: create a new pool.
64 * @destroy: destroy a pool.
65 * @malloc: allocate mem from a pool.
66 * @free: free mem from a pool.
67 * @sleep_mapped: whether zpool driver can sleep during map.
69 * @unmap: unmap a handle.
70 * @total_size: get total size of a pool.
72 * This is created by a zpool implementation and registered
79 struct list_head list
;
81 void *(*create
)(const char *name
, gfp_t gfp
);
82 void (*destroy
)(void *pool
);
84 bool malloc_support_movable
;
85 int (*malloc
)(void *pool
, size_t size
, gfp_t gfp
,
86 unsigned long *handle
);
87 void (*free
)(void *pool
, unsigned long handle
);
90 void *(*map
)(void *pool
, unsigned long handle
,
91 enum zpool_mapmode mm
);
92 void (*unmap
)(void *pool
, unsigned long handle
);
94 u64 (*total_pages
)(void *pool
);
97 void zpool_register_driver(struct zpool_driver
*driver
);
99 int zpool_unregister_driver(struct zpool_driver
*driver
);
101 bool zpool_can_sleep_mapped(struct zpool
*pool
);