zram/zsmalloc promotion
Subsystems (7)
Minchan Kim
maintainerv9 cover zram/zsmalloc promotion
Zram is a simple pseudo block device which can keep data on in-memory with compressed[1].
It have been used for many embedded system for several years One of significant usecase is in-memory swap device. Because NAND which is very popular on most embedded device is weak for frequent write without good wear-level and slow I/O hurts system's responsiblity so zram is really good choice to use memory efficiently.
In previous trial, there was some argument[2] that zram has similar goal with zswap so let's merge zram's functionality into zswap via adding pseudo block device in zswap but I and some people(At least, Hugh and Rik) believe it's not a good idea. [2][3][4] and zswap might go writethrough model[5]. It makes clear difference zram and zswap.
Zram itself is simple/well-designed/good abstraciton so it has clear market(ex, Android, TV, ChromeOS, some Linux distro) which is never niche. :)
Another zram-blk's usecase is following as.
The admin can use it as tmpfs so it could help small memory system. The tmpfs is never good solution for swapless embedded system.
Patch 1 adds new Kconfig for zram to use page table method instead of copy.
Patch 2 adds more comment for zsmalloc.
Patch 3 moves zsmalloc under mm.
Patch 4 moves zram from driver/staging to driver/blocks, finally.
[1] http://en.wikipedia.org/wiki/Zram
[2] https://lkml.org/lkml/2013/8/21/54
[3] https://lkml.org/lkml/2013/11/13/570
[4] https://lkml.org/lkml/2013/11/7/318
[5] http://www.spinics.net/lists/linux-mm/msg65499.html
* From v8
* Move zram.txt into Documentation/blockdev/ - Jerome
* Rebased on next-20131210
* From v7
* Remove unnecessary zswap VS zram comparison in cover letter.
* Add Reviewed-by/Acked-by I forgot.
* Remove exporting unmap_kernel_range patch. I will do if promotion is done.
* Move zsmalloc under mm - Hugh
Minchan Kim (3):
zsmalloc: add Kconfig for enabling page table method
zsmalloc: move it under mm
zram: promote zram from staging
Nitin Cupta (1):
zsmalloc: add more comment
Documentation/blockdev/zram.txt | 77 +++ drivers/block/Kconfig | 2 + drivers/block/Makefile | 1 + drivers/block/zram/Kconfig | 25 + drivers/block/zram/Makefile | 3 + drivers/block/zram/zram_drv.c | 994 +++++++++++++++++++++++++++ drivers/block/zram/zram_drv.h | 124 ++++ drivers/staging/Kconfig | 4 - drivers/staging/Makefile | 2 - drivers/staging/zram/Kconfig | 25 - drivers/staging/zram/Makefile | 3 - drivers/staging/zram/zram.txt | 77 --- drivers/staging/zram/zram_drv.c | 994 --------------------------- drivers/staging/zram/zram_drv.h | 125 ---- drivers/staging/zsmalloc/Kconfig | 11 - drivers/staging/zsmalloc/Makefile | 3 - drivers/staging/zsmalloc/zsmalloc-main.c | 1072 ----------------------------- drivers/staging/zsmalloc/zsmalloc.h | 43 -- include/linux/zsmalloc.h | 50 ++ mm/Kconfig | 25 + mm/Makefile | 1 + mm/zsmalloc.c | 1106 ++++++++++++++++++++++++++++++ 22 files changed, 2408 insertions(+), 2359 deletions(-) create mode 100644 Documentation/blockdev/zram.txt create mode 100644 drivers/block/zram/Kconfig create mode 100644 drivers/block/zram/Makefile create mode 100644 drivers/block/zram/zram_drv.c create mode 100644 drivers/block/zram/zram_drv.h delete mode 100644 drivers/staging/zram/Kconfig delete mode 100644 drivers/staging/zram/Makefile delete mode 100644 drivers/staging/zram/zram.txt delete mode 100644 drivers/staging/zram/zram_drv.c delete mode 100644 drivers/staging/zram/zram_drv.h delete mode 100644 drivers/staging/zsmalloc/Kconfig delete mode 100644 drivers/staging/zsmalloc/Makefile delete mode 100644 drivers/staging/zsmalloc/zsmalloc-main.c delete mode 100644 drivers/staging/zsmalloc/zsmalloc.h create mode 100644 include/linux/zsmalloc.h create mode 100644 mm/zsmalloc.c
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Minchan Kim
maintainerPATCH v9 1/4 zsmalloc: add Kconfig for enabling page table method
Zsmalloc has two methods 1) copy-based and 2) pte based to access objects that span two pages.
You can see history why we supported two approach from [1].
But it was bad choice that adding hard coding to select arch which want to use pte based method because there are lots of SoC in an architecure and they can have different cache size, CPU speed and so on so it would be better to expose it to user as selectable Kconfig option like Andrew Morton suggested.
[1] https://lkml.org/lkml/2012/7/11/58
--- drivers/staging/zsmalloc/Kconfig | 13 +++++++++++++ drivers/staging/zsmalloc/zsmalloc-main.c | 19 ++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/zsmalloc/Kconfig +13 -0
@@ -9,3 +9,16 @@ config ZSMALLOC 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
drivers/staging/zsmalloc/zsmalloc-main.c +4 -15
@@ -218,19 +218,8 @@ struct zs_pool {#define CLASS_IDX_MASK ((1 << CLASS_IDX_BITS) - 1)#define FULLNESS_MASK ((1 << FULLNESS_BITS) - 1) -/* -* By default, zsmalloc uses a copy-based object mapping method to access -* allocations that span two pages. However, if a particular architecture -* performs VM mapping faster than copying, then it should be added here -* so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use -* page table mapping rather than copying for object mapping. -*/ -#if defined(CONFIG_ARM ) && !defined(MODULE ) -#define USE_PGTABLE_MAPPING -#endif -struct mapping_area { -#ifdef USE_PGTABLE_MAPPING +#ifdef CONFIG_PGTABLE_MAPPING struct vm_struct *vm;/* vm area for mapping object that span pages */ #else char *vm_buf;/* copy buffer for objects that span pages */
@@ -631,7 +620,7 @@ static struct page *find_get_zspage(struct size_class *class)return page; } -#ifdef USE_PGTABLE_MAPPING +#ifdef CONFIG_PGTABLE_MAPPING static inline int __zs_cpu_up (struct mapping_area *area) {/*
@@ -669,7 +658,7 @@ static inline void __zs_unmap_object(struct mapping_area *area, unmap_kernel_range(addr, PAGE_SIZE * 2); } -#else /* USE_PGTABLE_MAPPING */ +#else /* CONFIG_PGTABLE_MAPPING */ static inline int __zs_cpu_up (struct mapping_area *area) {
@@ -747,7 +736,7 @@ out: pagefault_enable(); } -#endif /* USE_PGTABLE_MAPPING */ +#endif /* CONFIG_PGTABLE_MAPPING */ static int zs_cpu_notifier (struct notifier_block *nb,unsigned long action,void *pcpu)
Signature · 1 line
1.7.9.5
Minchan Kim
maintainerPATCH v9 2/4 zsmalloc: add more comment
In reply to Minchan KimFrom: Nitin Cupta <[email protected]>
This patch adds lots of comments and it will help others to review and enhance.
--- drivers/staging/zsmalloc/zsmalloc-main.c | 66 +++++++++++++++++++++++++----- drivers/staging/zsmalloc/zsmalloc.h | 9 +++- 2 files changed, 64 insertions(+), 11 deletions(-)
drivers/staging/zsmalloc/zsmalloc-main.c +56 -10
@@ -10,16 +10,14 @@* Released under the terms of GNU General Public License Version 2.0 */ -/* -* This allocator is designed for use with zcache and zram. Thus, the -* allocator is supposed to work well under low memory conditions. In -* particular, it never attempts higher order page allocation which is -* very likely to fail under memory pressure. On the other hand, if we -* just use single (0-order) pages, it would suffer from very high -* fragmentation -- any object of size PAGE_SIZE/2 or larger would occupy -* an entire page. This was one of the major issues with its predecessor -* (xvmalloc). +* This allocator is designed for use with zram. Thus, the allocator is +* supposed to work well under low memory conditions. In particular, it +* never attempts higher order page allocation which is very likely to +* fail under memory pressure. On the other hand, if we just use single +* (0-order) pages, it would suffer from very high fragmentation -- +* any object of size PAGE_SIZE/2 or larger would occupy an entire page. +* This was one of the major issues with its predecessor (xvmalloc). * * To overcome these issues, zsmalloc allocates a bunch of 0-order pages * and links them together using various 'struct page' fields. These linked
@@ -27,6 +25,21 @@* page boundaries. The code refers to these linked pages as a single entity * called zspage. * +* For simplicity, zsmalloc can only allocate objects of size up to PAGE_SIZE +* since this satisfies the requirements of all its current users (in the +* worst case, page is incompressible and is thus stored "as-is" i.e. in +* uncompressed form). For allocation requests larger than this size, failure +* is returned (see zs_malloc). +* +* Additionally, zs_malloc() does not return a dereferenceable pointer. +* Instead, it returns an opaque handle (unsigned long) which encodes actual +* location of the allocated object. The reason for this indirection is that +* zsmalloc does not keep zspages permanently mapped since that would cause +* issues on 32-bit systems where the VA region for kernel space mappings +* is very small. So, before using the allocating memory, the object has to +* be mapped using zs_map_object() to get a usable pointer and subsequently +* unmapped using zs_unmap_object(). +* * Following is how we use various fields and flags of underlying * struct page(s) to form a zspage. *
@@ -98,7 +111,7 @@/* * Object location (<PFN>, <obj_idx>) is encoded as -* as single (void *) handle value. +* as single (unsigned long) handle value. * * Note that object index <obj_idx> is relative to system * page <PFN> it is stored in, so for each sub-page belonging
@@ -264,6 +277,13 @@ static void set_zspage_mapping(struct page *page, unsigned int class_idx, page->mapping = (struct address_space *)m; } +/* +* zsmalloc divides the pool into various size classes where each +* class maintains a list of zspages where each zspage is divided +* into equal sized chunks. Each allocation falls into one of these +* classes depending on its size. This function returns index of the +* size class which has chunk size big enough to hold the give size. +*/ static int get_size_class_index (int size) {int idx =0 ;
@@ -275,6 +295,13 @@ static int get_size_class_index(int size)return idx; } +/* +* For each size class, zspages are divided into different groups +* depending on how "full" they are. This was done so that we could +* easily find empty or nearly empty zspages when we try to shrink +* the pool (not yet implemented). This function returns fullness +* status of the given page. +*/ static enum fullness_group get_fullness_group (struct page *page) {int inuse, max_objects;
@@ -296,6 +323,12 @@ static enum fullness_group get_fullness_group(struct page *page)return fg; } +/* +* Each size class maintains various freelists and zspages are assigned +* to one of these freelists based on the number of live objects they +* have. This functions inserts the given zspage into the freelist +* identified by <class, fullness_group>. +*/ static void insert_zspage (struct page *page,struct size_class *class,enum fullness_group fullness) {
@@ -313,6 +346,10 @@ static void insert_zspage(struct page *page, struct size_class *class, *head = page; } +/* +* This function removes the given zspage from the freelist identified +* by <class, fullness_group>. +*/ static void remove_zspage (struct page *page,struct size_class *class,enum fullness_group fullness) {
@@ -334,6 +371,15 @@ static void remove_zspage(struct page *page, struct size_class *class,list_del_init (&page->lru); } +/* +* Each size class maintains zspages in different fullness groups depending +* on the number of live objects they contain. When allocating or freeing +* objects, the fullness status of the page can change, say, from ALMOST_FULL +* to ALMOST_EMPTY when freeing an object. This function checks if such +* a status change has occurred for the given page and accordingly moves the +* page from the freelist of the old fullness group to that of the new +* fullness group. +*/ static enum fullness_group fix_fullness_group (struct zs_pool *pool,struct page *page) {
drivers/staging/zsmalloc/zsmalloc.h +8 -1
@@ -18,12 +18,19 @@/* * zsmalloc mapping modes * -* NOTE: These only make a difference when a mapped object spans pages +* NOTE: These only make a difference when a mapped object spans pages. +* They also have no effect when PGTABLE_MAPPING is selected. */ enum zs_mapmode {ZS_MM_RW ,/* normal read-write mapping */ ZS_MM_RO ,/* read-only (no copy-out at unmap time) */ ZS_MM_WO /* write-only (no copy-in at map time) */ +/* +* NOTE: ZS_MM_WO should only be used for initializing new +* (uninitialized) allocations. Partial writes to already +* initialized allocations should use ZS_MM_RW to preserve the +* existing data. +*/ };struct zs_pool ;
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Minchan Kim
maintainerPATCH v9 3/4 zsmalloc: move it under mm
In reply to Minchan KimThis 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
--- drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/zram/zram_drv.h | 3 +- drivers/staging/zsmalloc/Kconfig | 24 - drivers/staging/zsmalloc/Makefile | 3 - drivers/staging/zsmalloc/zsmalloc-main.c | 1107 ------------------------------ drivers/staging/zsmalloc/zsmalloc.h | 50 -- include/linux/zsmalloc.h | 50 ++ mm/Kconfig | 25 + mm/Makefile | 1 + mm/zsmalloc.c | 1106 +++++++++++++++++++++++++++++ 11 files changed, 1183 insertions(+), 1189 deletions(-) delete mode 100644 drivers/staging/zsmalloc/Kconfig delete mode 100644 drivers/staging/zsmalloc/Makefile delete mode 100644 drivers/staging/zsmalloc/zsmalloc-main.c delete mode 100644 drivers/staging/zsmalloc/zsmalloc.h create mode 100644 include/linux/zsmalloc.h create mode 100644 mm/zsmalloc.c
drivers/staging/Kconfig +0 -2
@@ -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"
drivers/staging/Makefile +0 -1
@@ -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/
drivers/staging/zram/zram_drv.h +1 -2
@@ -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
drivers/staging/zsmalloc/Kconfig deleted +0 -24
@@ -1,24 +0,0 @@ -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
drivers/staging/zsmalloc/Makefile deleted +0 -3
@@ -1,3 +0,0 @@ -zsmalloc-y := zsmalloc-main.o - -obj-$(CONFIG_ZSMALLOC) += zsmalloc.o
drivers/staging/zsmalloc/zsmalloc-main.c deleted +0 -1107
1,107 lines not on this page · raw message
drivers/staging/zsmalloc/zsmalloc.h deleted +0 -50
50 lines not on this page · raw message
include/linux/zsmalloc.h new file +50 -0
50 lines not on this page · raw message
mm/Kconfig +25 -0
@@ -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
mm/Makefile +1 -0
@@ -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
mm/zsmalloc.c new file +1106 -0
1,106 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Minchan Kim
maintainerPATCH v9 4/4 zram: promote zram from staging
In reply to Minchan KimZram has lived in staging for a LONG LONG time and have been fixed/improved by many contributors so code is clean and stable now. Of course, there are lots of product using zram in real practice.
The major TV companys have used zram as swap since two years ago and recently our production team released android smart phone with zram which is used as swap, too and recently Android Kitkat start to use zram for small memory smart phone. And there was a report Google released their ChromeOS with zram, too and cyanogenmod have been used zram long time ago. And I heard some disto have used zram block device for tmpfs. In addition, I saw many report from many other peoples. For example, Lubuntu start to use it.
The benefit of zram is very clear. With my experience, one of the benefit was to remove jitter of video application with backgroud memory pressure. It would be effect of efficient memory usage by compression but more issue is whether swap is there or not in the system. Recent mobile platforms have used JAVA so there are many anonymous pages. But embedded system normally are reluctant to use eMMC or SDCard as swap because there is wear-leveling and latency issues so if we do not use swap, it means we can't reclaim anoymous pages and at last, we could encounter OOM kill. :(
Although we have real storage as swap, it was a problem, too. Because it sometime ends up making system very unresponsible caused by slow swap storage performance.
Quote from Luigi on Google
"
Since Chrome OS was mentioned: the main reason why we don't use swap to a disk (rotating or SSD) is because it doesn't degrade gracefully and leads to a bad interactive experience. Generally we prefer to manage RAM at a higher level, by transparently killing and restarting processes. But we noticed that zram is fast enough to be competitive with the latter, and it lets us make more efficient use of the available RAM.
"
and he announced. http://www.spinics.net/lists/linux-mm/msg57717.html
Other uses case is to use zram for block device. Zram is block device so anyone can format the block device and mount on it so some guys on the internet start zram as /var/tmp.
http://forums.gentoo.org/viewtopic-t-838198-start-0.html
Let's promote zram and enhance/maintain it instead of removing.
--- Documentation/blockdev/zram.txt | 77 +++ drivers/block/Kconfig | 2 + drivers/block/Makefile | 1 + drivers/block/zram/Kconfig | 25 + drivers/block/zram/Makefile | 3 + drivers/block/zram/zram_drv.c | 994 +++++++++++++++++++++++++++++++++++++++ drivers/block/zram/zram_drv.h | 124 +++++ drivers/staging/Kconfig | 2 - drivers/staging/Makefile | 1 - drivers/staging/zram/Kconfig | 25 - drivers/staging/zram/Makefile | 3 - drivers/staging/zram/zram.txt | 77 --- drivers/staging/zram/zram_drv.c | 994 --------------------------------------- drivers/staging/zram/zram_drv.h | 124 ----- 14 files changed, 1226 insertions(+), 1226 deletions(-) create mode 100644 Documentation/blockdev/zram.txt create mode 100644 drivers/block/zram/Kconfig create mode 100644 drivers/block/zram/Makefile create mode 100644 drivers/block/zram/zram_drv.c create mode 100644 drivers/block/zram/zram_drv.h delete mode 100644 drivers/staging/zram/Kconfig delete mode 100644 drivers/staging/zram/Makefile delete mode 100644 drivers/staging/zram/zram.txt delete mode 100644 drivers/staging/zram/zram_drv.c delete mode 100644 drivers/staging/zram/zram_drv.h
Documentation/blockdev/zram.txt new file +77 -0
@@ -0,0 +1,77 @@ +zram: Compressed RAM based block devices +---------------------------------------- + +Project home: http://compcache.googlecode.com/ + +* Introduction + +The zram module creates RAM based block devices named /dev/zram<id> +(<id> = 0, 1, ...). Pages written to these disks are compressed and stored +in memory itself. These disks allow very fast I/O and compression provides +good amounts of memory savings. Some of the usecases include /tmp storage, +use as swap disks, various caches under /var and maybe many more :) + +Statistics for individual zram devices are exported through sysfs nodes at +/sys/block/zram<id>/ + +* Usage + +Following shows a typical sequence of steps for using zram. + +1) Load Module: + modprobe zram num_devices=4 + This creates 4 devices: /dev/zram{0,1,2,3} + (num_devices parameter is optional. Default: 1) + +2) Set Disksize + Set disk size by writing the value to sysfs node 'disksize'. + The value can be either in bytes or you can use mem suffixes. + Examples: + # Initialize /dev/zram0 with 50MB disksize + echo $((50*1024*1024)) > /sys/block/zram0/disksize + + # Using mem suffixes + echo 256K > /sys/block/zram0/disksize + echo 512M > /sys/block/zram0/disksize + echo 1G > /sys/block/zram0/disksize + +3) Activate: + mkswap /dev/zram0 + swapon /dev/zram0 + + mkfs.ext4 /dev/zram1 + mount /dev/zram1 /tmp + +4) Stats: + Per-device statistics are exported as various nodes under + /sys/block/zram<id>/ + disksize + num_reads + num_writes + invalid_io + notify_free + discard + zero_pages + orig_data_size + compr_data_size + mem_used_total + +5) Deactivate: + swapoff /dev/zram0 + umount /dev/zram1 + +6) Reset: + Write any positive value to 'reset' sysfs node + echo 1 > /sys/block/zram0/reset + echo 1 > /sys/block/zram1/reset + + This frees all the memory allocated for the given device and + resets the disksize to zero. You must set the disksize again + before reusing the device. + +Please report any problems at: + - Mailing list: linux-mm-cc at laptop dot org + - Issue tracker: http://code.google.com/p/compcache/issues/list + +Nitin Gupta [email protected]
drivers/block/Kconfig +2 -0
@@ -108,6 +108,8 @@ source "drivers/block/paride/Kconfig" source "drivers/block/mtip32xx/Kconfig" +source "drivers/block/zram/Kconfig" + config BLK_CPQ_DA tristate "Compaq SMART2 support" depends on PCI && VIRT_TO_BUS && 0
drivers/block/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o +obj-$(CONFIG_ZRAM) += zram/ nvme-y := nvme-core.o nvme-scsi.o skd-y := skd_main.o
drivers/block/zram/Kconfig new file +25 -0
@@ -0,0 +1,25 @@ +config ZRAM + tristate "Compressed RAM block device support" + depends on BLOCK && SYSFS && ZSMALLOC + select LZO_COMPRESS + select LZO_DECOMPRESS + default n + help + Creates virtual block devices called /dev/zramX (X = 0, 1, ...). + Pages written to these disks are compressed and stored in memory + itself. These disks allow very fast I/O and compression provides + good amounts of memory savings. + + It has several use cases, for example: /tmp storage, use as swap + disks and maybe many more. + + See zram.txt for more information. + Project home: <https://compcache.googlecode.com/> + +config ZRAM_DEBUG + bool "Compressed RAM block device debug support" + depends on ZRAM + default n + help + This option adds additional debugging code to the compressed + RAM block device driver.
drivers/block/zram/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +zram-y := zram_drv.o + +obj-$(CONFIG_ZRAM) += zram.o
drivers/block/zram/zram_drv.c new file +994 -0
994 lines not on this page · raw message
drivers/block/zram/zram_drv.h new file +124 -0
124 lines not on this page · raw message
drivers/staging/Kconfig +0 -2
@@ -76,8 +76,6 @@ source "drivers/staging/sep/Kconfig" source "drivers/staging/iio/Kconfig" -source "drivers/staging/zram/Kconfig" - source "drivers/staging/wlags49_h2/Kconfig" source "drivers/staging/wlags49_h25/Kconfig"
drivers/staging/Makefile +0 -1
@@ -32,7 +32,6 @@ obj-$(CONFIG_VT6656) += vt6656/ obj-$(CONFIG_VME_BUS) += vme/ obj-$(CONFIG_DX_SEP) += sep/ obj-$(CONFIG_IIO) += iio/ -obj-$(CONFIG_ZRAM) += zram/ obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ obj-$(CONFIG_FB_SM7XX) += sm7xxfb/
drivers/staging/zram/Kconfig deleted +0 -25
@@ -1,25 +0,0 @@ -config ZRAM - tristate "Compressed RAM block device support" - depends on BLOCK && SYSFS && ZSMALLOC - select LZO_COMPRESS - select LZO_DECOMPRESS - default n - help - Creates virtual block devices called /dev/zramX (X = 0, 1, ...). - Pages written to these disks are compressed and stored in memory - itself. These disks allow very fast I/O and compression provides - good amounts of memory savings. - - It has several use cases, for example: /tmp storage, use as swap - disks and maybe many more. - - See zram.txt for more information. - Project home: <https://compcache.googlecode.com/> - -config ZRAM_DEBUG - bool "Compressed RAM block device debug support" - depends on ZRAM - default n - help - This option adds additional debugging code to the compressed - RAM block device driver.
drivers/staging/zram/Makefile deleted +0 -3
@@ -1,3 +0,0 @@ -zram-y := zram_drv.o - -obj-$(CONFIG_ZRAM) += zram.o
drivers/staging/zram/zram.txt deleted +0 -77
77 lines not on this page · raw message
drivers/staging/zram/zram_drv.c deleted +0 -994
994 lines not on this page · raw message
drivers/staging/zram/zram_drv.h deleted +0 -124
124 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Minchan Kim
maintainerHello Greg,
Quoted 25 lines · Minchan Kim
Zram is a simple pseudo block device which can keep data on in-memory with compressed[1].
It have been used for many embedded system for several years One of significant usecase is in-memory swap device. Because NAND which is very popular on most embedded device is weak for frequent write without good wear-level and slow I/O hurts system's responsiblity so zram is really good choice to use memory efficiently.
In previous trial, there was some argument[2] that zram has similar goal with zswap so let's merge zram's functionality into zswap via adding pseudo block device in zswap but I and some
people(At least, Hugh and Rik)believe it's not a good idea. [2][3][4] and zswap might go writethrough model[5]. It makes clear difference zram and zswap.Zram itself is simple/well-designed/good abstraciton so it has clear
market(ex, Android, TV, ChromeOS, some Linux distro)which is never niche. :)Another zram-blk's usecase is following as.
The admin can use it as tmpfs so it could help small memory system. The tmpfs is never good solution for swapless embedded system.
Quoted 8 lines
Patch 1 adds new
Kconfigfor zram to use page table method instead of copy.Patch 2 adds more comment for zsmalloc.
Patch 3 moves zsmalloc under mm.
Patch 4 moves zram from driver/staging to driver/blocks, finally.
Patch 1(suggested by Andrew Morton) and 2(Just comment to make review easy) are prepartion for promotion so I hope it could be merged into your staging regardless of allowing promotion at the moment.
Thanks.
Signature · 8 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg Kroah-Hartman
maintainerQuoted 33 lines · Minchan Kim
Hello Greg,
Quoted 30 lines · Minchan Kim
Zram is a simple pseudo block device which can keep data on in-memory with compressed[1].
It have been used for many embedded system for several years One of significant usecase is in-memory swap device. Because NAND which is very popular on most embedded device is weak for frequent write without good wear-level and slow I/O hurts system's responsiblity so zram is really good choice to use memory efficiently.
In previous trial, there was some argument[2] that zram has similar goal with zswap so let's merge zram's functionality into zswap via adding pseudo block device in zswap but I and some
people(At least, Hugh and Rik)believe it's not a good idea. [2][3][4] and zswap might go writethrough model[5]. It makes clear difference zram and zswap.Zram itself is simple/well-designed/good abstraciton so it has clear
market(ex, Android, TV, ChromeOS, some Linux distro)which is never niche. :)Another zram-blk's usecase is following as.
The admin can use it as tmpfs so it could help small memory system. The tmpfs is never good solution for swapless embedded system.Patch 1 adds new
Kconfigfor zram to use page table method instead of copy.Patch 2 adds more comment for zsmalloc.
Quoted 7 lines
Quoted 3 lines
Patch 3 moves zsmalloc under mm.
Patch 4 moves zram from driver/staging to driver/blocks, finally.
Patch 1(suggested by Andrew Morton) and 2(Just comment to make review easy) are prepartion for promotion so I hope it could be merged into your staging regardless of allowing promotion at the moment.
Sure, I'll be glad to do so, thanks for letting me know.
greg k-h