From 4bab928965e4c6411a96a9edaef484b53425fedb Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 22 Apr 2011 12:50:19 -0700 Subject: [PATCH] Disable spinup-avoidance measures for non-rotational disks SSDs don't need to spin up or down, and they don't need the OS's help to do sensible power management when idle; thus, the spinup-avoidance measures increase the risk of data loss (by delaying writeback) without saving power. Add a new have_rotational_disks common function, and check it from journal-commit, laptop-mode, and xfs_buffer; exit $NA if the system has no rotational disks. --- pm/functions.in | 9 +++++++++ pm/power.d/journal-commit | 4 ++++ pm/power.d/laptop-mode | 1 + pm/power.d/xfs_buffer | 3 +++ 4 files changed, 17 insertions(+), 0 deletions(-) diff --git a/pm/functions.in b/pm/functions.in index bd649db..9efd071 100644 --- a/pm/functions.in +++ b/pm/functions.in @@ -249,3 +249,12 @@ dbus_send () command dbus-send "$@" 2>/dev/null || return $NA } +have_rotational_disks () +{ + for r in /sys/block/*/queue/rotational ; do + # Skip loop devices, which always show up as rotational + [ "${r#/sys/block/loop[0-9]}" != "$r" ] && continue + [ "$(cat "$r")" -eq 1 ] && return 0 + done + return 1 +} diff --git a/pm/power.d/journal-commit b/pm/power.d/journal-commit index 5c0fc16..223228d 100644 --- a/pm/power.d/journal-commit +++ b/pm/power.d/journal-commit @@ -19,6 +19,10 @@ We currently only handle EXT3 filesystems EOF } +# FIXME: This should really check the device corresponding to each filesystem. +# However, most laptops only have one disk, so this works reasonably well. +have_rotational_disks || exit $NA + # actually remount the file system remount_fs() { diff --git a/pm/power.d/laptop-mode b/pm/power.d/laptop-mode index 601b260..07bb4f9 100644 --- a/pm/power.d/laptop-mode +++ b/pm/power.d/laptop-mode @@ -46,6 +46,7 @@ memory every 10 minutes if dirty memory never hits 40% of system memory. EOF } +have_rotational_disks || exit $NA [ -w $VM/laptop_mode -a -w $VM/dirty_ratio ] || exit $NA read_values() { diff --git a/pm/power.d/xfs_buffer b/pm/power.d/xfs_buffer index d21e845..ad506b1 100644 --- a/pm/power.d/xfs_buffer +++ b/pm/power.d/xfs_buffer @@ -30,6 +30,9 @@ Defaults to 60000, or 10 minutes. EOF } +# FIXME: This should really check the device corresponding to each filesystem. +# However, most laptops only have one disk, so this works reasonably well. +have_rotational_disks || exit $NA [ -f $XFS/age_buffer_centisecs ] || exit $NA read_values() { -- 1.7.4.4