fix(zram): 优化 zram 设备检测与内存计算逻辑

This commit is contained in:
严浩
2026-03-23 10:47:38 +08:00
parent 7541c815c2
commit 7e84740222
+16 -1
View File
@@ -291,8 +291,23 @@ install_zram() {
print_yellow "未找到 modprobe,继续尝试配置 zram-tools" print_yellow "未找到 modprobe,继续尝试配置 zram-tools"
fi fi
if command -v udevadm >/dev/null 2>&1; then
udevadm settle || true
fi
if [ ! -d /sys/block/zram0 ] || [ ! -b /dev/zram0 ]; then
print_yellow "未检测到可用的 zram0 设备,跳过 zram 配置"
return 0
fi
local total_mem algo percent local total_mem algo percent
total_mem=$(free -m | awk '/^Mem:/{print $2}') total_mem=$(awk '/MemTotal/{print int($2 / 1024)}' /proc/meminfo)
if ! [[ "$total_mem" =~ ^[0-9]+$ ]] || [ "$total_mem" -le 0 ]; then
print_yellow "无法准确检测总内存,跳过 zram 配置"
return 0
fi
echo "检测到总内存: ${total_mem}MB" echo "检测到总内存: ${total_mem}MB"
if [ "$total_mem" -le 2500 ]; then if [ "$total_mem" -le 2500 ]; then