|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SCSI systems will always have a "root" device link. |
| 4 | +# NVMe systems will always have an "os" device link. |
| 5 | +# In cases where both a "root" and "os" device link exist, they should always point to the same device. |
| 6 | +# details: https://learn.microsoft.com/en-us/azure/virtual-machines/linux/azure-virtual-machine-utilities |
| 7 | +if [ -L "/dev/disk/azure/root" ]; then |
| 8 | + LINK_PATH="/dev/disk/azure/root" |
| 9 | +elif [ -L "/dev/disk/azure/os" ]; then |
| 10 | + LINK_PATH="/dev/disk/azure/os" |
| 11 | +else |
| 12 | + echo "no root or os device link found within /dev/disk/azure, cannot apply disk tuning" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +echo "found device link: $LINK_PATH" |
| 17 | +DEV_NAME=$(basename "$(readlink -f "$LINK_PATH")") |
| 18 | +echo "resolved root device: $DEV_NAME" |
| 19 | + |
| 20 | +# shellcheck disable=SC3010 |
| 21 | +if [[ "${DEV_NAME,,}" == *"nvme"* ]]; then |
| 22 | + # Disk tuning doesn't currently work as expected on NVMe devices - namely that the /device/queue_depth parameter |
| 23 | + # doesn't seem to be a settable option, and that the default /queue/nr_requests can actually be higher than what we |
| 24 | + # currently set on SCSI (128), which could end up hurting IO performance rather than optimize it. |
| 25 | + # TODO: reach out to NVMe team to see how we can better tune queue settings on NVMe devices. |
| 26 | + echo "$DEV_NAME is an NVMe device, will not apply disk tuning" |
| 27 | + exit 0 |
| 28 | +fi |
| 29 | + |
| 30 | +if [ ! -d "/sys/block/$DEV_NAME/queue" ]; then |
| 31 | + echo "queue settings directory for device: $DEV_NAME does not exist, unable to apply desired settings" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +if [ ! -d "/sys/block/$DEV_NAME/device" ]; then |
| 36 | + echo "device settings directory for device: $DEV_NAME does not exist, unable to apply desired settings" |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +echo "will apply settings to /sys/block/$DEV_NAME/queue/nr_requests and /sys/block/$DEV_NAME/device/queue_depth" |
| 41 | +echo 128 > "/sys/block/$DEV_NAME/queue/nr_requests" |
| 42 | +echo 128 > "/sys/block/$DEV_NAME/device/queue_depth" |
0 commit comments