Skip to content

Commit abf57e5

Browse files
committed
ZTS: Optimize KSM settings
Don't use KSM on the FreeBSD VMs and optimize KSM settings for Linux to have faster run times. Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
1 parent 6734008 commit abf57e5

File tree

6 files changed

+52
-66
lines changed

6 files changed

+52
-66
lines changed

.github/workflows/scripts/qemu-1-setup.sh

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,12 @@ set -eu
1010
export DEBIAN_FRONTEND="noninteractive"
1111
sudo apt-get -y update
1212
sudo apt-get install -y axel cloud-image-utils daemonize guestfs-tools \
13-
ksmtuned virt-manager linux-modules-extra-$(uname -r) zfsutils-linux
13+
virt-manager linux-modules-extra-$(uname -r) zfsutils-linux
1414

1515
# generate ssh keys
1616
rm -f ~/.ssh/id_ed25519
1717
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -q -N ""
1818

19-
# we expect RAM shortage
20-
cat << EOF | sudo tee /etc/ksmtuned.conf > /dev/null
21-
# /etc/ksmtuned.conf - Configuration file for ksmtuned
22-
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/chap-ksm
23-
KSM_MONITOR_INTERVAL=60
24-
25-
# Millisecond sleep between ksm scans for 16Gb server.
26-
# Smaller servers sleep more, bigger sleep less.
27-
KSM_SLEEP_MSEC=30
28-
29-
KSM_NPAGES_BOOST=0
30-
KSM_NPAGES_DECAY=0
31-
KSM_NPAGES_MIN=1000
32-
KSM_NPAGES_MAX=25000
33-
34-
KSM_THRES_COEF=80
35-
KSM_THRES_CONST=8192
36-
37-
LOGFILE=/var/log/ksmtuned.log
38-
DEBUG=1
39-
EOF
40-
sudo systemctl restart ksm
41-
sudo systemctl restart ksmtuned
42-
4319
# not needed
4420
sudo systemctl stop docker.socket
4521
sudo systemctl stop multipathd.socket
@@ -65,16 +41,14 @@ $DISK
6541
sync
6642
sleep 1
6743

68-
# swap with same size as RAM
44+
# swap with same size as RAM (16GiB)
6945
sudo mkswap $DISK-part1
7046
sudo swapon $DISK-part1
7147

72-
# 60GB data disk
48+
# JBOD 2xdisk for OpenZFS storage (test vm's)
7349
SSD1="$DISK-part2"
74-
75-
# 10GB data disk on ext4
76-
sudo fallocate -l 10G /test.ssd1
77-
SSD2=$(sudo losetup -b 4096 -f /test.ssd1 --show)
50+
sudo fallocate -l 12G /test.ssd2
51+
SSD2=$(sudo losetup -b 4096 -f /test.ssd2 --show)
7852

7953
# adjust zfs module parameter and create pool
8054
exec 1>/dev/null
@@ -83,11 +57,11 @@ ARC_MAX=$((1024*1024*512))
8357
echo $ARC_MIN | sudo tee /sys/module/zfs/parameters/zfs_arc_min
8458
echo $ARC_MAX | sudo tee /sys/module/zfs/parameters/zfs_arc_max
8559
echo 1 | sudo tee /sys/module/zfs/parameters/zvol_use_blk_mq
86-
sudo zpool create -f -o ashift=12 zpool $SSD1 $SSD2 \
87-
-O relatime=off -O atime=off -O xattr=sa -O compression=lz4 \
88-
-O mountpoint=/mnt/tests
60+
sudo zpool create -f -o ashift=12 zpool $SSD1 $SSD2 -O relatime=off \
61+
-O atime=off -O xattr=sa -O compression=lz4 -O sync=disabled \
62+
-O redundant_metadata=none -O mountpoint=/mnt/tests
8963

9064
# no need for some scheduler
9165
for i in /sys/block/s*/queue/scheduler; do
92-
echo "none" | sudo tee $i > /dev/null
66+
echo "none" | sudo tee $i
9367
done

.github/workflows/scripts/qemu-2-start.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ echo "ENV=$ENV" >> $ENV
150150
# result path
151151
echo 'RESPATH="/var/tmp/test_results"' >> $ENV
152152

153-
# FreeBSD 13 has problems with: e1000+virtio
153+
# FreeBSD 13 has problems with: e1000 and virtio
154154
echo "NIC=$NIC" >> $ENV
155155

156156
# freebsd15 -> used in zfs-qemu.yml
@@ -162,6 +162,14 @@ echo "OSv=\"$OSv\"" >> $ENV
162162
# FreeBSD 15 (Current) -> used for summary
163163
echo "OSNAME=\"$OSNAME\"" >> $ENV
164164

