Added kernel minor to the factor

Only kernels above 6.1 supports strict_limit and max_bytes
This commit is contained in:
Frede H 2024-09-13 15:07:11 +02:00
parent 9e8236c88b
commit 1fe2ddca75
No known key found for this signature in database
GPG key ID: 3629B5D280E47F0A
2 changed files with 9 additions and 7 deletions

View file

@ -1,7 +1,7 @@
# Maintainer: root.nix.dk
pkgname='udev-usb-sync'
pkgver=0.9
pkgrel=3
pkgver=0.10
pkgrel=1
pkgdesc='Fine tune write cache and impose buffer limits when USB storage device is plugged'
arch=('any')
url='https://codeberg.org/wonky/udev-usb-sync'

View file

@ -42,21 +42,23 @@ CONFIG='/etc/udev-usb-sync/udev-usb-sync.conf'
BLOCKDEVICE="$1"
SPEED="$2"
KERNEL_MAJOR_VERSION=$(uname -r | awk -F'.' '{print $1}')
KERNEL_MINOR_VERSION=$(uname -r | awk -F'.' '{print $2}')
# disable write cache for device if possible
[[ -n $(which hdparm) ]] && $(which hdparm) -W 0 /dev/$BLOCKDEVICE
[[ -n $(which hdparm) ]] && $(which hdparm) -W 0 /dev/$BLOCKDEVICE > /dev/null
if [[ $KERNEL_MAJOR_VERSION -le 5 ]]; then
if [[ $KERNEL_MAJOR_VERSION -le 6 ]]; then
# the following rules is introduced with kernel 2.6
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-ratio
# 1% of available RAM -> 8046522kB -> 80.465kB -> 80MB
echo 1 > /sys/block/$BLOCKDEVICE/bdi/max_ratio
elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]]; then
# the following rules is introduced with kernel 6.1
elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]] && [[ $KERNEL_MINOR_VERSION -ge 2 ]]; then
# the following rules is introduced with kernel 6.2
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-strict-limit
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-bytes
# Turning strictlimit on has no visible effect if max_ratio is equal to 100%.
echo 50 > /sys/block/$BLOCKDEVICE/bdi/max_ratio
# apply strict limit
echo 1 > /sys/block/$BLOCKDEVICE/bdi/strict_limit