1 #!/bin/sh 2 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 3 # 4 # This program is free software; you can redistribute it and/or 5 # modify it under the terms of the GNU General Public License as 6 # published by the Free Software Foundation; either version 2 of 7 # the License, or (at your option) any later version. 8 # 9 # This program is distributed in the hope that it would be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write the Free Software Foundation, 16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 # 18 # Test creates several zram devices with different filesystems on them. 19 # It fills each device with zeros and checks that compression works. 20 # 21 # Author: Alexey Kodanev <alexey.kodanev (at] oracle.com> 22 23 TCID="zram01" 24 TST_TOTAL=8 25 26 . test.sh 27 . zram_lib.sh 28 29 # Test will create the following number of zram devices: 30 dev_num=4 31 # This is a list of parameters for zram devices. 32 # Number of items must be equal to 'dev_num' parameter. 33 zram_max_streams="2 3 5 8" 34 35 FS_SIZE="402653184" 36 FS_TYPE="btrfs" 37 38 RAM_SIZE=$(awk '/MemTotal:/ {print $2}' /proc/meminfo) 39 if [ "$RAM_SIZE" -lt 1048576 ]; then 40 tst_res TINFO "Not enough space for Btrfs" 41 FS_SIZE="26214400" 42 FS_TYPE="ext2" 43 fi 44 45 # The zram sysfs node 'disksize' value can be either in bytes, 46 # or you can use mem suffixes. But in some old kernels, mem 47 # suffixes are not supported, for example, in RHEL6.6GA's kernel 48 # layer, it uses strict_strtoull() to parse disksize which does 49 # not support mem suffixes, in some newer kernels, they use 50 # memparse() which supports mem suffixes. So here we just use 51 # bytes to make sure everything works correctly. 52 zram_sizes="26214400 26214400 26214400 $FS_SIZE" 53 zram_mem_limits="25M 25M 25M $((FS_SIZE/1024/1024))M" 54 zram_filesystems="ext3 ext4 xfs $FS_TYPE" 55 zram_algs="lzo lzo lzo lzo" 56 57 TST_CLEANUP="zram_cleanup" 58 59 zram_fill_fs() 60 { 61 tst_check_cmds dd free awk 62 local mem_free0=$(free -m | awk 'NR==2 {print $4}') 63 64 for i in $(seq 0 $(($dev_num - 1))); do 65 tst_resm TINFO "fill zram$i..." 66 local b=0 67 while true; do 68 dd conv=notrunc if=/dev/zero of=zram${i}/file \ 69 oflag=append count=1 bs=1024 status=none \ 70 > /dev/null 2>&1 || break 71 b=$(($b + 1)) 72 done 73 tst_resm TINFO "zram$i can be filled with '$b' KB" 74 done 75 76 local mem_free1=$(free -m | awk 'NR==2 {print $4}') 77 local used_mem=$(($mem_free0 - $mem_free1)) 78 79 local total_size=0 80 for sm in $zram_sizes; do 81 local s=$(echo $sm | sed 's/M//') 82 total_size=$(($total_size + $s)) 83 done 84 85 tst_resm TINFO "zram used ${used_mem}M, zram disk sizes ${total_size}M" 86 87 local v=$((100 * $total_size / $used_mem)) 88 89 if [ "$v" -lt 100 ]; then 90 tst_resm TFAIL "compression ratio: 0.$v:1" 91 return 92 fi 93 94 tst_resm TPASS "compression ratio: $(echo "scale=2; $v / 100 " | bc):1" 95 } 96 97 zram_load 98 zram_max_streams 99 zram_compress_alg 100 zram_set_disksizes 101 zram_set_memlimit 102 zram_makefs 103 zram_mount 104 zram_fill_fs 105 106 tst_exit 107