From 479a30369d7d205eea03e69e9d1e213557083985 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 02:34:48 +0100 Subject: [PATCH 1/7] feat: Enable IO threading --- src/disk.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 360f134..32ec67b 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -3,12 +3,12 @@ set -Eeuo pipefail # Docker environment variables -: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' -: ${DISK_FMT:='raw'} # Disk file format, 'raw' by default for best performance -: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance -: ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host. -: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD -: ${DISK_FLAGS:='nocow=on,cluster_size=2M'} # Specifies the options for use with the qcow2 disk format +: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing' +: ${DISK_FMT:='raw'} # Disk file format, 'raw' by default for best performance +: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance +: ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host. +: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD +: ${DISK_FLAGS:='nocow=on'} # Specifies the options for use with the qcow2 disk format BOOT="$STORAGE/$BASE.boot.img" SYSTEM="$STORAGE/$BASE.system.img" @@ -17,10 +17,11 @@ SYSTEM="$STORAGE/$BASE.system.img" [ ! -f "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82 DISK_OPTS="\ - -device virtio-scsi-pci,id=hw-synoboot,bus=pcie.0,addr=0xa \ + -object iothread,id=io1 -object iothread,id=io2 \ + -device virtio-scsi-pci,id=hw-synoboot,iothread=io1,bus=pcie.0,addr=0xa \ -drive file=$BOOT,if=none,id=drive-synoboot,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-synoboot.0,channel=0,scsi-id=0,lun=0,drive=drive-synoboot,id=synoboot0,rotation_rate=$DISK_ROTATION,bootindex=1 \ - -device virtio-scsi-pci,id=hw-synosys,bus=pcie.0,addr=0xb \ + -device virtio-scsi-pci,id=hw-synosys,iothread=io1,bus=pcie.0,addr=0xb \ -drive file=$SYSTEM,if=none,id=drive-synosys,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-synosys.0,channel=0,scsi-id=0,lun=0,drive=drive-synosys,id=synosys0,rotation_rate=$DISK_ROTATION,bootindex=2" @@ -306,7 +307,7 @@ addDisk () { fi DISK_OPTS="$DISK_OPTS \ - -device virtio-scsi-pci,id=hw-$DISK_ID,bus=pcie.0,addr=$DISK_ADDRESS \ + -device virtio-scsi-pci,id=hw-$DISK_ID,iothread=io2,bus=pcie.0,addr=$DISK_ADDRESS \ -drive file=$DISK_FILE,if=none,id=drive-$DISK_ID,format=$DISK_FMT,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-$DISK_ID.0,channel=0,scsi-id=0,lun=0,drive=drive-$DISK_ID,id=$DISK_ID,rotation_rate=$DISK_ROTATION,bootindex=$DISK_INDEX" @@ -381,7 +382,7 @@ addDevice () { [ ! -b "$DISK_DEV" ] && error "Device $DISK_DEV cannot be found! Please add it to the 'devices' section of your compose file." && exit 55 DISK_OPTS="$DISK_OPTS \ - -device virtio-scsi-pci,id=hw-$DISK_ID,bus=pcie.0,addr=$DISK_ADDRESS \ + -device virtio-scsi-pci,id=hw-$DISK_ID,iothread=io2,bus=pcie.0,addr=$DISK_ADDRESS \ -drive file=$DISK_DEV,if=none,id=drive-$DISK_ID,format=raw,cache=$DISK_CACHE,aio=$DISK_IO,discard=$DISK_DISCARD,detect-zeroes=on \ -device scsi-hd,bus=hw-$DISK_ID.0,channel=0,scsi-id=0,lun=0,drive=drive-$DISK_ID,id=$DISK_ID,rotation_rate=$DISK_ROTATION,bootindex=$DISK_INDEX" From 5b69178f08ea6a621f798a1871bbd2ba4ad2d5ac Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 03:33:41 +0100 Subject: [PATCH 2/7] docs: Allocation --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7cf118b..c7365aa 100644 --- a/readme.md +++ b/readme.md @@ -99,7 +99,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti DISK_FMT: "qcow2" ``` - Please note that disabling preallocation will negatively affect write performance any time the image needs to grow. + Please note that this may reduce the write performance of the disk. * ### How do I increase the amount of CPU or RAM? From fafd4a4fcaadaf251c5976f5a081608984ae5eea Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 03:59:19 +0100 Subject: [PATCH 3/7] feat: Enable IO threading --- src/disk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/disk.sh b/src/disk.sh index 32ec67b..7c00aa0 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -146,7 +146,7 @@ resizeDisk() { DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE") local REQ=$((DATA_SIZE-CUR_SIZE)) (( REQ < 1 )) && error "Shrinking disks is not supported yet, please increase ${DISK_DESC^^}_SIZE." && exit 71 - + if [[ "$ALLOCATE" != [Nn]* ]]; then # Check free diskspace From 3bcd831531c0d4b7f52db29aabb1c12faebc723d Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 04:30:01 +0100 Subject: [PATCH 4/7] fix: Display timeout --- src/power.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/power.sh b/src/power.sh index 18f87c1..0cdbc9b 100644 --- a/src/power.sh +++ b/src/power.sh @@ -4,7 +4,7 @@ set -Eeuo pipefail # Configure QEMU for graceful shutdown QEMU_PORT=7100 -QEMU_TIMEOUT=50 +QEMU_TIMEOUT=55 QEMU_PID="/run/qemu.pid" QEMU_COUNT="/run/qemu.count" @@ -67,6 +67,10 @@ _graceful_shutdown() { done + if [ "$(cat $QEMU_COUNT)" -ge "$QEMU_TIMEOUT" ]; then + echo && error "Shutdown timeout reached, forcefully quitting.." + fi + echo && echo "❯ Quitting..." echo 'quit' | nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 || true From 6599861dbb8c66021f50a7f260268fbda2d71f11 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 05:46:49 +0100 Subject: [PATCH 5/7] feat: Detect COW on BTRFS --- src/disk.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/disk.sh b/src/disk.sh index 7c00aa0..2db4db6 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -269,6 +269,13 @@ addDisk () { if [[ "$FS" == "overlay"* ]]; then info "Warning: the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!" fi + if [[ "$FS" == "btrfs"* ]]; then + FA=$(lsattr -d "$DIR") + if [[ "$FA" != *"C"* ]]; then + info "Warning: the filesystem of $DIR is BTRFS, and COW (copy on write) is not disabled for that folder!" + info "This will negatively affect write performance, please empty the folder and disable COW (chattr +C )." + fi + fi [ -z "$DISK_SPACE" ] && DISK_SPACE="16G" DISK_SPACE=$(echo "$DISK_SPACE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') From 631568681ef7beb157a36b3e3db4097ec36854e0 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 06:01:50 +0100 Subject: [PATCH 6/7] feat: Detect COW on BTRFS --- src/install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/install.sh b/src/install.sh index aa106a4..1190c1c 100644 --- a/src/install.sh +++ b/src/install.sh @@ -55,6 +55,13 @@ FS=$(stat -f -c %T "$STORAGE") if [[ "$FS" == "overlay"* ]]; then info "Warning: the filesystem of $STORAGE is OverlayFS, this usually means it was binded to an invalid path!" fi +if [[ "$FS" == "btrfs"* ]]; then + FA=$(lsattr -d "$STORAGE") + if [[ "$FA" != *"C"* ]]; then + info "Warning: the filesystem of $STORAGE is BTRFS, and COW (copy on write) is not disabled for that folder!" + info "This will negatively affect write performance, please empty the folder and disable COW (chattr +C )." + fi +fi if [[ "$FS" != "fat"* && "$FS" != "vfat"* && "$FS" != "exfat"* && \ "$FS" != "ntfs"* && "$FS" != "fuse"* && "$FS" != "msdos"* ]]; then From 9bac0c94a874debc0e992629067bee5c8be69189 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 19 Dec 2023 06:11:50 +0100 Subject: [PATCH 7/7] feat: Detect COW on btrfs --- src/disk.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/disk.sh b/src/disk.sh index 2db4db6..35c1d58 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -260,7 +260,7 @@ addDisk () { local DISK_ADDRESS=$7 local DISK_FMT=$8 local DISK_FILE="$DISK_BASE.$DISK_EXT" - local DIR FS DATA_SIZE PREV_FMT PREV_EXT CUR_SIZE + local DIR FS FA DATA_SIZE PREV_FMT PREV_EXT CUR_SIZE DIR=$(dirname "$DISK_FILE") [ ! -d "$DIR" ] && return 0 @@ -270,7 +270,12 @@ addDisk () { info "Warning: the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!" fi if [[ "$FS" == "btrfs"* ]]; then - FA=$(lsattr -d "$DIR") + if [ -f "$DISK_FILE" ] ; then + FA=$(lsattr "$DISK_FILE") + [[ "$FA" == *"C"* ]] && FA=$(lsattr -d "$DIR") + else + FA=$(lsattr -d "$DIR") + fi if [[ "$FA" != *"C"* ]]; then info "Warning: the filesystem of $DIR is BTRFS, and COW (copy on write) is not disabled for that folder!" info "This will negatively affect write performance, please empty the folder and disable COW (chattr +C )."