f21fb798fe
zram: Compressed RAM based block devices ---------------------------------------- The zram module creates RAM based block devices named /dev/zram<id> (<id> = 0, 1, ...). Pages written to these disks are compressed and stored in memory itself. These disks allow very fast I/O and compression provides good amounts of memory savings. Some of the usecases include /tmp storage, use as swap disks, various caches under /var and maybe many more :) Statistics for individual zram devices are exported through sysfs nodes at /sys/block/zram<id>/ This patch is to validate the zram functionality. Test interacts with block device /dev/zram<id> and sysfs nodes /sys/block/zram<id>/ zram.sh: sanity check of CONFIG_ZRAM and to run zram01 and zram02 tests zram01.sh: creates general purpose ram disks with different filesystems zram02.sh: creates block device for swap zram_lib.sh: create library with initialization/cleanup functions README: ZRAM introduction and Kconfig required. Makefile: To run zram tests zram test output ----------------- ./zram.sh -------------------- running zram tests -------------------- /dev/zram0 device file found: OK set max_comp_streams to zram device(s) /sys/block/zram0/max_comp_streams = '2' (1/1) zram max streams: OK test that we can set compression algorithm supported algs: [lzo] lz4 /sys/block/zram0/comp_algorithm = 'lzo' (1/1) zram set compression algorithm: OK set disk size to zram device(s) /sys/block/zram0/disksize = '2097152' (1/1) zram set disksizes: OK set memory limit to zram device(s) /sys/block/zram0/mem_limit = '2M' (1/1) zram set memory limit: OK make ext4 filesystem on /dev/zram0 zram mkfs.ext4: OK mount /dev/zram0 zram mount of zram device(s): OK fill zram0... zram0 can be filled with '1932' KB zram used 3M, zram disk sizes 2097152M zram compression ratio: 699050.66:1: OK zram cleanup zram01 : [PASS] /dev/zram0 device file found: OK set max_comp_streams to zram device(s) /sys/block/zram0/max_comp_streams = '2' (1/1) zram max streams: OK set disk size to zram device(s) /sys/block/zram0/disksize = '1048576' (1/1) zram set disksizes: OK set memory limit to zram device(s) /sys/block/zram0/mem_limit = '1M' (1/1) zram set memory limit: OK make swap with zram device(s) done with /dev/zram0 zram making zram mkswap and swapon: OK zram swapoff: OK zram cleanup zram02 : [PASS] CC: Shuah Khan <shuahkh@osg.samsung.com> CC: Tyler Baker <tyler.baker@linaro.org> CC: Milosz Wasilewski <milosz.wasilewski@linaro.org> CC: Alexey Kodanev <alexey.kodanev@oracle.com> Signed-off-by: Naresh Kamboju <naresh.kamboju@linaro.org> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com> Reviewed-By: Tyler Baker <tyler.baker@linaro.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
99 lines
2.6 KiB
Bash
Executable File
99 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation; either version 2 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it would be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# Test creates several zram devices with different filesystems on them.
|
|
# It fills each device with zeros and checks that compression works.
|
|
#
|
|
# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
|
|
# Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
|
|
|
|
TCID="zram01"
|
|
ERR_CODE=0
|
|
|
|
. ./zram_lib.sh
|
|
|
|
# Test will create the following number of zram devices:
|
|
dev_num=1
|
|
# This is a list of parameters for zram devices.
|
|
# Number of items must be equal to 'dev_num' parameter.
|
|
zram_max_streams="2"
|
|
|
|
# The zram sysfs node 'disksize' value can be either in bytes,
|
|
# or you can use mem suffixes. But in some old kernels, mem
|
|
# suffixes are not supported, for example, in RHEL6.6GA's kernel
|
|
# layer, it uses strict_strtoull() to parse disksize which does
|
|
# not support mem suffixes, in some newer kernels, they use
|
|
# memparse() which supports mem suffixes. So here we just use
|
|
# bytes to make sure everything works correctly.
|
|
zram_sizes="2097152" # 2MB
|
|
zram_mem_limits="2M"
|
|
zram_filesystems="ext4"
|
|
zram_algs="lzo"
|
|
|
|
zram_fill_fs()
|
|
{
|
|
local mem_free0=$(free -m | awk 'NR==2 {print $4}')
|
|
|
|
for i in $(seq 0 $(($dev_num - 1))); do
|
|
echo "fill zram$i..."
|
|
local b=0
|
|
while [ true ]; do
|
|
dd conv=notrunc if=/dev/zero of=zram${i}/file \
|
|
oflag=append count=1 bs=1024 status=none \
|
|
> /dev/null 2>&1 || break
|
|
b=$(($b + 1))
|
|
done
|
|
echo "zram$i can be filled with '$b' KB"
|
|
done
|
|
|
|
local mem_free1=$(free -m | awk 'NR==2 {print $4}')
|
|
local used_mem=$(($mem_free0 - $mem_free1))
|
|
|
|
local total_size=0
|
|
for sm in $zram_sizes; do
|
|
local s=$(echo $sm | sed 's/M//')
|
|
total_size=$(($total_size + $s))
|
|
done
|
|
|
|
echo "zram used ${used_mem}M, zram disk sizes ${total_size}M"
|
|
|
|
local v=$((100 * $total_size / $used_mem))
|
|
|
|
if [ "$v" -lt 100 ]; then
|
|
echo "FAIL compression ratio: 0.$v:1"
|
|
ERR_CODE=-1
|
|
zram_cleanup
|
|
return
|
|
fi
|
|
|
|
echo "zram compression ratio: $(echo "scale=2; $v / 100 " | bc):1: OK"
|
|
}
|
|
|
|
zram_load
|
|
zram_max_streams
|
|
zram_compress_alg
|
|
zram_set_disksizes
|
|
zram_set_memlimit
|
|
zram_makefs
|
|
zram_mount
|
|
|
|
zram_fill_fs
|
|
zram_cleanup
|
|
zram_unload
|
|
|
|
if [ $ERR_CODE -ne 0 ]; then
|
|
echo "$TCID : [FAIL]"
|
|
else
|
|
echo "$TCID : [PASS]"
|
|
fi
|