blob: 393541be1ec0ef62fecbc5541de3f6648b71a993 [file] [log] [blame]
Nitin Gupta00ac9ba2010-06-01 13:31:26 +05301zram: Compressed RAM based block devices
2----------------------------------------
Nitin Gupta47f9afb2009-09-22 10:26:54 +05303
Nitin Gupta47f9afb2009-09-22 10:26:54 +05304* Introduction
5
Nitin Gupta9b9913d2010-08-09 22:56:55 +05306The 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 :)
Nitin Gupta47f9afb2009-09-22 10:26:54 +053011
Nitin Gupta9b9913d2010-08-09 22:56:55 +053012Statistics for individual zram devices are exported through sysfs nodes at
13/sys/block/zram<id>/
Nitin Gupta47f9afb2009-09-22 10:26:54 +053014
15* Usage
16
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053017Following shows a typical sequence of steps for using zram.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053018
Nitin Gupta9b9913d2010-08-09 22:56:55 +0530191) Load Module:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053020 modprobe zram num_devices=4
Nitin Gupta9b9913d2010-08-09 22:56:55 +053021 This creates 4 devices: /dev/zram{0,1,2,3}
Nitin Gupta47f9afb2009-09-22 10:26:54 +053022 (num_devices parameter is optional. Default: 1)
23
Minchan Kim0231c402013-01-30 11:41:40 +0900242) 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
Nitin Gupta47f9afb2009-09-22 10:26:54 +053030
Minchan Kim0231c402013-01-30 11:41:40 +090031 # Using mem suffixes
32 echo 256K > /sys/block/zram0/disksize
33 echo 512M > /sys/block/zram0/disksize
34 echo 1G > /sys/block/zram0/disksize
Nitin Gupta47f9afb2009-09-22 10:26:54 +053035
Sergey Senozhatskye64cd512014-04-07 15:38:07 -070036Note:
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
Nitin Gupta47f9afb2009-09-22 10:26:54 +0530413) Activate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053042 mkswap /dev/zram0
43 swapon /dev/zram0
44
45 mkfs.ext4 /dev/zram1
46 mount /dev/zram1 /tmp
Nitin Gupta47f9afb2009-09-22 10:26:54 +053047
484) Stats:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053049 Per-device statistics are exported as various nodes under
50 /sys/block/zram<id>/
51 disksize
52 num_reads
53 num_writes
54 invalid_io
55 notify_free
56 discard
57 zero_pages
58 orig_data_size
59 compr_data_size
60 mem_used_total
Nitin Gupta47f9afb2009-09-22 10:26:54 +053061
625) Deactivate:
Nitin Gupta00ac9ba2010-06-01 13:31:26 +053063 swapoff /dev/zram0
64 umount /dev/zram1
Nitin Gupta47f9afb2009-09-22 10:26:54 +053065
666) Reset:
Nitin Gupta9b9913d2010-08-09 22:56:55 +053067 Write any positive value to 'reset' sysfs node
68 echo 1 > /sys/block/zram0/reset
69 echo 1 > /sys/block/zram1/reset
70
Minchan Kim0231c402013-01-30 11:41:40 +090071 This frees all the memory allocated for the given device and
72 resets the disksize to zero. You must set the disksize again
73 before reusing the device.
Nitin Gupta47f9afb2009-09-22 10:26:54 +053074
Nitin Gupta47f9afb2009-09-22 10:26:54 +053075Nitin Gupta
76ngupta@vflare.org