Skip to content

Commit 6100ff1

Browse files
committed
Added the madvise new zswap test
1 parent 3d395ef commit 6100ff1

11 files changed

+1138
-0
lines changed

tests/madvise/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Instructions
2+
## Run in Baremetal
3+
1. Run
4+
```
5+
./make_swap_space.sh
6+
```
7+
Additional details of make_swap_space.sh script:
8+
Command Line Arguments: The script now accepts -l for specifying the swap file location and -s for specifying the swap size in GB.
9+
Default Values: If no arguments are provided, it defaults to /mnt/nvme1/swapfile for the location and 1GB for the size.
10+
Dynamic Path Handling: It dynamically checks the available space in the directory derived from the provided or default swap file location.
11+
Example of creating 4GB swap space at /mnt/nvme1/swapfile
12+
```
13+
./make_swap_space.sh [-l <path_to_swap_file>] [-s <swap_size_in_GBi>]
14+
```
15+
2. Configure IAA device
16+
```
17+
./enable_kernel_iaa
18+
```
19+
3. Active zswap by runnig
20+
```
21+
./enable_zswap.sh
22+
```
23+
4. Collect data and generate reports for all the compressors.
24+
```
25+
./collect_all.sh
26+
```
27+
This will generate html files for CDFs of compress, decompress, compression ratio and page fault latencies and a summary.xlsx file. This will also generate (to stdout) P50 & P99 values.
28+
29+
## Additional details
30+
For running individual compressors
31+
32+
```
33+
echo 'lz4' > /sys/module/zswap/parameters/compressor
34+
./collect_bpftraces.sh
35+
echo 'deflate-iaa-canned' > /sys/module/zswap/parameters/compressor
36+
./collect_bpftraces.sh
37+
```
38+
... and so on. This will generate a <compressor>_output file for each run
39+
40+
Once all runs are collected, run the post-processing Python script:
41+
```
42+
./process_bpftraces.py
43+
```
44+
This will generate html files for CDFs of compress, decompress, compression ratio and page fault latencies and a summary.xlsx file.
45+
This will also generate (to stdout) P50 & P99 values.
46+
47+

tests/madvise/collect_all.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
#SPDX-License-Identifier: BSD-3-Clause
3+
#Copyright (c) 2023, Intel Corporation
4+
comp_list=("lz4" "lzo-rle" "lzo" "deflate-iaa" "deflate-iaa-canned" "zstd")
5+
6+
freq_list=("2500" "2900")
7+
dataset_list=("silesia.tar" "defconfig.out")
8+
9+
for freq in "${freq_list[@]}"; do
10+
for dataset in "${dataset_list[@]}"; do
11+
for comp in "${comp_list[@]}"; do
12+
echo "Removing ${comp}_output"
13+
rm -f ${comp}_output
14+
echo $comp > /sys/module/zswap/parameters/compressor
15+
echo "Collecting data for $comp at ${freq}MHz"
16+
./collect_bpftraces.sh -f $freq -t $dataset
17+
done
18+
./process_bpftraces.py
19+
rm -rf result_$freq_$dataset
20+
echo "creating result_$freq_$dataset"
21+
mkdir result_${freq}_${dataset}
22+
cp *_output result_${freq}_${dataset}
23+
cp *.html result_${freq}_${dataset}
24+
cp *.xlsx result_${freq}_${dataset}
25+
cp perf_* result_${freq}_${dataset}
26+
done
27+
done