165+
# default vm count for testings
166+
VMs=2
167+
echo "VMs=\"$VMs\"" >> $ENV
168+
169+
# default cpu count for testing vm's
170+
CPU=2
171+
echo "CPU=\"$CPU\"" >> $ENV
172+
165173
sudo mkdir -p "/mnt/tests"
166174
sudo chown -R $(whoami) /mnt/tests
167175

@@ -223,12 +231,19 @@ sudo virt-install \
223231
--disk $DISK,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
224232
--import --noautoconsole >/dev/null
225233

234+
# enable KSM on Linux
235+
if [ ${OS:0:7} != "freebsd" ]; then
236+
sudo virsh dommemstat --domain "openzfs" --period 5
237+
sudo virsh node-memory-tune 100 30 1
238+
echo 1 | sudo tee /sys/kernel/mm/ksm/run > /dev/null
239+
fi
240+
226241
# Give the VMs hostnames so we don't have to refer to them with
227242
# hardcoded IP addresses.
228243
#
229244
# vm0: Initial VM we install dependencies and build ZFS on.
230245
# vm1..2 Testing VMs
231-
for i in {0..9} ; do
246+
for ((i=0; i<=VMs; i++)); do
232247
echo "192.168.122.1$i vm$i" | sudo tee -a /etc/hosts
233248
done
234249

.github/workflows/scripts/qemu-5-setup.sh

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,33 @@ PID=$(pidof /usr/bin/qemu-system-x86_64)
1414
tail --pid=$PID -f /dev/null
1515
sudo virsh undefine openzfs
1616

17-
# default values per test vm:
18-
VMs=2
19-
CPU=2
20-
2117
# cpu pinning
2218
CPUSET=("0,1" "2,3")
2319

2420
case "$OS" in
2521
freebsd*)
26-
# FreeBSD can't be optimized via ksmtuned
22+
# FreeBSD needs only 6GiB
2723
RAM=6
2824
;;
2925
*)
30-
# Linux can be optimized via ksmtuned
26+
# Linux needs more memory, but can be optimized to share it via KSM
3127
RAM=8
3228
;;
3329
esac
3430

35-
# this can be different for each distro
36-
echo "VMs=$VMs" >> $ENV
37-
3831
# create snapshot we can clone later
3932
sudo zfs snapshot zpool/openzfs@now
4033

4134
# setup the testing vm's
4235
PUBKEY=$(cat ~/.ssh/id_ed25519.pub)
43-
for i in $(seq 1 $VMs); do
4436

37+
# start testing VMs
38+
for ((i=1; i<=VMs; i++)); do
4539
echo "Creating disk for vm$i..."
4640
DISK="/dev/zvol/zpool/vm$i"
4741
FORMAT="raw"
48-
sudo zfs clone zpool/openzfs@now zpool/vm$i
49-
sudo zfs create -ps -b 64k -V 80g zpool/vm$i-2
42+
sudo zfs clone zpool/openzfs@now zpool/vm$i-system
43+
sudo zfs create -ps -b 64k -V 64g zpool/vm$i-tests
5044

5145
cat <<EOF > /tmp/user-data
5246
#cloud-config
@@ -83,23 +77,21 @@ EOF
8377
--graphics none \
8478
--cloud-init user-data=/tmp/user-data \
8579
--network bridge=virbr0,model=$NIC,mac="52:54:00:83:79:0$i" \
86-
--disk $DISK,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
87-
--disk $DISK-2,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
80+
--disk $DISK-system,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
81+
--disk $DISK-tests,bus=virtio,cache=none,format=$FORMAT,driver.discard=unmap \
8882
--import --noautoconsole >/dev/null
8983
done
9084

91-
# check the memory state from time to time
85+
# generate some memory stats
9286
cat <<EOF > cronjob.sh
93-
# $OS
9487
exec 1>>/var/tmp/stats.txt
9588
exec 2>&1
96-
echo "*******************************************************"
97-
date
89+
echo "********************************************************************************"
9890
uptime
9991
free -m
100-
df -h /mnt/tests
10192
zfs list
10293
EOF
94+
10395
sudo chmod +x cronjob.sh
10496
sudo mv -f cronjob.sh /root/cronjob.sh
10597
echo '*/5 * * * * /root/cronjob.sh' > crontab.txt
@@ -108,15 +100,15 @@ rm crontab.txt
108100

