Skip to content

Commit bcf1647

Browse files
minchanktorvalds
authored andcommitted
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>
1 parent 73f9455 commit bcf1647

9 files changed

Lines changed: 28 additions & 34 deletions

File tree

‎drivers/staging/Kconfig‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ source "drivers/staging/sep/Kconfig"
7676

7777
source "drivers/staging/iio/Kconfig"
7878

79-
source "drivers/staging/zsmalloc/Kconfig"
80-
8179
source "drivers/staging/zram/Kconfig"
8280

8381
source "drivers/staging/wlags49_h2/Kconfig"

‎drivers/staging/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ obj-$(CONFIG_VME_BUS) += vme/
3333
obj-$(CONFIG_DX_SEP) += sep/
3434
obj-$(CONFIG_IIO) += iio/
3535
obj-$(CONFIG_ZRAM) += zram/
36-
obj-$(CONFIG_ZSMALLOC) += zsmalloc/
3736
obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
3837
obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
3938
obj-$(CONFIG_FB_SM7XX) += sm7xxfb/

‎drivers/staging/zram/zram_drv.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
#include <linux/spinlock.h>
1919
#include <linux/mutex.h>
20-
21-
#include "../zsmalloc/zsmalloc.h"
20+
#include <linux/zsmalloc.h>
2221

2322
/*
2423
* Some arbitrary value. This is just to catch

‎drivers/staging/zsmalloc/Kconfig‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎drivers/staging/zsmalloc/Makefile‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎mm/Kconfig‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,28 @@ config MEM_SOFT_DIRTY
552552
it can be cleared by hands.
553553

554554
See Documentation/vm/soft-dirty.txt for more details.
555+
556+
config ZSMALLOC
557+
bool "Memory allocator for compressed pages"
558+
depends on MMU
559+
default n
560+
help
561+
zsmalloc is a slab-based memory allocator designed to store
562+
compressed RAM pages. zsmalloc uses virtual memory mapping
563+
in order to reduce fragmentation. However, this results in a
564+
non-standard allocator interface where a handle, not a pointer, is
565+
returned by an alloc(). This handle must be mapped in order to
566+
access the allocated space.
567+
568+
config PGTABLE_MAPPING
569+
bool "Use page table mapping to access object in zsmalloc"
570+
depends on ZSMALLOC
571+
help
572+
By default, zsmalloc uses a copy-based object mapping method to
573+
access allocations that span two pages. However, if a particular
574+
architecture (ex, ARM) performs VM mapping faster than copying,
575+
then you should select this. This causes zsmalloc to use page table
576+
mapping rather than copying for object mapping.
577+
578+
You can check speed with zsmalloc benchmark[1].
579+
[1] https://github.com/spartacus06/zsmalloc

‎mm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
6060
obj-$(CONFIG_CLEANCACHE) += cleancache.o
6161
obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
6262
obj-$(CONFIG_ZBUD) += zbud.o
63+
obj-$(CONFIG_ZSMALLOC) += zsmalloc.o
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@
9090
#include <linux/hardirq.h>
9191
#include <linux/spinlock.h>
9292
#include <linux/types.h>
93-
94-
#include "zsmalloc.h"
93+
#include <linux/zsmalloc.h>
9594

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

0 commit comments

Comments
 (0)