tests/madvise/collect_bpftraces.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
#SPDX-License-Identifier: BSD-3-Clause
3+
#Copyright (c) 2023, Intel Corporation
4+
5+
# Define the location of the swap file
6+
SWAP="silesia.tar"
7+
COMP=$(cat /sys/module/zswap/parameters/compressor 2>/dev/null)
8+
CORE_FREQUENCY=2500
9+
10+
11+
while getopts "f:t:" opt; do
12+
case $opt in
13+
f) CORE_FREQUENCY="$OPTARG" ;;
14+
t) SWAP="$OPTARG" ;;
15+
\?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
16+
esac
17+
done
18+
19+
# Function to handle errors
20+
handle_error() {
21+
echo "Error: $1"
22+
exit 1
23+
}
24+
25+
26+
# Set CPU frequency to 2.5GHz for performance
27+
cpupower frequency-set -g performance --min ${CORE_FREQUENCY}MHz --max ${CORE_FREQUENCY}MHz > /dev/null || handle_error "Failed to set CPU frequency"
28+
29+
# Check if the swap file exists, if not download it
30+
if [ ! -f "$SWAP" ] ; then
31+
case "$SWAP" in
32+
"defconfig.out")
33+
echo "unzipping defconfig.out.gz"
34+
gunzip < defconfig.out.gz > defconfig.out ;;
35+
"silesia.tar")
36+
echo "Downloading $SWAP from http://wanos.co/assets/silesia.tar"
37+
wget --no-check-certificate http://wanos.co/assets/silesia.tar || handle_error "Failed to download $SWAP" ;;
38+
*) echo "Invalid file $SWAP" ; exit 1 ;
39+
esac
40+
fi
41+
42+
43+
# Install bpftrace if it is not available
44+
if [ ! -f /usr/bin/bpftrace ]; then
45+
echo "Installing bpftrace..."
46+
yum install bpftrace -y || handle_error "Failed to install bpftrace"
47+
fi
48+
49+
# Build the madvise_test executable if not already built
50+
if [ ! -f madvise_test ]; then
51+
echo "Building madvise_test..."
52+
gcc -o madvise_test madvise_test.c || handle_error "Failed to build madvise_test"
53+
fi
54+
55+
# Turn off read-ahead to optimize performance
56+
echo 0 > /proc/sys/vm/page-cluster || handle_error "Failed to set page-cluster"
57+
58+
59+
# Clear transparent huge pages configuration
60+
echo 'never' > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled || handle_error "Failed to clear hugepages-2048kB configuration"
61+
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled || handle_error "Failed to clear transparent_hugepage configuration"
62+
63+
# Calculate swap size and pages
64+
SZ=$(ls -s "$SWAP" | awk '{print $1}')
65+
NPGS=$(echo "scale=0; $SZ/4-1" | bc -l)
66+
67+
68+
CMD="./madvise_test ${SWAP} ${NPGS}"
69+
if [[ $COMP == 'deflate-iaa-canned' || $COMP == 'deflate-iaa-dynamic'||$COMP == 'deflate-iaa' ]];then
70+
COMP_STR="iaa_comp_acompress"
71+
DCOMP_STR="iaa_comp_adecompress"
72+
SZ_STR="arg0+68"
73+
elif [ $COMP == 'lzo-rle' ]; then
74+
COMP_STR="lzorle_scompress"
75+
DCOMP_STR="lzorle_sdecompress"
76+
SZ_STR="arg4"
77+
else
78+
COMP_STR="${COMP}_scompress"
79+
DCOMP_STR="${COMP}_sdecompress"
80+
SZ_STR="arg4"
81+
fi
82+
83+
PROG=`echo "kprobe:${COMP_STR} { @start=nsecs; @sz=${SZ_STR}; } kretprobe:${COMP_STR} { printf (\"C %d\\nR %d\\n\", nsecs-@start, *@sz); }
84+
kprobe:${DCOMP_STR} { @start=nsecs; } kretprobe:${DCOMP_STR} { printf (\"D %d\\n\", nsecs-@start); }
85+
kprobe:handle_mm_fault /(arg1&0xfff) == 0/{@pf[cpu]=nsecs; if(arg2!=0x1254) {@pf[cpu]=0;}} kretprobe:handle_mm_fault {if(@pf[cpu]) {printf(\"P %d\\n\", nsecs-@pf[cpu]);} @pf[cpu]=0;}
86+
kprobe:swap_writepage { @start_swap_write=nsecs; } kretprobe:swap_writepage { printf (\"SW %d\\n\", nsecs-@start_swap_write); }
87+
kprobe:swap_read_folio { @start_swap_read=nsecs; } kretprobe:swap_read_folio { printf (\"SR %d\\n\", nsecs-@start_swap_read);}
88+
kprobe:zswap_compress { @start_zswap_comp=nsecs; @zsz=arg1;} kretprobe:zswap_compress { printf (\"ZC %d\\nZCSZ %d\\nZCR %d\\n\", nsecs-@start_zswap_comp, *(@zsz+8), retval&0x1);}
89+
kprobe:zswap_decompress { @start_zswap_decomp=nsecs; } kretprobe:zswap_decompress { printf (\"ZD %d\\n\", nsecs-@start_zswap_decomp);}
90+
END { clear(@pf); delete(@start); delete(@sz);}"`
91+
92+
perf stat -o perf_${COMP}.log bpftrace -e "${PROG}" -c "${CMD}" -o ${COMP}_output
93+
echo "Script completed successfully."

tests/madvise/defconfig.out.gz

9.51 MB
Binary file not shown.

tests/madvise/disable_iaa

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#SPDX-License-Identifier: BSD-3-Clause
3+
#Copyright (c) 2023, Intel Corporation
4+
5+
IAX_CONFIG_PATH=/sys/bus/dsa/devices
6+
7+
IAX_BIND_PATH=/sys/bus/dsa/drivers/idxd/bind
8+
IAX_BIND_WQ_PATH=/sys/bus/dsa/drivers/crypto/bind
9+
10+
IAX_UNBIND_PATH=/sys/bus/dsa/drivers/idxd/unbind
11+
IAX_UNBIND_WQ_PATH=/sys/bus/dsa/drivers/crypto/unbind
12+
13+
#
14+
# count iax instances
15+
#
16+
iax_dev_id="0cfe"
17+
num_iax=$(lspci -d:${iax_dev_id} | wc -l)
18+
num_wq=1
19+
echo "Found ${num_iax} IAX instances"
20+
21+
#
22+
# disable iax wqs and devices
23+
#
24+
echo "Disable IAX"
25+
26+
for ((i = 1; i < 2 * ${num_iax}; i += 2)); do
27+
for ((j = 0; j < ${num_wq}; j += 1)); do
28+
echo disable wq iax${i}/wq${i}.${j}
29+
echo wq${i}.${j} > $IAX_UNBIND_WQ_PATH
30+
done
31+
echo disable iax iax${i}
32+
echo iax${i} > $IAX_UNBIND_PATH
33+
done
34+
35+
rmmod iaa_crypto
36+
modprobe iaa_crypto

