blob: aadfe60391b74643150b9a911f9fde8da8746abe [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
Nitin Gupta47f9afb2009-09-22 10:26:54 +05304* Introduction
5
Nitin Gupta9b9913d2010-08-09 22:56:55 +05306The zram module creates RAM based block devices named /dev/zram<id>
7(<id> = 0, 1, ...). Pages written to these disks are compressed and stored
8in memory itself. These disks allow very fast I/O and compression provides
9good amounts of memory savings. Some of the usecases include /tmp storage,
10use as swap disks, various caches under /var and maybe many more :)
Nitin Gupta47f9afb2009-09-22 10:26:54 +053011
Nitin Gupta9b9913d2010-08-09 22:56:55 +053012Statistics for individual zram devices are exported through sysfs nodes at
13/sys/block/zram<id>/
Nitin Gupta47f9afb2009-09-22 10:26:54 +053014
15* Usage
16
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053017Following shows a typical sequence of steps for using zram.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053018
Nitin Gupta9b9913d2010-08-09 22:56:55 +0530191) Load Module:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053020 modprobe zram num_devices=4
Nitin Gupta9b9913d2010-08-09 22:56:55 +053021 This creates 4 devices: /dev/zram{0,1,2,3}
Nitin Gupta47f9afb2009-09-22 10:26:54 +053022 (num_devices parameter is optional. Default: 1)
23
Sergey Senozhatskybeca3ec2014-04-07 15:38:14 -0700242) Set max number of compression streams
25 Compression backend may use up to max_comp_streams compression streams,
26 thus allowing up to max_comp_streams concurrent compression operations.
27 By default, compression backend uses single compression stream.
28
29 Examples:
30 #show max compression streams number
31 cat /sys/block/zram0/max_comp_streams
32
33 #set max compression streams number to 3
34 echo 3 > /sys/block/zram0/max_comp_streams
35
36Note:
37In order to enable compression backend's multi stream support max_comp_streams
38must be initially set to desired concurrency level before ZRAM device
39initialisation. Once the device initialised as a single stream compression
40backend (max_comp_streams equals to 0) changing the value of max_comp_streams
41will not take any effect, because single stream compression backend implemented
42as a special case and does not support dynamic max_comp_streams. Only multi
43stream backend supports dynamic max_comp_streams adjustment.
44
453) Set Disksize
Minchan Kim0231c402013-01-30 11:41:40 +090046 Set disk size by writing the value to sysfs node 'disksize'.
47 The value can be either in bytes or you can use mem suffixes.
48 Examples:
49 # Initialize /dev/zram0 with 50MB disksize
50 echo $((50*1024*1024)) > /sys/block/zram0/disksize
Nitin Gupta47f9afb2009-09-22 10:26:54 +053051
Minchan Kim0231c402013-01-30 11:41:40 +090052 # Using mem suffixes
53 echo 256K > /sys/block/zram0/disksize
54 echo 512M > /sys/block/zram0/disksize
55 echo 1G > /sys/block/zram0/disksize
Nitin Gupta47f9afb2009-09-22 10:26:54 +053056
Sergey Senozhatskye64cd512014-04-07 15:38:07 -070057Note:
58There is little point creating a zram of greater than twice the size of memory
59since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the
60size of the disk when not in use so a huge zram is wasteful.
61
Sergey Senozhatskybeca3ec2014-04-07 15:38:14 -0700624) Activate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053063 mkswap /dev/zram0
64 swapon /dev/zram0
65
66 mkfs.ext4 /dev/zram1
67 mount /dev/zram1 /tmp
Nitin Gupta47f9afb2009-09-22 10:26:54 +053068
Sergey Senozhatskybeca3ec2014-04-07 15:38:14 -0700695) Stats:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053070 Per-device statistics are exported as various nodes under
71 /sys/block/zram<id>/
72 disksize
73 num_reads
74 num_writes
Sergey Senozhatsky8dd1d322014-04-07 15:38:08 -070075 failed_reads
76 failed_writes
Nitin Gupta9b9913d2010-08-09 22:56:55 +053077 invalid_io
78 notify_free
Nitin Gupta9b9913d2010-08-09 22:56:55 +053079 zero_pages
80 orig_data_size
81 compr_data_size
82 mem_used_total
Nitin Gupta47f9afb2009-09-22 10:26:54 +053083
Sergey Senozhatskybeca3ec2014-04-07 15:38:14 -0700846) Deactivate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053085 swapoff /dev/zram0
86 umount /dev/zram1
Nitin Gupta47f9afb2009-09-22 10:26:54 +053087
Sergey Senozhatskybeca3ec2014-04-07 15:38:14 -0700887) Reset:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053089 Write any positive value to 'reset' sysfs node
90 echo 1 > /sys/block/zram0/reset
91 echo 1 > /sys/block/zram1/reset
92
Minchan Kim0231c402013-01-30 11:41:40 +090093 This frees all the memory allocated for the given device and
94 resets the disksize to zero. You must set the disksize again
95 before reusing the device.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053096
Nitin Gupta47f9afb2009-09-22 10:26:54 +053097Nitin Gupta
98ngupta@vflare.org