diff options
author | Minchan Kim <minchan@kernel.org> | 2014-01-30 18:45:50 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-30 19:56:55 -0500 |
commit | bcf1647d0899666f0fb90d176abf63bae22abb7c (patch) | |
tree | 6682b0feec718f594829770b4287afa2da266a0f /include/linux/zsmalloc.h | |
parent | 73f945505b9bf798d8c3ee830cb330dd6d7fb4c7 (diff) |
zsmalloc: move it under mm
This patch moves zsmalloc under mm directory.
Before that, description will explain why we have needed custom
allocator.
Zsmalloc is a new slab-based memory allocator for storing compressed
pages. It is designed for low fragmentation and high allocation success
rate on large object, but <= PAGE_SIZE allocations.
zsmalloc differs from the kernel slab allocator in two primary ways to
achieve these design goals.
zsmalloc never requires high order page allocations to back slabs, or
"size classes" in zsmalloc terms. Instead it allows multiple
single-order pages to be stitched together into a "zspage" which backs
the slab. This allows for higher allocation success rate under memory
pressure.
Also, zsmalloc allows objects to span page boundaries within the zspage.
This allows for lower fragmentation than could be had with the kernel
slab allocator for objects between PAGE_SIZE/2 and PAGE_SIZE. With the
kernel slab allocator, if a page compresses to 60% of it original size,
the memory savings gained through compression is lost in fragmentation
because another object of the same size can't be stored in the leftover
space.
This ability to span pages results in zsmalloc allocations not being
directly addressable by the user. The user is given an
non-dereferencable handle in response to an allocation request. That
handle must be mapped, using zs_map_object(), which returns a pointer to
the mapped region that can be used. The mapping is necessary since the
object data may reside in two different noncontigious pages.
The zsmalloc fulfills the allocation needs for zram perfectly
[sjenning@linux.vnet.ibm.com: borrow Seth's quote]
Signed-off-by: Minchan Kim <minchan@kernel.org>
Acked-by: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Bob Liu <bob.liu@oracle.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Luigi Semenzato <semenzato@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Seth Jennings <sjenning@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/zsmalloc.h')
-rw-r--r-- | include/linux/zsmalloc.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h new file mode 100644 index 000000000000..c2eb174b97ee --- /dev/null +++ b/include/linux/zsmalloc.h | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
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 | |||
18 | /* | ||
19 | * zsmalloc mapping modes | ||
20 | * | ||
21 | * NOTE: These only make a difference when a mapped object spans pages. | ||
22 | * They also have no effect when PGTABLE_MAPPING is selected. | ||
23 | */ | ||
24 | enum 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) */ | ||
28 | /* | ||
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 | */ | ||
34 | }; | ||
35 | |||
36 | struct zs_pool; | ||
37 | |||
38 | struct zs_pool *zs_create_pool(gfp_t flags); | ||
39 | void zs_destroy_pool(struct zs_pool *pool); | ||
40 | |||
41 | unsigned long zs_malloc(struct zs_pool *pool, size_t size); | ||
42 | void zs_free(struct zs_pool *pool, unsigned long obj); | ||
43 | |||
44 | void *zs_map_object(struct zs_pool *pool, unsigned long handle, | ||
45 | enum zs_mapmode mm); | ||
46 | void zs_unmap_object(struct zs_pool *pool, unsigned long handle); | ||
47 | |||
48 | u64 zs_get_total_size_bytes(struct zs_pool *pool); | ||
49 | |||
50 | #endif | ||