blob: c2eb174b97eef7cf74045be9c6cdf0ac779564ee [file] [log] [blame]
Nitin Gupta61989a82012-01-09 16:51:56 -06001/*
2 * zsmalloc memory allocator
3 *
4 * Copyright (C) 2011 Nitin Gupta
5 *
6 * This code is released using a dual license strategy: BSD/GPL
7 * You can choose the license that better fits your requirements.
8 *
9 * Released under the terms of 3-clause BSD License
10 * Released under the terms of GNU General Public License Version 2.0
11 */
12
13#ifndef _ZS_MALLOC_H_
14#define _ZS_MALLOC_H_
15
16#include <linux/types.h>
17
Seth Jenningsb7418512012-07-02 16:15:52 -050018/*
19 * zsmalloc mapping modes
20 *
Nitin Cuptac3e3e882013-12-11 11:04:37 +090021 * NOTE: These only make a difference when a mapped object spans pages.
22 * They also have no effect when PGTABLE_MAPPING is selected.
Sara Bird396b7fd2013-05-20 15:18:14 -040023 */
Seth Jenningsb7418512012-07-02 16:15:52 -050024enum zs_mapmode {
25 ZS_MM_RW, /* normal read-write mapping */
26 ZS_MM_RO, /* read-only (no copy-out at unmap time) */
27 ZS_MM_WO /* write-only (no copy-in at map time) */
Nitin Cuptac3e3e882013-12-11 11:04:37 +090028 /*
29 * NOTE: ZS_MM_WO should only be used for initializing new
30 * (uninitialized) allocations. Partial writes to already
31 * initialized allocations should use ZS_MM_RW to preserve the
32 * existing data.
33 */
Seth Jenningsb7418512012-07-02 16:15:52 -050034};
35
Nitin Gupta61989a82012-01-09 16:51:56 -060036struct zs_pool;
37
Seth Jennings0d145a52013-01-30 09:36:52 -060038struct zs_pool *zs_create_pool(gfp_t flags);
Nitin Gupta61989a82012-01-09 16:51:56 -060039void zs_destroy_pool(struct zs_pool *pool);
40
Minchan Kimc2344342012-06-08 15:39:25 +090041unsigned long zs_malloc(struct zs_pool *pool, size_t size);
42void zs_free(struct zs_pool *pool, unsigned long obj);
Nitin Gupta61989a82012-01-09 16:51:56 -060043
Seth Jenningsb7418512012-07-02 16:15:52 -050044void *zs_map_object(struct zs_pool *pool, unsigned long handle,
45 enum zs_mapmode mm);
Minchan Kimc2344342012-06-08 15:39:25 +090046void zs_unmap_object(struct zs_pool *pool, unsigned long handle);
Nitin Gupta61989a82012-01-09 16:51:56 -060047
48u64 zs_get_total_size_bytes(struct zs_pool *pool);
49
50#endif