blob: 765d790ae83102bc11d2770cd01a1b6501c2fe8e [file] [log] [blame]
Nitin Gupta00ac9ba2010-06-01 13:31:26 +05301zram: Compressed RAM based block devices
2----------------------------------------
Nitin Gupta47f9afb2009-09-22 10:26:54 +05303
4Project home: http://compcache.googlecode.com/
5
6* Introduction
7
Nitin Gupta9b9913d2010-08-09 22:56:55 +05308The zram module creates RAM based block devices named /dev/zram<id>
9(<id> = 0, 1, ...). Pages written to these disks are compressed and stored
10in memory itself. These disks allow very fast I/O and compression provides
11good amounts of memory savings. Some of the usecases include /tmp storage,
12use as swap disks, various caches under /var and maybe many more :)
Nitin Gupta47f9afb2009-09-22 10:26:54 +053013
Nitin Gupta9b9913d2010-08-09 22:56:55 +053014Statistics for individual zram devices are exported through sysfs nodes at
15/sys/block/zram<id>/
Nitin Gupta47f9afb2009-09-22 10:26:54 +053016
17* Usage
18
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053019Following shows a typical sequence of steps for using zram.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053020
Nitin Gupta9b9913d2010-08-09 22:56:55 +0530211) Load Module:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053022 modprobe zram num_devices=4
Nitin Gupta9b9913d2010-08-09 22:56:55 +053023 This creates 4 devices: /dev/zram{0,1,2,3}
Nitin Gupta47f9afb2009-09-22 10:26:54 +053024 (num_devices parameter is optional. Default: 1)
25
Minchan Kim0231c402013-01-30 11:41:40 +0900262) Set Disksize
27 Set disk size by writing the value to sysfs node 'disksize'.
28 The value can be either in bytes or you can use mem suffixes.
29 Examples:
30 # Initialize /dev/zram0 with 50MB disksize
31 echo $((50*1024*1024)) > /sys/block/zram0/disksize
Nitin Gupta47f9afb2009-09-22 10:26:54 +053032
Minchan Kim0231c402013-01-30 11:41:40 +090033 # Using mem suffixes
34 echo 256K > /sys/block/zram0/disksize
35 echo 512M > /sys/block/zram0/disksize
36 echo 1G > /sys/block/zram0/disksize
Nitin Gupta47f9afb2009-09-22 10:26:54 +053037
383) Activate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053039 mkswap /dev/zram0
40 swapon /dev/zram0
41
42 mkfs.ext4 /dev/zram1
43 mount /dev/zram1 /tmp
Nitin Gupta47f9afb2009-09-22 10:26:54 +053044
454) Stats:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053046 Per-device statistics are exported as various nodes under
47 /sys/block/zram<id>/
48 disksize
49 num_reads
50 num_writes
51 invalid_io
52 notify_free
53 discard
54 zero_pages
55 orig_data_size
56 compr_data_size
57 mem_used_total
Nitin Gupta47f9afb2009-09-22 10:26:54 +053058
595) Deactivate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053060 swapoff /dev/zram0
61 umount /dev/zram1
Nitin Gupta47f9afb2009-09-22 10:26:54 +053062
636) Reset:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053064 Write any positive value to 'reset' sysfs node
65 echo 1 > /sys/block/zram0/reset
66 echo 1 > /sys/block/zram1/reset
67
Minchan Kim0231c402013-01-30 11:41:40 +090068 This frees all the memory allocated for the given device and
69 resets the disksize to zero. You must set the disksize again
70 before reusing the device.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053071
72Please report any problems at:
73 - Mailing list: linux-mm-cc at laptop dot org
74 - Issue tracker: http://code.google.com/p/compcache/issues/list
75
76Nitin Gupta
77ngupta@vflare.org