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@oracle.com> 22 23TCID="zram01" 24TST_TOTAL=8 25 26. test.sh 27. zram_lib.sh 28 29# Test will create the following number of zram devices: 30dev_num=4 31# This is a list of parameters for zram devices. 32# Number of items must be equal to 'dev_num' parameter. 33zram_max_streams="2 3 5 8" 34 35# The zram sysfs node 'disksize' value can be either in bytes, 36# or you can use mem suffixes. But in some old kernels, mem 37# suffixes are not supported, for example, in RHEL6.6GA's kernel 38# layer, it uses strict_strtoull() to parse disksize which does 39# not support mem suffixes, in some newer kernels, they use 40# memparse() which supports mem suffixes. So here we just use 41# bytes to make sure everything works correctly. 42zram_sizes="26214400 26214400 26214400 41943040" # 25MB, 40MB for btrfs 43zram_mem_limits="25M 25M 25M 40M" 44zram_filesystems="ext3 ext4 xfs btrfs" 45zram_algs="lzo lzo lzo lzo" 46 47TST_CLEANUP="zram_cleanup" 48 49zram_fill_fs() 50{ 51 tst_check_cmds dd free awk 52 local mem_free0=$(free -m | awk 'NR==2 {print $4}') 53 54 for i in $(seq 0 $(($dev_num - 1))); do 55 tst_resm TINFO "fill zram$i..." 56 local b=0 57 while true; do 58 dd conv=notrunc if=/dev/zero of=zram${i}/file \ 59 oflag=append count=1 bs=1024 status=none \ 60 > /dev/null 2>&1 || break 61 b=$(($b + 1)) 62 done 63 tst_resm TINFO "zram$i can be filled with '$b' KB" 64 done 65 66 local mem_free1=$(free -m | awk 'NR==2 {print $4}') 67 local used_mem=$(($mem_free0 - $mem_free1)) 68 69 local total_size=0 70 for sm in $zram_sizes; do 71 local s=$(echo $sm | sed 's/M//') 72 total_size=$(($total_size + $s)) 73 done 74 75 tst_resm TINFO "zram used ${used_mem}M, zram disk sizes ${total_size}M" 76 77 local v=$((100 * $total_size / $used_mem)) 78 79 if [ "$v" -lt 100 ]; then 80 tst_resm TFAIL "compression ratio: 0.$v:1" 81 return 82 fi 83 84 tst_resm TPASS "compression ratio: $(echo "scale=2; $v / 100 " | bc):1" 85} 86 87zram_load 88zram_max_streams 89zram_compress_alg 90zram_set_disksizes 91zram_set_memlimit 92zram_makefs 93zram_mount 94 95zram_fill_fs 96 97tst_exit 98