109101
# check if the machines are okay
110102
echo "Waiting for vm's to come up... (${VMs}x CPU=$CPU RAM=$RAM)"
111-
for i in $(seq 1 $VMs); do
103+
for ((i=1; i<=VMs; i++)); do
112104
.github/workflows/scripts/qemu-wait-for-vm.sh vm$i
113105
done
114106
echo "All $VMs VMs are up now."
115107

116108
# Save the VM's serial output (ttyS0) to /var/tmp/console.txt
117109
# - ttyS0 on the VM corresponds to a local /dev/pty/N entry
118110
# - use 'virsh ttyconsole' to lookup the /dev/pty/N entry
119-
for i in $(seq 1 $VMs); do
111+
for ((i=1; i<=VMs; i++)); do
120112
mkdir -p $RESPATH/vm$i
121113
read "pty" <<< $(sudo virsh ttyconsole vm$i)
122114
sudo nohup bash -c "cat $pty > $RESPATH/vm$i/console.txt" &

.github/workflows/scripts/qemu-6-tests.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if [ -z ${1:-} ]; then
4545
echo 0 > /tmp/ctr
4646
date "+%s" > /tmp/tsstart
4747

48-
for i in $(seq 1 $VMs); do
48+
for ((i=1; i<=VMs; i++)); do
4949
IP="192.168.122.1$i"
5050
daemonize -c /var/tmp -p vm${i}.pid -o vm${i}log.txt -- \
5151
$SSH zfs@$IP $TESTS $OS $i $VMs $CI_TYPE
@@ -58,7 +58,7 @@ if [ -z ${1:-} ]; then
5858
done
5959

6060
# wait for all vm's to finish
61-
for i in $(seq 1 $VMs); do
61+
for ((i=1; i<=VMs; i++)); do
6262
tail --pid=$(cat vm${i}.pid) -f /dev/null
6363
pid=$(cat vm${i}log.pid)
6464
rm -f vm${i}log.pid
@@ -72,19 +72,24 @@ fi
7272
export PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin"
7373
case "$1" in
7474
freebsd*)
75+
TDIR="/usr/local/share/zfs"
7576
sudo kldstat -n zfs 2>/dev/null && sudo kldunload zfs
7677
sudo -E ./zfs/scripts/zfs.sh
77-
TDIR="/usr/local/share/zfs"
78+
sudo mv -f /var/tmp/*.txt /tmp
79+
sudo newfs -U -t -L tmp /dev/vtbd1 >/dev/null
80+
sudo mount -o noatime /dev/vtbd1 /var/tmp
81+
sudo chmod 1777 /var/tmp
82+
sudo mv -f /tmp/*.txt /var/tmp
7883
;;
7984
*)
8085
# use xfs @ /var/tmp for all distros
86+
TDIR="/usr/share/zfs"
87+
sudo -E modprobe zfs
8188
sudo mv -f /var/tmp/*.txt /tmp
8289
sudo mkfs.xfs -fq /dev/vdb
8390
sudo mount -o noatime /dev/vdb /var/tmp
8491
sudo chmod 1777 /var/tmp
8592
sudo mv -f /tmp/*.txt /var/tmp
86-
sudo -E modprobe zfs
87-
TDIR="/usr/share/zfs"
8893
;;
8994
esac
9095

.github/workflows/scripts/qemu-7-prepare.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BASE="$HOME/work/zfs/zfs"
2828
MERGE="$BASE/.github/workflows/scripts/merge_summary.awk"
2929

3030
# catch result files of testings (vm's should be there)
31-
for i in $(seq 1 $VMs); do
31+
for ((i=1; i<=VMs; i++)); do
3232
rsync -arL zfs@vm$i:$RESPATH/current $RESPATH/vm$i || true
3333
scp zfs@vm$i:"/var/tmp/*.txt" $RESPATH/vm$i || true
3434
scp zfs@vm$i:"/var/tmp/*.rpm" $RESPATH/vm$i || true
@@ -37,7 +37,7 @@ cp -f /var/tmp/*.txt $RESPATH || true
3737
cd $RESPATH
3838

3939
# prepare result files for summary
40-
for i in $(seq 1 $VMs); do
40+
for ((i=1; i<=VMs; i++)); do
4141
file="vm$i/build-stderr.txt"
4242
test -s $file && mv -f $file build-stderr.txt
4343

.github/workflows/scripts/qemu-8-summary.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fi
4545

4646
echo -e "\nFull logs for download:\n $1\n"
4747

48-
for i in $(seq 1 $VMs); do
48+
for ((i=1; i<=VMs; i++)); do
4949
rv=$(cat vm$i/tests-exitcode.txt)
5050

5151
if [ $rv = 0 ]; then

0 commit comments

Comments
 (0)