Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * zsmalloc memory allocator
0003  *
0004  * Copyright (C) 2011  Nitin Gupta
0005  * Copyright (C) 2012, 2013 Minchan Kim
0006  *
0007  * This code is released using a dual license strategy: BSD/GPL
0008  * You can choose the license that better fits your requirements.
0009  *
0010  * Released under the terms of 3-clause BSD License
0011  * Released under the terms of GNU General Public License Version 2.0
0012  */
0013 
0014 #ifndef _ZS_MALLOC_H_
0015 #define _ZS_MALLOC_H_
0016 
0017 #include <linux/types.h>
0018 
0019 /*
0020  * zsmalloc mapping modes
0021  *
0022  * NOTE: These only make a difference when a mapped object spans pages.
0023  */
0024 enum zs_mapmode {
0025     ZS_MM_RW, /* normal read-write mapping */
0026     ZS_MM_RO, /* read-only (no copy-out at unmap time) */
0027     ZS_MM_WO /* write-only (no copy-in at map time) */
0028     /*
0029      * NOTE: ZS_MM_WO should only be used for initializing new
0030      * (uninitialized) allocations.  Partial writes to already
0031      * initialized allocations should use ZS_MM_RW to preserve the
0032      * existing data.
0033      */
0034 };
0035 
0036 struct zs_pool_stats {
0037     /* How many pages were migrated (freed) */
0038     atomic_long_t pages_compacted;
0039 };
0040 
0041 struct zs_pool;
0042 
0043 struct zs_pool *zs_create_pool(const char *name);
0044 void zs_destroy_pool(struct zs_pool *pool);
0045 
0046 unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags);
0047 void zs_free(struct zs_pool *pool, unsigned long obj);
0048 
0049 size_t zs_huge_class_size(struct zs_pool *pool);
0050 
0051 void *zs_map_object(struct zs_pool *pool, unsigned long handle,
0052             enum zs_mapmode mm);
0053 void zs_unmap_object(struct zs_pool *pool, unsigned long handle);
0054 
0055 unsigned long zs_get_total_pages(struct zs_pool *pool);
0056 unsigned long zs_compact(struct zs_pool *pool);
0057 
0058 void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats);
0059 #endif