Commit | Line | Data |
---|---|---|
00ac9ba0 NG |
1 | zram: Compressed RAM based block devices |
2 | ---------------------------------------- | |
47f9afb3 NG |
3 | |
4 | Project home: http://compcache.googlecode.com/ | |
5 | ||
6 | * Introduction | |
7 | ||
9b9913d8 NG |
8 | The zram module creates RAM based block devices named /dev/zram<id> |
9 | (<id> = 0, 1, ...). Pages written to these disks are compressed and stored | |
10 | in memory itself. These disks allow very fast I/O and compression provides | |
11 | good amounts of memory savings. Some of the usecases include /tmp storage, | |
12 | use as swap disks, various caches under /var and maybe many more :) | |
47f9afb3 | 13 | |
9b9913d8 NG |
14 | Statistics for individual zram devices are exported through sysfs nodes at |
15 | /sys/block/zram<id>/ | |
47f9afb3 NG |
16 | |
17 | * Usage | |
18 | ||
00ac9ba0 | 19 | Following shows a typical sequence of steps for using zram. |
47f9afb3 | 20 | |
9b9913d8 | 21 | 1) Load Module: |
00ac9ba0 | 22 | modprobe zram num_devices=4 |
9b9913d8 | 23 | This creates 4 devices: /dev/zram{0,1,2,3} |
47f9afb3 NG |
24 | (num_devices parameter is optional. Default: 1) |
25 | ||
9b9913d8 NG |
26 | 2) Set Disksize (Optional): |
27 | Set disk size by writing the value to sysfs node 'disksize' | |
28 | (in bytes). If disksize is not given, default value of 25% | |
29 | of RAM is used. | |
30 | ||
31 | # Initialize /dev/zram0 with 50MB disksize | |
32 | echo $((50*1024*1024)) > /sys/block/zram0/disksize | |
47f9afb3 | 33 | |
9b9913d8 NG |
34 | NOTE: disksize cannot be changed if the disk contains any |
35 | data. So, for such a disk, you need to issue 'reset' (see below) | |
36 | before you can change its disksize. | |
47f9afb3 NG |
37 | |
38 | 3) Activate: | |
00ac9ba0 NG |
39 | mkswap /dev/zram0 |
40 | swapon /dev/zram0 | |
41 | ||
42 | mkfs.ext4 /dev/zram1 | |
43 | mount /dev/zram1 /tmp | |
47f9afb3 NG |
44 | |
45 | 4) Stats: | |
9b9913d8 NG |
46 | Per-device statistics are exported as various nodes under |
47 | /sys/block/zram<id>/ | |
48 | disksize | |
49 | num_reads | |
50 | num_writes | |
51 | invalid_io | |
52 | notify_free | |
53 | discard | |
54 | zero_pages | |
55 | orig_data_size | |
56 | compr_data_size | |
57 | mem_used_total | |
47f9afb3 NG |
58 | |
59 | 5) Deactivate: | |
00ac9ba0 NG |
60 | swapoff /dev/zram0 |
61 | umount /dev/zram1 | |
47f9afb3 NG |
62 | |
63 | 6) Reset: | |
9b9913d8 NG |
64 | Write any positive value to 'reset' sysfs node |
65 | echo 1 > /sys/block/zram0/reset | |
66 | echo 1 > /sys/block/zram1/reset | |
67 | ||
68 | (This frees all the memory allocated for the given device). | |
47f9afb3 NG |
69 | |
70 | ||
71 | Please report any problems at: | |
72 | - Mailing list: linux-mm-cc at laptop dot org | |
73 | - Issue tracker: http://code.google.com/p/compcache/issues/list | |
74 | ||
75 | Nitin Gupta | |
76 | ngupta@vflare.org |