Merge tag 'iommu-fixes-v3.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / Documentation / blockdev / zram.txt
CommitLineData
00ac9ba0
NG
1zram: Compressed RAM based block devices
2----------------------------------------
47f9afb3 3
47f9afb3
NG
4* Introduction
5
9b9913d8
NG
6The 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 :)
47f9afb3 11
9b9913d8
NG
12Statistics for individual zram devices are exported through sysfs nodes at
13/sys/block/zram<id>/
47f9afb3
NG
14
15* Usage
16
00ac9ba0 17Following shows a typical sequence of steps for using zram.
47f9afb3 18
9b9913d8 191) Load Module:
00ac9ba0 20 modprobe zram num_devices=4
9b9913d8 21 This creates 4 devices: /dev/zram{0,1,2,3}
47f9afb3
NG
22 (num_devices parameter is optional. Default: 1)
23
beca3ec7
SS
242) 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
60a726e3
MK
40backend (max_comp_streams equals to 1), you will see error if you try to change
41the value of max_comp_streams because single stream compression backend
42implemented as a special case by lock overhead issue and does not support
43dynamic max_comp_streams. Only multi stream backend supports dynamic
44max_comp_streams adjustment.
beca3ec7 45
e46b8a03
SS
463) Select compression algorithm
47 Using comp_algorithm device attribute one can see available and
48 currently selected (shown in square brackets) compression algortithms,
49 change selected compression algorithm (once the device is initialised
50 there is no way to change compression algorithm).
51
52 Examples:
53 #show supported compression algorithms
54 cat /sys/block/zram0/comp_algorithm
55 lzo [lz4]
56
57 #select lzo compression algorithm
58 echo lzo > /sys/block/zram0/comp_algorithm
59
604) Set Disksize
0231c403
MK
61 Set disk size by writing the value to sysfs node 'disksize'.
62 The value can be either in bytes or you can use mem suffixes.
63 Examples:
64 # Initialize /dev/zram0 with 50MB disksize
65 echo $((50*1024*1024)) > /sys/block/zram0/disksize
66
67 # Using mem suffixes
68 echo 256K > /sys/block/zram0/disksize
69 echo 512M > /sys/block/zram0/disksize
70 echo 1G > /sys/block/zram0/disksize
47f9afb3 71
e64cd51d
SS
72Note:
73There is little point creating a zram of greater than twice the size of memory
74since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the
75size of the disk when not in use so a huge zram is wasteful.
76
e46b8a03 775) Activate:
00ac9ba0
NG
78 mkswap /dev/zram0
79 swapon /dev/zram0
80
81 mkfs.ext4 /dev/zram1
82 mount /dev/zram1 /tmp
47f9afb3 83
e46b8a03 846) Stats:
9b9913d8
NG
85 Per-device statistics are exported as various nodes under
86 /sys/block/zram<id>/
87 disksize
88 num_reads
89 num_writes
8dd1d324
SS
90 failed_reads
91 failed_writes
9b9913d8
NG
92 invalid_io
93 notify_free
9b9913d8
NG
94 zero_pages
95 orig_data_size
96 compr_data_size
97 mem_used_total
47f9afb3 98
e46b8a03 997) Deactivate:
00ac9ba0
NG
100 swapoff /dev/zram0
101 umount /dev/zram1
47f9afb3 102
e46b8a03 1038) Reset:
9b9913d8
NG
104 Write any positive value to 'reset' sysfs node
105 echo 1 > /sys/block/zram0/reset
106 echo 1 > /sys/block/zram1/reset
107
0231c403
MK
108 This frees all the memory allocated for the given device and
109 resets the disksize to zero. You must set the disksize again
110 before reusing the device.
47f9afb3 111
47f9afb3
NG
112Nitin Gupta
113ngupta@vflare.org
This page took 0.33517 seconds and 5 git commands to generate.