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.
33 * zpool_register_driver() - register a zpool implementation.
39 atomic_set(&driver->refcount, 0); in zpool_register_driver()
40 list_add(&driver->list, &drivers_head); in zpool_register_driver()
46 * zpool_unregister_driver() - unregister a zpool implementation.
60 refcount = atomic_read(&driver->refcount); in zpool_unregister_driver()
63 ret = -EBUSY; in zpool_unregister_driver()
65 list_del(&driver->list); in zpool_unregister_driver()
72 /* this assumes @type is null-terminated. */
79 if (!strcmp(driver->type, type)) { in zpool_get_driver()
80 bool got = try_module_get(driver->owner); in zpool_get_driver()
83 atomic_inc(&driver->refcount); in zpool_get_driver()
95 atomic_dec(&driver->refcount); in zpool_put_driver()
96 module_put(driver->owner); in zpool_put_driver()
100 * zpool_has_pool() - Check if the pool driver is available
113 * The @type string must be null-terminated.
122 request_module("zpool-%s", type); in zpool_has_pool()
135 * zpool_create_pool() - Create a new zpool
142 * used when allocating memory, if the implementation supports it. If the
145 * Implementations must guarantee this to be thread-safe.
147 * The @type and @name strings must be null-terminated.
162 request_module("zpool-%s", type); in zpool_create_pool()
173 pr_err("couldn't create zpool - out of memory\n"); in zpool_create_pool()
178 zpool->driver = driver; in zpool_create_pool()
179 zpool->pool = driver->create(name, gfp, ops, zpool); in zpool_create_pool()
180 zpool->ops = ops; in zpool_create_pool()
181 zpool->evictable = driver->shrink && ops && ops->evict; in zpool_create_pool()
182 zpool->can_sleep_mapped = driver->sleep_mapped; in zpool_create_pool()
184 if (!zpool->pool) { in zpool_create_pool()
197 * zpool_destroy_pool() - Destroy a zpool
200 * Implementations must guarantee this to be thread-safe,
209 pr_debug("destroying pool type %s\n", zpool->driver->type); in zpool_destroy_pool()
211 zpool->driver->destroy(zpool->pool); in zpool_destroy_pool()
212 zpool_put_driver(zpool->driver); in zpool_destroy_pool()
217 * zpool_get_type() - Get the type of the zpool
222 * Implementations must guarantee this to be thread-safe.
228 return zpool->driver->type; in zpool_get_type()
232 * zpool_malloc_support_movable() - Check if the zpool supports
233 * allocating movable memory
236 * This returns if the zpool supports allocating movable memory.
238 * Implementations must guarantee this to be thread-safe.
240 * Returns: true if the zpool supports allocating movable memory, false if not
244 return zpool->driver->malloc_support_movable; in zpool_malloc_support_movable()
248 * zpool_malloc() - Allocate memory
250 * @size: The amount of memory to allocate.
251 * @gfp: The GFP flags to use when allocating memory.
254 * This allocates the requested amount of memory from the pool.
255 * The gfp flags will be used when allocating memory, if the
259 * Implementations must guarantee this to be thread-safe.
266 return zpool->driver->malloc(zpool->pool, size, gfp, handle); in zpool_malloc()
270 * zpool_free() - Free previously allocated memory
271 * @zpool: The zpool that allocated the memory.
272 * @handle: The handle to the memory to free.
274 * This frees previously allocated memory. This does not guarantee
275 * that the pool will actually free memory, only that the memory
278 * Implementations must guarantee this to be thread-safe,
285 zpool->driver->free(zpool->pool, handle); in zpool_free()
289 * zpool_shrink() - Shrink the pool size
294 * This attempts to shrink the actual memory size of the pool
297 * of the handles, this will fail. If non-NULL, the @reclaimed
301 * Implementations must guarantee this to be thread-safe.
308 return zpool->driver->shrink ? in zpool_shrink()
309 zpool->driver->shrink(zpool->pool, pages, reclaimed) : -EINVAL; in zpool_shrink()
313 * zpool_map_handle() - Map a previously allocated handle into memory
316 * @mapmode: How the memory should be mapped
318 * This maps a previously allocated handle into memory. The @mapmode
319 * param indicates to the implementation how the memory will be
320 * used, i.e. read-only, write-only, read-write. If the
321 * implementation does not support it, the memory will be treated
322 * as read-write.
326 * actions. The code that uses the mapped handle should complete
327 * its operations on the mapped handle memory quickly and unmap
328 * as soon as possible. As the implementation may use per-cpu
329 * data, multiple handles should not be mapped concurrently on
332 * Returns: A pointer to the handle's mapped memory area.
337 return zpool->driver->map(zpool->pool, handle, mapmode); in zpool_map_handle()
341 * zpool_unmap_handle() - Unmap a previously mapped handle
345 * This unmaps a previously mapped handle. Any locks or other
347 * will be undone here. The memory area returned from
352 zpool->driver->unmap(zpool->pool, handle); in zpool_unmap_handle()
356 * zpool_get_total_size() - The total size of the pool
365 return zpool->driver->total_size(zpool->pool); in zpool_get_total_size()
369 * zpool_evictable() - Test if zpool is potentially evictable
383 return zpool->evictable; in zpool_evictable()
387 * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped.
394 return zpool->can_sleep_mapped; in zpool_can_sleep_mapped()
399 MODULE_DESCRIPTION("Common API for compressed memory storage");