![解决 USB 驱动器/大容量存储停顿问题](https://linux22.com/image/229564/%E8%A7%A3%E5%86%B3%20USB%20%E9%A9%B1%E5%8A%A8%E5%99%A8%2F%E5%A4%A7%E5%AE%B9%E9%87%8F%E5%AD%98%E5%82%A8%E5%81%9C%E9%A1%BF%E9%97%AE%E9%A2%98.png)
遗憾的是,该问题在这里报告和描述:有害的 USB 记忆棒停滞问题。恢复解决方法修复?和“写回限制”是解决“USB 存储卡停顿问题”的方法吗?尽管可以使用,但截至 2024 年,现代 Linux 发行版中的问题仍然悬而未决BDI接口Linux 6.2 中引入释放2023 年 2 月。
这可以通过udev
调用脚本的简单规则来解决,该脚本为 USB 大容量存储设备设置合理的回写缓存值。
答案1
udev 规则/etc/udev/rules.d/99-adjust-writeback-cache.rules
:
ACTION=="add", KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", \
RUN+="/usr/local/lib/adjust-writeback-cache.sh $major $minor"
cat /usr/local/lib/adjust-writeback-cache.sh
#! /bin/bash
devroot=/sys/class/bdi
max_bytes=134217728 # must be divisible by 4096
dev=$1:$2
logme="logger --tag `basename $0`"
test "$TERM" = "xterm-256color" && logme=echo
test "$UID" -ne "0" && $logme "Must be run under root" && exit 1
test -z "$2" && $logme "Need two arguments: major minor" && exit 2
$logme "Adjusting writeback cache for the device [$dev] to $max_bytes bytes ..."
test ! -d "$devroot/$dev" && $logme "The device [$dev] is not found in $devroot. Bailing out!" && exit 3
echo $max_bytes > "$devroot/$dev/max_bytes"
res=`cat "$devroot/$dev/max_bytes"`
test "$res" = "$max_bytes" && $logme "All good!" || $logme "The operation has failed."
不要忘记使其可执行,例如sudo chmod 755 /usr/local/lib/adjust-writeback-cache.sh