tests/madvise/enable_kernel_iaa

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
#SPDX-License-Identifier: BSD-3-Clause
3+
#Copyright (c) 2023, Intel Corporation
4+
5+
IAX_CONFIG_PATH=/sys/bus/dsa/devices
6+
7+
IAX_BIND_PATH=/sys/bus/dsa/drivers/idxd/bind
8+
IAX_BIND_WQ_PATH=/sys/bus/dsa/drivers/crypto/bind
9+
10+
IAX_UNBIND_PATH=/sys/bus/dsa/drivers/idxd/unbind
11+
IAX_UNBIND_WQ_PATH=/sys/bus/dsa/drivers/crypto/unbind
12+
VERIFY_COMPRESS_PATH=/sys/bus/dsa/drivers/crypto/verify_compress
13+
14+
# input arg: if not 0, setup dedicated work queues (default: 0)
15+
verify_compress=${1:-1}; shift
16+
mode=${1:-1}; shift
17+
iaa_devices=${1:-4}; shift
18+
iaa_engines=${1:-8}; shift
19+
iaa_wqs=${1:-1}; shift
20+
echo "enabled iaa_devices per socket: (${iaa_devices})"
21+
echo "enabled iaa_engines per device: (${iaa_engines})"
22+
23+
# Get number of cores and sockets
24+
sockets=$(lscpu | grep Socket | awk '{print $2}')
25+
cores=$(lscpu | grep socket | awk '{print $4}')
26+
27+
if [ ${iaa_engines} -eq 8 ]; then
28+
engine_string=""
29+
else
30+
engine_string="-engine-${iaa_engines}"
31+
fi
32+
33+
if [ ${iaa_wqs} -ne 1 ]; then
34+
wq_string="-${iaa_wqs}wq"
35+
else
36+
wq_string=""
37+
fi
38+
39+
40+
#
41+
# select iax config
42+
#
43+
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44+
echo ${dir}
45+
if [ ${mode} -eq 0 ]; then
46+
config_json=${dir}/iax-${iaa_devices}${engine_string}${wq_string}-swq.json
47+
elif [ ${mode} -eq 1 ]; then
48+
config_json=${dir}/iax-${iaa_devices}${engine_string}${wq_string}-dwq.json
49+
else
50+
echo "unsupported mode ${mode}"
51+
exit
52+
fi
53+
echo $config_json
54+
55+
56+
#
57+
# count iax instances
58+
#
59+
iax_dev_id="0cfe"
60+
num_iax_in_hw=$(lspci -d:${iax_dev_id} | wc -l)
61+
62+
# apply verify-compress
63+
echo $verify_compress > ${VERIFY_COMPRESS_PATH}
64+
65+
#
66+
# load iax config json
67+
#
68+
echo "Load IAX config: ${config_json}"
69+
accel-config load-config -c ${config_json}
70+
71+
#
72+
# enable iax devices and wqs
73+
num_iax=${iaa_devices}
74+
socket_iax_start=1
75+
socket_iax_end=$(($num_iax*2))
76+
for ((socket = 0; socket < ${sockets}; socket += 1)); do
77+
78+
echo "Enable IAX (${iaa_devices})"
79+
for ((i = ${socket_iax_start}; i < ${socket_iax_end} ; i += 2)); do
80+
echo enable iax iax${i}
81+
echo iax${i} > $IAX_BIND_PATH
82+
for ((j = 0; j < ${iaa_wqs}; j += 1)); do
83+
echo enable wq wq${i}.${j}
84+
echo wq${i}.${j} > $IAX_BIND_WQ_PATH
85+
done
86+
done
87+
socket_iax_start=$(($socket_iax_start + ($num_iax)*2))
88+
socket_iax_end=$(($socket_iax_end + ($num_iax)*2))
89+
done

tests/madvise/enable_zswap.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#SPDX-License-Identifier: BSD-3-Clause
3+
#Copyright (c) 2023, Intel Corporation
4+
5+
# Enable zswap
6+
echo "Enabling zswap..."
7+
sudo sh -c 'echo zsmalloc > /sys/module/zswap/parameters/zpool'
8+
sudo sh -c 'echo 1 > /sys/module/zswap/parameters/enabled'
9+
10+
# Recheck the configuration
11+
ZPOOL=$(cat /sys/module/zswap/parameters/zpool)
12+
ENABLED=$(cat /sys/module/zswap/parameters/enabled)
13+
14+
if [ "$ZPOOL" == "zsmalloc" ] && [ "$ENABLED" == "Y" ]; then
15+
echo "zswap has been enabled with zpool set to zsmalloc."
16+
else
17+
echo "Failed to configure zswap correctly. Please check the parameters."
18+
fi

0 commit comments

Comments
 (0)