Lines Matching +full:memory +full:- +full:mapped
1 // SPDX-License-Identifier: GPL-2.0-only
3 * zpool memory storage api
7 * This is a common frontend for memory storage pool implementations.
8 * Typically, this is used to store compressed memory.
38 * zpool_register_driver() - register a zpool implementation.
44 atomic_set(&driver->refcount, 0); in zpool_register_driver()
45 list_add(&driver->list, &drivers_head); in zpool_register_driver()
51 * zpool_unregister_driver() - unregister a zpool implementation.
65 refcount = atomic_read(&driver->refcount); in zpool_unregister_driver()
68 ret = -EBUSY; in zpool_unregister_driver()
70 list_del(&driver->list); in zpool_unregister_driver()
77 /* this assumes @type is null-terminated. */
84 if (!strcmp(driver->type, type)) { in zpool_get_driver()
85 bool got = try_module_get(driver->owner); in zpool_get_driver()
88 atomic_inc(&driver->refcount); in zpool_get_driver()
100 atomic_dec(&driver->refcount); in zpool_put_driver()
101 module_put(driver->owner); in zpool_put_driver()
105 * zpool_has_pool() - Check if the pool driver is available
118 * The @type string must be null-terminated.
127 request_module("zpool-%s", type); in zpool_has_pool()
140 * zpool_create_pool() - Create a new zpool
147 * used when allocating memory, if the implementation supports it. If the
150 * Implementations must guarantee this to be thread-safe.
152 * The @type and @name strings must be null-terminated.
167 request_module("zpool-%s", type); in zpool_create_pool()
178 pr_err("couldn't create zpool - out of memory\n"); in zpool_create_pool()
183 zpool->driver = driver; in zpool_create_pool()
184 zpool->pool = driver->create(name, gfp, ops, zpool); in zpool_create_pool()
185 zpool->ops = ops; in zpool_create_pool()
186 zpool->evictable = driver->shrink && ops && ops->evict; in zpool_create_pool()
187 zpool->can_sleep_mapped = driver->sleep_mapped; in zpool_create_pool()
189 if (!zpool->pool) { in zpool_create_pool()
199 list_add(&zpool->list, &pools_head); in zpool_create_pool()
206 * zpool_destroy_pool() - Destroy a zpool
209 * Implementations must guarantee this to be thread-safe,
218 pr_debug("destroying pool type %s\n", zpool->driver->type); in zpool_destroy_pool()
221 list_del(&zpool->list); in zpool_destroy_pool()
223 zpool->driver->destroy(zpool->pool); in zpool_destroy_pool()
224 zpool_put_driver(zpool->driver); in zpool_destroy_pool()
229 * zpool_get_type() - Get the type of the zpool
234 * Implementations must guarantee this to be thread-safe.
240 return zpool->driver->type; in zpool_get_type()
244 * zpool_malloc_support_movable() - Check if the zpool supports
245 * allocating movable memory
248 * This returns if the zpool supports allocating movable memory.
250 * Implementations must guarantee this to be thread-safe.
252 * Returns: true if the zpool supports allocating movable memory, false if not
256 return zpool->driver->malloc_support_movable; in zpool_malloc_support_movable()
260 * zpool_malloc() - Allocate memory
262 * @size: The amount of memory to allocate.
263 * @gfp: The GFP flags to use when allocating memory.
266 * This allocates the requested amount of memory from the pool.
267 * The gfp flags will be used when allocating memory, if the
271 * Implementations must guarantee this to be thread-safe.
278 return zpool->driver->malloc(zpool->pool, size, gfp, handle); in zpool_malloc()
282 * zpool_free() - Free previously allocated memory
283 * @zpool: The zpool that allocated the memory.
284 * @handle: The handle to the memory to free.
286 * This frees previously allocated memory. This does not guarantee
287 * that the pool will actually free memory, only that the memory
290 * Implementations must guarantee this to be thread-safe,
297 zpool->driver->free(zpool->pool, handle); in zpool_free()
301 * zpool_shrink() - Shrink the pool size
306 * This attempts to shrink the actual memory size of the pool
309 * of the handles, this will fail. If non-NULL, the @reclaimed
313 * Implementations must guarantee this to be thread-safe.
320 return zpool->driver->shrink ? in zpool_shrink()
321 zpool->driver->shrink(zpool->pool, pages, reclaimed) : -EINVAL; in zpool_shrink()
325 * zpool_map_handle() - Map a previously allocated handle into memory
328 * @mapmode: How the memory should be mapped
330 * This maps a previously allocated handle into memory. The @mapmode
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.
338 * actions. The code that uses the mapped handle should complete
339 * its operations on the mapped handle memory quickly and unmap
340 * as soon as possible. As the implementation may use per-cpu
341 * data, multiple handles should not be mapped concurrently on
344 * Returns: A pointer to the handle's mapped memory area.
349 return zpool->driver->map(zpool->pool, handle, mapmode); in zpool_map_handle()
353 * zpool_unmap_handle() - Unmap a previously mapped handle
357 * This unmaps a previously mapped handle. Any locks or other
359 * will be undone here. The memory area returned from
364 zpool->driver->unmap(zpool->pool, handle); in zpool_unmap_handle()
368 * zpool_get_total_size() - The total size of the pool
377 return zpool->driver->total_size(zpool->pool); in zpool_get_total_size()
381 * zpool_evictable() - Test if zpool is potentially evictable
395 return zpool->evictable; in zpool_evictable()
399 * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped.
406 return zpool->can_sleep_mapped; in zpool_can_sleep_mapped()
411 MODULE_DESCRIPTION("Common API for compressed memory storage");