Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * zpool memory storage api |
| 4 | * |
| 5 | * Copyright (C) 2014 Dan Streetman |
| 6 | * |
| 7 | * This is a common frontend for memory storage pool implementations. |
| 8 | * Typically, this is used to store compressed memory. |
| 9 | */ |
| 10 | |
| 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 12 | |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/zpool.h> |
| 20 | |
| 21 | struct zpool { |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 22 | struct zpool_driver *driver; |
| 23 | void *pool; |
Krzysztof Kozlowski | 7867277 | 2015-09-08 15:05:03 -0700 | [diff] [blame] | 24 | const struct zpool_ops *ops; |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 25 | bool evictable; |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 26 | bool can_sleep_mapped; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 27 | |
| 28 | struct list_head list; |
| 29 | }; |
| 30 | |
| 31 | static LIST_HEAD(drivers_head); |
| 32 | static DEFINE_SPINLOCK(drivers_lock); |
| 33 | |
| 34 | static LIST_HEAD(pools_head); |
| 35 | static DEFINE_SPINLOCK(pools_lock); |
| 36 | |
| 37 | /** |
| 38 | * zpool_register_driver() - register a zpool implementation. |
| 39 | * @driver: driver to register |
| 40 | */ |
| 41 | void zpool_register_driver(struct zpool_driver *driver) |
| 42 | { |
| 43 | spin_lock(&drivers_lock); |
| 44 | atomic_set(&driver->refcount, 0); |
| 45 | list_add(&driver->list, &drivers_head); |
| 46 | spin_unlock(&drivers_lock); |
| 47 | } |
| 48 | EXPORT_SYMBOL(zpool_register_driver); |
| 49 | |
| 50 | /** |
| 51 | * zpool_unregister_driver() - unregister a zpool implementation. |
| 52 | * @driver: driver to unregister. |
| 53 | * |
| 54 | * Module usage counting is used to prevent using a driver |
| 55 | * while/after unloading, so if this is called from module |
| 56 | * exit function, this should never fail; if called from |
| 57 | * other than the module exit function, and this returns |
| 58 | * failure, the driver is in use and must remain available. |
| 59 | */ |
| 60 | int zpool_unregister_driver(struct zpool_driver *driver) |
| 61 | { |
| 62 | int ret = 0, refcount; |
| 63 | |
| 64 | spin_lock(&drivers_lock); |
| 65 | refcount = atomic_read(&driver->refcount); |
| 66 | WARN_ON(refcount < 0); |
| 67 | if (refcount > 0) |
| 68 | ret = -EBUSY; |
| 69 | else |
| 70 | list_del(&driver->list); |
| 71 | spin_unlock(&drivers_lock); |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | EXPORT_SYMBOL(zpool_unregister_driver); |
| 76 | |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 77 | /* this assumes @type is null-terminated. */ |
Sergey SENOZHATSKY | 6f3526d | 2015-11-06 16:29:21 -0800 | [diff] [blame] | 78 | static struct zpool_driver *zpool_get_driver(const char *type) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 79 | { |
| 80 | struct zpool_driver *driver; |
| 81 | |
| 82 | spin_lock(&drivers_lock); |
| 83 | list_for_each_entry(driver, &drivers_head, list) { |
| 84 | if (!strcmp(driver->type, type)) { |
| 85 | bool got = try_module_get(driver->owner); |
| 86 | |
| 87 | if (got) |
| 88 | atomic_inc(&driver->refcount); |
| 89 | spin_unlock(&drivers_lock); |
| 90 | return got ? driver : NULL; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | spin_unlock(&drivers_lock); |
| 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | static void zpool_put_driver(struct zpool_driver *driver) |
| 99 | { |
| 100 | atomic_dec(&driver->refcount); |
| 101 | module_put(driver->owner); |
| 102 | } |
| 103 | |
| 104 | /** |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 105 | * zpool_has_pool() - Check if the pool driver is available |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 106 | * @type: The type of the zpool to check (e.g. zbud, zsmalloc) |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 107 | * |
| 108 | * This checks if the @type pool driver is available. This will try to load |
| 109 | * the requested module, if needed, but there is no guarantee the module will |
| 110 | * still be loaded and available immediately after calling. If this returns |
| 111 | * true, the caller should assume the pool is available, but must be prepared |
| 112 | * to handle the @zpool_create_pool() returning failure. However if this |
| 113 | * returns false, the caller should assume the requested pool type is not |
| 114 | * available; either the requested pool type module does not exist, or could |
| 115 | * not be loaded, and calling @zpool_create_pool() with the pool type will |
| 116 | * fail. |
| 117 | * |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 118 | * The @type string must be null-terminated. |
| 119 | * |
Dan Streetman | 3f0e131 | 2015-09-09 15:35:16 -0700 | [diff] [blame] | 120 | * Returns: true if @type pool is available, false if not |
| 121 | */ |
| 122 | bool zpool_has_pool(char *type) |
| 123 | { |
| 124 | struct zpool_driver *driver = zpool_get_driver(type); |
| 125 | |
| 126 | if (!driver) { |
| 127 | request_module("zpool-%s", type); |
| 128 | driver = zpool_get_driver(type); |
| 129 | } |
| 130 | |
| 131 | if (!driver) |
| 132 | return false; |
| 133 | |
| 134 | zpool_put_driver(driver); |
| 135 | return true; |
| 136 | } |
| 137 | EXPORT_SYMBOL(zpool_has_pool); |
| 138 | |
| 139 | /** |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 140 | * zpool_create_pool() - Create a new zpool |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 141 | * @type: The type of the zpool to create (e.g. zbud, zsmalloc) |
| 142 | * @name: The name of the zpool (e.g. zram0, zswap) |
| 143 | * @gfp: The GFP flags to use when allocating the pool. |
| 144 | * @ops: The optional ops callback. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 145 | * |
| 146 | * This creates a new zpool of the specified type. The gfp flags will be |
| 147 | * used when allocating memory, if the implementation supports it. If the |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 148 | * ops param is NULL, then the created zpool will not be evictable. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 149 | * |
| 150 | * Implementations must guarantee this to be thread-safe. |
| 151 | * |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 152 | * The @type and @name strings must be null-terminated. |
| 153 | * |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 154 | * Returns: New zpool on success, NULL on failure. |
| 155 | */ |
Sergey SENOZHATSKY | 6f3526d | 2015-11-06 16:29:21 -0800 | [diff] [blame] | 156 | struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp, |
Krzysztof Kozlowski | 7867277 | 2015-09-08 15:05:03 -0700 | [diff] [blame] | 157 | const struct zpool_ops *ops) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 158 | { |
| 159 | struct zpool_driver *driver; |
| 160 | struct zpool *zpool; |
| 161 | |
Dan Streetman | cf41f5f | 2015-06-25 15:00:37 -0700 | [diff] [blame] | 162 | pr_debug("creating pool type %s\n", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 163 | |
| 164 | driver = zpool_get_driver(type); |
| 165 | |
| 166 | if (!driver) { |
Kees Cook | 137f8cf | 2014-08-29 15:18:40 -0700 | [diff] [blame] | 167 | request_module("zpool-%s", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 168 | driver = zpool_get_driver(type); |
| 169 | } |
| 170 | |
| 171 | if (!driver) { |
| 172 | pr_err("no driver for type %s\n", type); |
| 173 | return NULL; |
| 174 | } |
| 175 | |
| 176 | zpool = kmalloc(sizeof(*zpool), gfp); |
| 177 | if (!zpool) { |
| 178 | pr_err("couldn't create zpool - out of memory\n"); |
| 179 | zpool_put_driver(driver); |
| 180 | return NULL; |
| 181 | } |
| 182 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 183 | zpool->driver = driver; |
Dan Streetman | 479305f | 2015-06-25 15:00:40 -0700 | [diff] [blame] | 184 | zpool->pool = driver->create(name, gfp, ops, zpool); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 185 | zpool->ops = ops; |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 186 | zpool->evictable = driver->shrink && ops && ops->evict; |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 187 | zpool->can_sleep_mapped = driver->sleep_mapped; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 188 | |
| 189 | if (!zpool->pool) { |
| 190 | pr_err("couldn't create %s pool\n", type); |
| 191 | zpool_put_driver(driver); |
| 192 | kfree(zpool); |
| 193 | return NULL; |
| 194 | } |
| 195 | |
Dan Streetman | cf41f5f | 2015-06-25 15:00:37 -0700 | [diff] [blame] | 196 | pr_debug("created pool type %s\n", type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 197 | |
| 198 | spin_lock(&pools_lock); |
| 199 | list_add(&zpool->list, &pools_head); |
| 200 | spin_unlock(&pools_lock); |
| 201 | |
| 202 | return zpool; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * zpool_destroy_pool() - Destroy a zpool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 207 | * @zpool: The zpool to destroy. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 208 | * |
| 209 | * Implementations must guarantee this to be thread-safe, |
| 210 | * however only when destroying different pools. The same |
| 211 | * pool should only be destroyed once, and should not be used |
| 212 | * after it is destroyed. |
| 213 | * |
| 214 | * This destroys an existing zpool. The zpool should not be in use. |
| 215 | */ |
| 216 | void zpool_destroy_pool(struct zpool *zpool) |
| 217 | { |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 218 | pr_debug("destroying pool type %s\n", zpool->driver->type); |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 219 | |
| 220 | spin_lock(&pools_lock); |
| 221 | list_del(&zpool->list); |
| 222 | spin_unlock(&pools_lock); |
| 223 | zpool->driver->destroy(zpool->pool); |
| 224 | zpool_put_driver(zpool->driver); |
| 225 | kfree(zpool); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * zpool_get_type() - Get the type of the zpool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 230 | * @zpool: The zpool to check |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 231 | * |
| 232 | * This returns the type of the pool. |
| 233 | * |
| 234 | * Implementations must guarantee this to be thread-safe. |
| 235 | * |
| 236 | * Returns: The type of zpool. |
| 237 | */ |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 238 | const char *zpool_get_type(struct zpool *zpool) |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 239 | { |
Dan Streetman | 69e18f4 | 2015-11-06 16:29:18 -0800 | [diff] [blame] | 240 | return zpool->driver->type; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /** |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 244 | * zpool_malloc_support_movable() - Check if the zpool supports |
| 245 | * allocating movable memory |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 246 | * @zpool: The zpool to check |
| 247 | * |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 248 | * This returns if the zpool supports allocating movable memory. |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 249 | * |
| 250 | * Implementations must guarantee this to be thread-safe. |
| 251 | * |
Randy Dunlap | b6aa2c8 | 2020-08-11 18:33:28 -0700 | [diff] [blame] | 252 | * Returns: true if the zpool supports allocating movable memory, false if not |
Hui Zhu | c165f25 | 2019-09-23 15:39:37 -0700 | [diff] [blame] | 253 | */ |
| 254 | bool zpool_malloc_support_movable(struct zpool *zpool) |
| 255 | { |
| 256 | return zpool->driver->malloc_support_movable; |
| 257 | } |
| 258 | |
| 259 | /** |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 260 | * zpool_malloc() - Allocate memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 261 | * @zpool: The zpool to allocate from. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 262 | * @size: The amount of memory to allocate. |
| 263 | * @gfp: The GFP flags to use when allocating memory. |
| 264 | * @handle: Pointer to the handle to set |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 265 | * |
| 266 | * This allocates the requested amount of memory from the pool. |
| 267 | * The gfp flags will be used when allocating memory, if the |
| 268 | * implementation supports it. The provided @handle will be |
| 269 | * set to the allocated object handle. |
| 270 | * |
| 271 | * Implementations must guarantee this to be thread-safe. |
| 272 | * |
| 273 | * Returns: 0 on success, negative value on error. |
| 274 | */ |
| 275 | int zpool_malloc(struct zpool *zpool, size_t size, gfp_t gfp, |
| 276 | unsigned long *handle) |
| 277 | { |
| 278 | return zpool->driver->malloc(zpool->pool, size, gfp, handle); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * zpool_free() - Free previously allocated memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 283 | * @zpool: The zpool that allocated the memory. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 284 | * @handle: The handle to the memory to free. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 285 | * |
| 286 | * This frees previously allocated memory. This does not guarantee |
| 287 | * that the pool will actually free memory, only that the memory |
| 288 | * in the pool will become available for use by the pool. |
| 289 | * |
| 290 | * Implementations must guarantee this to be thread-safe, |
| 291 | * however only when freeing different handles. The same |
| 292 | * handle should only be freed once, and should not be used |
| 293 | * after freeing. |
| 294 | */ |
| 295 | void zpool_free(struct zpool *zpool, unsigned long handle) |
| 296 | { |
| 297 | zpool->driver->free(zpool->pool, handle); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * zpool_shrink() - Shrink the pool size |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 302 | * @zpool: The zpool to shrink. |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 303 | * @pages: The number of pages to shrink the pool. |
| 304 | * @reclaimed: The number of pages successfully evicted. |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 305 | * |
| 306 | * This attempts to shrink the actual memory size of the pool |
| 307 | * by evicting currently used handle(s). If the pool was |
| 308 | * created with no zpool_ops, or the evict call fails for any |
| 309 | * of the handles, this will fail. If non-NULL, the @reclaimed |
| 310 | * parameter will be set to the number of pages reclaimed, |
| 311 | * which may be more than the number of pages requested. |
| 312 | * |
| 313 | * Implementations must guarantee this to be thread-safe. |
| 314 | * |
| 315 | * Returns: 0 on success, negative value on error/failure. |
| 316 | */ |
| 317 | int zpool_shrink(struct zpool *zpool, unsigned int pages, |
| 318 | unsigned int *reclaimed) |
| 319 | { |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 320 | return zpool->driver->shrink ? |
| 321 | zpool->driver->shrink(zpool->pool, pages, reclaimed) : -EINVAL; |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
| 325 | * zpool_map_handle() - Map a previously allocated handle into memory |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 326 | * @zpool: The zpool that the handle was allocated from |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 327 | * @handle: The handle to map |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 328 | * @mapmode: How the memory should be mapped |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 329 | * |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 330 | * This maps a previously allocated handle into memory. The @mapmode |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 331 | * param indicates to the implementation how the memory will be |
| 332 | * used, i.e. read-only, write-only, read-write. If the |
| 333 | * implementation does not support it, the memory will be treated |
| 334 | * as read-write. |
| 335 | * |
| 336 | * This may hold locks, disable interrupts, and/or preemption, |
| 337 | * and the zpool_unmap_handle() must be called to undo those |
| 338 | * actions. The code that uses the mapped handle should complete |
Ingo Molnar | f0953a1 | 2021-05-06 18:06:47 -0700 | [diff] [blame] | 339 | * its operations on the mapped handle memory quickly and unmap |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 340 | * as soon as possible. As the implementation may use per-cpu |
| 341 | * data, multiple handles should not be mapped concurrently on |
| 342 | * any cpu. |
| 343 | * |
| 344 | * Returns: A pointer to the handle's mapped memory area. |
| 345 | */ |
| 346 | void *zpool_map_handle(struct zpool *zpool, unsigned long handle, |
| 347 | enum zpool_mapmode mapmode) |
| 348 | { |
| 349 | return zpool->driver->map(zpool->pool, handle, mapmode); |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * zpool_unmap_handle() - Unmap a previously mapped handle |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 354 | * @zpool: The zpool that the handle was allocated from |
Mike Rapoport | b7701a5 | 2018-02-06 15:42:13 -0800 | [diff] [blame] | 355 | * @handle: The handle to unmap |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 356 | * |
| 357 | * This unmaps a previously mapped handle. Any locks or other |
| 358 | * actions that the implementation took in zpool_map_handle() |
| 359 | * will be undone here. The memory area returned from |
| 360 | * zpool_map_handle() should no longer be used after this. |
| 361 | */ |
| 362 | void zpool_unmap_handle(struct zpool *zpool, unsigned long handle) |
| 363 | { |
| 364 | zpool->driver->unmap(zpool->pool, handle); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * zpool_get_total_size() - The total size of the pool |
Mike Rapoport | f144c39 | 2018-02-06 15:42:16 -0800 | [diff] [blame] | 369 | * @zpool: The zpool to check |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 370 | * |
| 371 | * This returns the total size in bytes of the pool. |
| 372 | * |
| 373 | * Returns: Total size of the zpool in bytes. |
| 374 | */ |
| 375 | u64 zpool_get_total_size(struct zpool *zpool) |
| 376 | { |
| 377 | return zpool->driver->total_size(zpool->pool); |
| 378 | } |
| 379 | |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 380 | /** |
| 381 | * zpool_evictable() - Test if zpool is potentially evictable |
Mike Rapoport | 14fec9e | 2018-02-21 14:45:46 -0800 | [diff] [blame] | 382 | * @zpool: The zpool to test |
Yu Zhao | 9c3760e | 2018-01-31 16:19:59 -0800 | [diff] [blame] | 383 | * |
| 384 | * Zpool is only potentially evictable when it's created with struct |
| 385 | * zpool_ops.evict and its driver implements struct zpool_driver.shrink. |
| 386 | * |
| 387 | * However, it doesn't necessarily mean driver will use zpool_ops.evict |
| 388 | * in its implementation of zpool_driver.shrink. It could do internal |
| 389 | * defragmentation instead. |
| 390 | * |
| 391 | * Returns: true if potentially evictable; false otherwise. |
| 392 | */ |
| 393 | bool zpool_evictable(struct zpool *zpool) |
| 394 | { |
| 395 | return zpool->evictable; |
| 396 | } |
| 397 | |
Tian Tao | fc6697a | 2021-02-25 17:18:17 -0800 | [diff] [blame] | 398 | /** |
| 399 | * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped. |
| 400 | * @zpool: The zpool to test |
| 401 | * |
| 402 | * Returns: true if zpool can sleep; false otherwise. |
| 403 | */ |
| 404 | bool zpool_can_sleep_mapped(struct zpool *zpool) |
| 405 | { |
| 406 | return zpool->can_sleep_mapped; |
| 407 | } |
| 408 | |
Dan Streetman | af8d417 | 2014-08-06 16:08:36 -0700 | [diff] [blame] | 409 | MODULE_LICENSE("GPL"); |
| 410 | MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); |
| 411 | MODULE_DESCRIPTION("Common API for compressed memory storage"); |