1bcf1647dSMinchan Kim /* 2bcf1647dSMinchan Kim * zsmalloc memory allocator 3bcf1647dSMinchan Kim * 4bcf1647dSMinchan Kim * Copyright (C) 2011 Nitin Gupta 531fc00bbSMinchan Kim * Copyright (C) 2012, 2013 Minchan Kim 6bcf1647dSMinchan Kim * 7bcf1647dSMinchan Kim * This code is released using a dual license strategy: BSD/GPL 8bcf1647dSMinchan Kim * You can choose the license that better fits your requirements. 9bcf1647dSMinchan Kim * 10bcf1647dSMinchan Kim * Released under the terms of 3-clause BSD License 11bcf1647dSMinchan Kim * Released under the terms of GNU General Public License Version 2.0 12bcf1647dSMinchan Kim */ 13bcf1647dSMinchan Kim 14bcf1647dSMinchan Kim #ifndef _ZS_MALLOC_H_ 15bcf1647dSMinchan Kim #define _ZS_MALLOC_H_ 16bcf1647dSMinchan Kim 17bcf1647dSMinchan Kim #include <linux/types.h> 18bcf1647dSMinchan Kim 197d3f3938SSergey Senozhatsky struct zs_pool_stats { 20860c707dSSergey Senozhatsky /* How many pages were migrated (freed) */ 2123959281SRokudo Yan atomic_long_t pages_compacted; 227d3f3938SSergey Senozhatsky }; 237d3f3938SSergey Senozhatsky 24bcf1647dSMinchan Kim struct zs_pool; 25bcf1647dSMinchan Kim 26d0d8da2dSSergey Senozhatsky struct zs_pool *zs_create_pool(const char *name); 27bcf1647dSMinchan Kim void zs_destroy_pool(struct zs_pool *pool); 28bcf1647dSMinchan Kim 29d0d8da2dSSergey Senozhatsky unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags); 30bcf1647dSMinchan Kim void zs_free(struct zs_pool *pool, unsigned long obj); 31bcf1647dSMinchan Kim 32010b495eSSergey Senozhatsky size_t zs_huge_class_size(struct zs_pool *pool); 33010b495eSSergey Senozhatsky 34722cdc17SMinchan Kim unsigned long zs_get_total_pages(struct zs_pool *pool); 35312fcae2SMinchan Kim unsigned long zs_compact(struct zs_pool *pool); 36bcf1647dSMinchan Kim 377c2af309SAlexey Romanov unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); 387c2af309SAlexey Romanov 397d3f3938SSergey Senozhatsky void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); 40*44f76413SSergey Senozhatsky 41*44f76413SSergey Senozhatsky void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle, 42*44f76413SSergey Senozhatsky void *local_copy); 43*44f76413SSergey Senozhatsky void zs_obj_read_end(struct zs_pool *pool, unsigned long handle, 44*44f76413SSergey Senozhatsky void *handle_mem); 45*44f76413SSergey Senozhatsky void zs_obj_write(struct zs_pool *pool, unsigned long handle, 46*44f76413SSergey Senozhatsky void *handle_mem, size_t mem_len); 47*44f76413SSergey Senozhatsky 48bcf1647dSMinchan Kim #endif 49