Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * zpool memory storage api
0004  *
0005  * Copyright (C) 2014 Dan Streetman
0006  *
0007  * This is a common frontend for the zbud and zsmalloc memory
0008  * storage pool implementations.  Typically, this is used to
0009  * store compressed memory.
0010  */
0011 
0012 #ifndef _ZPOOL_H_
0013 #define _ZPOOL_H_
0014 
0015 struct zpool;
0016 
0017 struct zpool_ops {
0018     int (*evict)(struct zpool *pool, unsigned long handle);
0019 };
0020 
0021 /*
0022  * Control how a handle is mapped.  It will be ignored if the
0023  * implementation does not support it.  Its use is optional.
0024  * Note that this does not refer to memory protection, it
0025  * refers to how the memory will be copied in/out if copying
0026  * is necessary during mapping; read-write is the safest as
0027  * it copies the existing memory in on map, and copies the
0028  * changed memory back out on unmap.  Write-only does not copy
0029  * in the memory and should only be used for initialization.
0030  * If in doubt, use ZPOOL_MM_DEFAULT which is read-write.
0031  */
0032 enum zpool_mapmode {
0033     ZPOOL_MM_RW, /* normal read-write mapping */
0034     ZPOOL_MM_RO, /* read-only (no copy-out at unmap time) */
0035     ZPOOL_MM_WO, /* write-only (no copy-in at map time) */
0036 
0037     ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
0038 };
0039 
0040 bool zpool_has_pool(char *type);
0041 
0042 struct zpool *zpool_create_pool(const char *type, const char *name,
0043             gfp_t gfp, const struct zpool_ops *ops);
0044 
0045 const char *zpool_get_type(struct zpool *pool);
0046 
0047 void zpool_destroy_pool(struct zpool *pool);
0048 
0049 bool zpool_malloc_support_movable(struct zpool *pool);
0050 
0051 int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
0052             unsigned long *handle);
0053 
0054 void zpool_free(struct zpool *pool, unsigned long handle);
0055 
0056 int zpool_shrink(struct zpool *pool, unsigned int pages,
0057             unsigned int *reclaimed);
0058 
0059 void *zpool_map_handle(struct zpool *pool, unsigned long handle,
0060             enum zpool_mapmode mm);
0061 
0062 void zpool_unmap_handle(struct zpool *pool, unsigned long handle);
0063 
0064 u64 zpool_get_total_size(struct zpool *pool);
0065 
0066 
0067 /**
0068  * struct zpool_driver - driver implementation for zpool
0069  * @type:   name of the driver.
0070  * @list:   entry in the list of zpool drivers.
0071  * @create: create a new pool.
0072  * @destroy:    destroy a pool.
0073  * @malloc: allocate mem from a pool.
0074  * @free:   free mem from a pool.
0075  * @shrink: shrink the pool.
0076  * @sleep_mapped: whether zpool driver can sleep during map.
0077  * @map:    map a handle.
0078  * @unmap:  unmap a handle.
0079  * @total_size: get total size of a pool.
0080  *
0081  * This is created by a zpool implementation and registered
0082  * with zpool.
0083  */
0084 struct zpool_driver {
0085     char *type;
0086     struct module *owner;
0087     atomic_t refcount;
0088     struct list_head list;
0089 
0090     void *(*create)(const char *name,
0091             gfp_t gfp,
0092             const struct zpool_ops *ops,
0093             struct zpool *zpool);
0094     void (*destroy)(void *pool);
0095 
0096     bool malloc_support_movable;
0097     int (*malloc)(void *pool, size_t size, gfp_t gfp,
0098                 unsigned long *handle);
0099     void (*free)(void *pool, unsigned long handle);
0100 
0101     int (*shrink)(void *pool, unsigned int pages,
0102                 unsigned int *reclaimed);
0103 
0104     bool sleep_mapped;
0105     void *(*map)(void *pool, unsigned long handle,
0106                 enum zpool_mapmode mm);
0107     void (*unmap)(void *pool, unsigned long handle);
0108 
0109     u64 (*total_size)(void *pool);
0110 };
0111 
0112 void zpool_register_driver(struct zpool_driver *driver);
0113 
0114 int zpool_unregister_driver(struct zpool_driver *driver);
0115 
0116 bool zpool_evictable(struct zpool *pool);
0117 bool zpool_can_sleep_mapped(struct zpool *pool);
0118 
0119 #endif