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 | ||
0231c403 MK |
24 | 2) 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 NG |
35 | |
36 | 3) Activate: | |
00ac9ba0 NG |
37 | mkswap /dev/zram0 |
38 | swapon /dev/zram0 | |
39 | ||
40 | mkfs.ext4 /dev/zram1 | |
41 | mount /dev/zram1 /tmp | |
47f9afb3 NG |
42 | |
43 | 4) Stats: | |
9b9913d8 NG |
44 | Per-device statistics are exported as various nodes under |
45 | /sys/block/zram<id>/ | |
46 | disksize | |
47 | num_reads | |
48 | num_writes | |
49 | invalid_io | |
50 | notify_free | |
51 | discard | |
52 | zero_pages | |
53 | orig_data_size | |
54 | compr_data_size | |
55 | mem_used_total | |
47f9afb3 NG |
56 | |
57 | 5) Deactivate: | |
00ac9ba0 NG |
58 | swapoff /dev/zram0 |
59 | umount /dev/zram1 | |
47f9afb3 NG |
60 | |
61 | 6) Reset: | |
9b9913d8 NG |
62 | Write any positive value to 'reset' sysfs node |
63 | echo 1 > /sys/block/zram0/reset | |
64 | echo 1 > /sys/block/zram1/reset | |
65 | ||
0231c403 MK |
66 | This frees all the memory allocated for the given device and |
67 | resets the disksize to zero. You must set the disksize again | |
68 | before reusing the device. | |
47f9afb3 | 69 | |
47f9afb3 NG |
70 | Nitin Gupta |
71 | ngupta@vflare.org |