Skip to content

Commit

Permalink
zsmalloc: move it under mm
Browse files Browse the repository at this point in the history
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

[[email protected]: borrow Seth's quote]
Signed-off-by: Minchan Kim <[email protected]>
Acked-by: Nitin Gupta <[email protected]>
Reviewed-by: Konrad Rzeszutek Wilk <[email protected]>
Cc: Bob Liu <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Luigi Semenzato <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Seth Jennings <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
minchank authored and torvalds committed Jan 31, 2014
1 parent 73f9455 commit bcf1647
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 34 deletions.
2 changes: 0 additions & 2 deletions drivers/staging/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ source "drivers/staging/sep/Kconfig"

source "drivers/staging/iio/Kconfig"

source "drivers/staging/zsmalloc/Kconfig"

source "drivers/staging/zram/Kconfig"

source "drivers/staging/wlags49_h2/Kconfig"
Expand Down
1 change: 0 additions & 1 deletion drivers/staging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ obj-$(CONFIG_VME_BUS) += vme/
obj-$(CONFIG_DX_SEP) += sep/
obj-$(CONFIG_IIO) += iio/
obj-$(CONFIG_ZRAM) += zram/
obj-$(CONFIG_ZSMALLOC) += zsmalloc/
obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
obj-$(CONFIG_FB_SM7XX) += sm7xxfb/
Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/zram/zram_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

#include <linux/spinlock.h>
#include <linux/mutex.h>

#include "../zsmalloc/zsmalloc.h"
#include <linux/zsmalloc.h>

/*
* Some arbitrary value. This is just to catch
Expand Down
24 changes: 0 additions & 24 deletions drivers/staging/zsmalloc/Kconfig

This file was deleted.

3 changes: 0 additions & 3 deletions drivers/staging/zsmalloc/Makefile

This file was deleted.

File renamed without changes.
25 changes: 25 additions & 0 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,28 @@ config MEM_SOFT_DIRTY
it can be cleared by hands.

See Documentation/vm/soft-dirty.txt for more details.

config ZSMALLOC
bool "Memory allocator for compressed pages"
depends on MMU
default n
help
zsmalloc is a slab-based memory allocator designed to store
compressed RAM pages. zsmalloc uses virtual memory mapping
in order to reduce fragmentation. However, this results in a
non-standard allocator interface where a handle, not a pointer, is
returned by an alloc(). This handle must be mapped in order to
access the allocated space.

config PGTABLE_MAPPING
bool "Use page table mapping to access object in zsmalloc"
depends on ZSMALLOC
help
By default, zsmalloc uses a copy-based object mapping method to
access allocations that span two pages. However, if a particular
architecture (ex, ARM) performs VM mapping faster than copying,
then you should select this. This causes zsmalloc to use page table
mapping rather than copying for object mapping.

You can check speed with zsmalloc benchmark[1].
[1] https://github.com/spartacus06/zsmalloc
1 change: 1 addition & 0 deletions mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
obj-$(CONFIG_CLEANCACHE) += cleancache.o
obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
obj-$(CONFIG_ZBUD) += zbud.o
obj-$(CONFIG_ZSMALLOC) += zsmalloc.o
3 changes: 1 addition & 2 deletions drivers/staging/zsmalloc/zsmalloc-main.c → mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
#include <linux/hardirq.h>
#include <linux/spinlock.h>
#include <linux/types.h>

#include "zsmalloc.h"
#include <linux/zsmalloc.h>

/*
* This must be power of 2 and greater than of equal to sizeof(link_free).
Expand Down

0 comments on commit bcf1647

Please sign in to comment.