]>
Commit | Line | Data |
---|---|---|
00ac9ba0 NG |
1 | zram: Compressed RAM based block devices |
2 | ---------------------------------------- | |
47f9afb3 | 3 | |
47f9afb3 NG |
4 | * Introduction |
5 | ||
9b9913d8 NG |
6 | The zram module creates RAM based block devices named /dev/zram<id> |
7 | (<id> = 0, 1, ...). Pages written to these disks are compressed and stored | |
8 | in memory itself. These disks allow very fast I/O and compression provides | |
9 | good amounts of memory savings. Some of the usecases include /tmp storage, | |
10 | use as swap disks, various caches under /var and maybe many more :) | |
47f9afb3 | 11 | |
9b9913d8 NG |
12 | Statistics for individual zram devices are exported through sysfs nodes at |
13 | /sys/block/zram<id>/ | |
47f9afb3 NG |
14 | |
15 | * Usage | |
16 | ||
00ac9ba0 | 17 | Following shows a typical sequence of steps for using zram. |
47f9afb3 | 18 | |
9b9913d8 | 19 | 1) 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 |
24 | 2) 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 | ||
36 | Note: | |
37 | In order to enable compression backend's multi stream support max_comp_streams | |
38 | must be initially set to desired concurrency level before ZRAM device | |
39 | initialisation. Once the device initialised as a single stream compression | |
40 | backend (max_comp_streams equals to 0) changing the value of max_comp_streams | |
41 | will not take any effect, because single stream compression backend implemented | |
42 | as a special case and does not support dynamic max_comp_streams. Only multi | |
43 | stream backend supports dynamic max_comp_streams adjustment. | |
44 | ||
45 | 3) Set Disksize | |
0231c403 MK |
46 | 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 | |
51 | ||
52 | # Using mem suffixes | |
53 | echo 256K > /sys/block/zram0/disksize | |
54 | echo 512M > /sys/block/zram0/disksize | |
55 | echo 1G > /sys/block/zram0/disksize | |
47f9afb3 | 56 | |
e64cd51d SS |
57 | Note: |
58 | There is little point creating a zram of greater than twice the size of memory | |
59 | since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the | |
60 | size of the disk when not in use so a huge zram is wasteful. | |
61 | ||
beca3ec7 | 62 | 4) Activate: |
00ac9ba0 NG |
63 | mkswap /dev/zram0 |
64 | swapon /dev/zram0 | |
65 | ||
66 | mkfs.ext4 /dev/zram1 | |
67 | mount /dev/zram1 /tmp | |
47f9afb3 | 68 | |
beca3ec7 | 69 | 5) Stats: |
9b9913d8 NG |
70 | Per-device statistics are exported as various nodes under |
71 | /sys/block/zram<id>/ | |
72 | disksize | |
73 | num_reads | |
74 | num_writes | |
8dd1d324 SS |
75 | failed_reads |
76 | failed_writes | |
9b9913d8 NG |
77 | invalid_io |
78 | notify_free | |
9b9913d8 NG |
79 | zero_pages |
80 | orig_data_size | |
81 | compr_data_size | |
82 | mem_used_total | |
47f9afb3 | 83 | |
beca3ec7 | 84 | 6) Deactivate: |
00ac9ba0 NG |
85 | swapoff /dev/zram0 |
86 | umount /dev/zram1 | |
47f9afb3 | 87 | |
beca3ec7 | 88 | 7) Reset: |
9b9913d8 NG |
89 | Write any positive value to 'reset' sysfs node |
90 | echo 1 > /sys/block/zram0/reset | |
91 | echo 1 > /sys/block/zram1/reset | |
92 | ||
0231c403 MK |
93 | 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. | |
47f9afb3 | 96 | |
47f9afb3 NG |
97 | Nitin Gupta |
98 | ngupta@vflare.org |