Test zram at kernel 3.10 4.12
Use ltp to test zram
测试环境:
#uname -r 3.10.0-327.ali2010.rc6.alios7.x86_64
- 没有指定zram algorithm(没有设置), 因为kernel v3.15开始才支持选择compression algorithms:
cat /sys/block/zram0/comp_algorithm
。比如:select lzo compression algorithm:echo lzo > /sys/block/zram0/comp_algorithm
测试原理:
- 创建4个zram虚拟磁盘 zram0 zram1 zram2 zram3
- 分别创建4个文件系统,分别大小如下
- /dev/zram0: ext4 100M
- /dev/zram1: ext4 100M
- /dev/zram2: ext4 100M
- /dev/zram3: ext4 100M
- 分别挂载/dev/zram0 /dev/zram1 /dev/zram2 /dev/zram3 到四个目录
- 通过dd工具写四个目录
- 利用free命令获得dd塞满四个目录前后,zram一共使用多少内存
used_mem=$(($mem_free0 - $mem_free1))
total_size=400M
- 压缩比 =
$total_size / $used_mem
测试结果:
前提条件: 关闭所有测试期间可能使用,释放内存的干扰因素
测试结果压缩比:1.41:1
#sh zram01.sh
TINFO create '4' zram device(s)
TPASS test succeeded
./zram_lib.sh: line 60: tst_tmpdir: command not found
TINFO set disk size to zram device(s)
TINFO /sys/block/zram0/disksize = '50M' (1/4)
TINFO /sys/block/zram1/disksize = '50M' (2/4)
TINFO /sys/block/zram2/disksize = '50M' (3/4)
TINFO /sys/block/zram3/disksize = '50M' (4/4)
TPASS test succeeded
./zram_lib.sh: line 202: tst_check_cmds: command not found
TINFO make ext4 filesystem on /dev/zram0
TINFO make ext4 filesystem on /dev/zram1
TINFO make ext4 filesystem on /dev/zram2
TINFO make ext4 filesystem on /dev/zram3
TPASS zram_makefs succeeded
TINFO mount /dev/zram0
mkdir: cannot create directory ‘zram0’: File exists
TINFO mount /dev/zram1
mkdir: cannot create directory ‘zram1’: File exists
TINFO mount /dev/zram2
mkdir: cannot create directory ‘zram2’: File exists
TINFO mount /dev/zram3
mkdir: cannot create directory ‘zram3’: File exists
TPASS mount of zram device(s) succeeded
TINFO fill zram0...
TINFO zram0 can be filled with '44416' KB
TINFO fill zram1...
TINFO zram1 can be filled with '44416' KB
TINFO fill zram2...
TINFO zram2 can be filled with '44404' KB
TINFO fill zram3...
TINFO zram3 can be filled with '44416' KB
TINFO zram used 126M, zram disk sizes 180M
TPASS compression ratio: 1.42:1
TINFO zram cleanup
同样方式,改变一些条件后的测试结果
kernel version | zram数量 | 文件系统 | zram大小 | 测试结果:压缩比 |
---|---|---|---|---|
物理机 3.10 | 4 | ext4 ext4 ext4 ext4 | 50M 50M 50M 50M | 1.12:1-1.40:1 |
物理机 3.10 | 4 | ext4 ext4 ext4 ext4 | 100M 100M 100M 100M | 1.10:1 |
Aliyun VM 4.12 | 4 | ext4 ext4 ext4 ext4 | 50M 50M 50M 50M | 1.00:1 |
Aliyun VM 4.12 | 4 | ext4 ext4 ext4 ext4 | 100M 100M 100M 100M | 1.07:1 |
结论:
通过这种方式测试zram的压缩效果并不是很明显。在kernel 3.10 和kernel 4.12差距也并不多。
测试环境:aliyun ECS VM + rhel7.3 + kernel 4.12
kernel version|zram数量|文件系统|zram大小|测试结果:压缩比|
----|----|---|---|---|---
aliyun ECS VM + el7.3 +kernel 4.12|4|ext4 ext4 ext4 ext4|100M 100M 100M 100M|1.07:1
[root@izrj9hbvvadz319i4e695tz zram]# uname -r
4.12.7-1.el7.elrepo.x86_64
[root@izrj9hbvvadz319i4e695tz ~]# cat /sys/block/zram0/comp_algorithm
[lzo] lz4 deflate lz4hc 842
[root@izrj9hbvvadz319i4e695tz zram]# sh zram01.sh
TINFO create '4' zram device(s)
TPASS test succeeded
./zram_lib.sh:行60: tst_tmpdir: 未找到命令
./zram_lib.sh:行65: tst_kvcmp: 未找到命令
TINFO set max_comp_streams to zram device(s)
TINFO /sys/block/zram0/max_comp_streams = '2' (1/4)
TFAIL can't set max_streams '3', get
TINFO /sys/block/zram1/max_comp_streams = '2' (2/4)
TFAIL can't set max_streams '5', get
TINFO /sys/block/zram2/max_comp_streams = '2' (3/4)
TFAIL can't set max_streams '8', get
TINFO /sys/block/zram3/max_comp_streams = '2' (4/4)
TPASS test succeeded
./zram_lib.sh:行92: tst_kvcmp: 未找到命令
TINFO test that we can set compression algorithm
TINFO supported algs: [lzo] lz4 deflate lz4hc 842
TINFO /sys/block/zram0/comp_algorithm = 'lzo' (1/4)
TINFO /sys/block/zram1/comp_algorithm = 'lzo' (2/4)
TINFO /sys/block/zram2/comp_algorithm = 'lzo' (3/4)
TINFO /sys/block/zram3/comp_algorithm = 'lzo' (4/4)
TPASS test succeeded
TINFO set disk size to zram device(s)
TINFO /sys/block/zram0/disksize = '100M' (1/4)
TINFO /sys/block/zram1/disksize = '100M' (2/4)
TINFO /sys/block/zram2/disksize = '100M' (3/4)
TINFO /sys/block/zram3/disksize = '100M' (4/4)
TPASS test succeeded
./zram_lib.sh:行133: tst_kvcmp: 未找到命令
TINFO set memory limit to zram device(s)
TINFO /sys/block/zram0/mem_limit = '100M' (1/4)
TINFO /sys/block/zram1/mem_limit = '100M' (2/4)
TINFO /sys/block/zram2/mem_limit = '100M' (3/4)
TINFO /sys/block/zram3/mem_limit = '100M' (4/4)
TPASS test succeeded
./zram_lib.sh:行202: tst_check_cmds: 未找到命令
TINFO make ext3 filesystem on /dev/zram0
TINFO make ext4 filesystem on /dev/zram1
TINFO make xfs filesystem on /dev/zram2
TINFO make btrfs filesystem on /dev/zram3
TPASS zram_makefs succeeded
TINFO mount /dev/zram0
mkdir: 无法创建目录"zram0": 文件已存在
TINFO mount /dev/zram1
mkdir: 无法创建目录"zram1": 文件已存在
TINFO mount /dev/zram2
mkdir: 无法创建目录"zram2": 文件已存在
TINFO mount /dev/zram3
mkdir: 无法创建目录"zram3": 文件已存在
TPASS mount of zram device(s) succeeded
zram01.sh:行58: tst_check_cmds: 未找到命令
TINFO fill zram0...
TINFO zram0 can be filled with '94936' KB
TINFO fill zram1...
TINFO zram1 can be filled with '92968' KB
TINFO fill zram2...
TINFO zram2 can be filled with '90568' KB
TINFO fill zram3...
TINFO zram3 can be filled with '73657' KB
TINFO zram used 355M, zram disk sizes 380M
TPASS compression ratio: 1.07:1
TINFO zram cleanup
muahao@aliyun.com