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 19bcf1647dSMinchan Kim /* 20bcf1647dSMinchan Kim * zsmalloc mapping modes 21bcf1647dSMinchan Kim * 22bcf1647dSMinchan Kim * NOTE: These only make a difference when a mapped object spans pages. 23bcf1647dSMinchan Kim */ 24bcf1647dSMinchan Kim enum zs_mapmode { 25bcf1647dSMinchan Kim ZS_MM_RW, /* normal read-write mapping */ 26bcf1647dSMinchan Kim ZS_MM_RO, /* read-only (no copy-out at unmap time) */ 27bcf1647dSMinchan Kim ZS_MM_WO /* write-only (no copy-in at map time) */ 28bcf1647dSMinchan Kim /* 29bcf1647dSMinchan Kim * NOTE: ZS_MM_WO should only be used for initializing new 30bcf1647dSMinchan Kim * (uninitialized) allocations. Partial writes to already 31bcf1647dSMinchan Kim * initialized allocations should use ZS_MM_RW to preserve the 32bcf1647dSMinchan Kim * existing data. 33bcf1647dSMinchan Kim */ 34bcf1647dSMinchan Kim }; 35bcf1647dSMinchan Kim 367d3f3938SSergey Senozhatsky struct zs_pool_stats { 37860c707dSSergey Senozhatsky /* How many pages were migrated (freed) */ 3823959281SRokudo Yan atomic_long_t pages_compacted; 397d3f3938SSergey Senozhatsky }; 407d3f3938SSergey Senozhatsky 41bcf1647dSMinchan Kim struct zs_pool; 42bcf1647dSMinchan Kim 43d0d8da2dSSergey Senozhatsky struct zs_pool *zs_create_pool(const char *name); 44bcf1647dSMinchan Kim void zs_destroy_pool(struct zs_pool *pool); 45bcf1647dSMinchan Kim 46d0d8da2dSSergey Senozhatsky unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags); 47bcf1647dSMinchan Kim void zs_free(struct zs_pool *pool, unsigned long obj); 48bcf1647dSMinchan Kim 49010b495eSSergey Senozhatsky size_t zs_huge_class_size(struct zs_pool *pool); 50010b495eSSergey Senozhatsky 51bcf1647dSMinchan Kim void *zs_map_object(struct zs_pool *pool, unsigned long handle, 52bcf1647dSMinchan Kim enum zs_mapmode mm); 53bcf1647dSMinchan Kim void zs_unmap_object(struct zs_pool *pool, unsigned long handle); 54bcf1647dSMinchan Kim 55722cdc17SMinchan Kim unsigned long zs_get_total_pages(struct zs_pool *pool); 56312fcae2SMinchan Kim unsigned long zs_compact(struct zs_pool *pool); 57bcf1647dSMinchan Kim 58*7c2af309SAlexey Romanov unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); 59*7c2af309SAlexey Romanov 607d3f3938SSergey Senozhatsky void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); 61bcf1647dSMinchan Kim #endif 62