zram: factor out single stream compression
[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
0231c403
MK
242) Set Disksize
25 Set disk size by writing the value to sysfs node 'disksize'.
26 The value can be either in bytes or you can use mem suffixes.
27 Examples:
28 # Initialize /dev/zram0 with 50MB disksize
29 echo $((50*1024*1024)) > /sys/block/zram0/disksize
30
31 # Using mem suffixes
32 echo 256K > /sys/block/zram0/disksize
33 echo 512M > /sys/block/zram0/disksize
34 echo 1G > /sys/block/zram0/disksize
47f9afb3 35
e64cd51d
SS
36Note:
37There is little point creating a zram of greater than twice the size of memory
38since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the
39size of the disk when not in use so a huge zram is wasteful.
40
47f9afb3 413) Activate:
00ac9ba0
NG
42 mkswap /dev/zram0
43 swapon /dev/zram0
44
45 mkfs.ext4 /dev/zram1
46 mount /dev/zram1 /tmp
47f9afb3
NG
47
484) Stats:
9b9913d8
NG
49 Per-device statistics are exported as various nodes under
50 /sys/block/zram<id>/
51 disksize
52 num_reads
53 num_writes
8dd1d324
SS
54 failed_reads
55 failed_writes
9b9913d8
NG
56 invalid_io
57 notify_free
9b9913d8
NG
58 zero_pages
59 orig_data_size
60 compr_data_size
61 mem_used_total
47f9afb3
NG
62
635) Deactivate:
00ac9ba0
NG
64 swapoff /dev/zram0
65 umount /dev/zram1
47f9afb3
NG
66
676) Reset:
9b9913d8
NG
68 Write any positive value to 'reset' sysfs node
69 echo 1 > /sys/block/zram0/reset
70 echo 1 > /sys/block/zram1/reset
71
0231c403
MK
72 This frees all the memory allocated for the given device and
73 resets the disksize to zero. You must set the disksize again
74 before reusing the device.
47f9afb3 75
47f9afb3
NG
76Nitin Gupta
77ngupta@vflare.org
This page took 0.351036 seconds and 5 git commands to generate.