[LTP] [PATCH v4 2/4] zram/zram_lib.sh: adapt the situation that zram device is being used

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Mon Dec 20 03:58:49 CET 2021


Hi Petr
> Hi Xu,
>
>>>> If zram-generator package is installed and works, then we can not remove zram module
>>>> because zram swap is being used. This case needs a clean zram environment, change this
>>>> test by using hot_add/hot_remove interface[1]. So even zram device is being used, we
>>>> still can add zram device and remove them in cleanup.
>
>>> BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic
>>> device add/remove functionality")). Hopefully anybody still supporting older
>>> kernels is using old LTP for it.
>> Oh, I don't realize it before. I tested it on centos7 then I think this
>> control interface maybe introduced long time ago.
>
>> To be honst, I don't want to make this case more complex. How about
>> adding  /sys/class/zram-control check after load zram module. If not,
>> just report  case needs to use hot_add/hot_remove interface .
>
> Would it work something like this?
I don't want to use kernel version check because the hot_add/hot_remove 
interface is easy to backport. I will send a v5
1) new kernel and not load zram kernel module, then modprobe and rmmod 
is enough, doesn't need to use hot_add/hot_remove
2) new kernel and load zram kernel module or built in kernel, use 
hot_add/hot_remove
3) old kernel and can be modprobe and rmmod, work as 1)
4)old kernel but is being used or built in kernel, then skip this case 
like patch v3 does

Best Regards
Yang Xu
>
> ZRAM_SYSCTL_KERNEL_VERSION="4.2"
> ...
> zram_cleanup()
> {
> ...
> 	if tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION; then
> 		for i in $(seq $dev_start $dev_end); do
> 			echo $i>  /sys/class/zram-control/hot_remove
> 		done
> 	fi
>
> zram_load()
> {
> ...
> 	if [ ! -d "/sys/class/zram-control" ]; then
> 		modprobe zram num_devices=$dev_num
> 		module_load=1
> 		dev_start=0
> 		dev_end=$(($dev_num - 1))
> 		tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created"
> 		return
> 	fi
>
> 	tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION&&  \
> 		tst_brk TCONF "test requires kernel $ZRAM_SYSCTL_KERNEL_VERSION+"
>
> 	dev_start=$(ls /dev/zram* | wc -w)
> 	dev_end=$(($dev_start + $dev_num - 1))
>
> 	for i in $(seq  $dev_start $dev_end); do
> 		cat /sys/class/zram-control/hot_add>  /dev/null
> 	done
>
> Kind regards,
> Petr


More information about the ltp mailing list