Linux – Stronger laptop_mode in Linux

hard drivekernellaptoplinuxpower-management

Can I have stronger laptop mode in Linux?

I want to spin down the hard drive and prevent it to spin up even if something wants to read something not in cache. In general I want to have these modes:

  1. Normal
  2. Current laptop mode
  3. Stronger laptop mode: spin up only when needs to read something uncached (and cache it). No spinups to write something unless really memory pressure (Exception: explicit "sync" command in console). Kernel is allowed to keep processes in D-sleep for 10 seconds for that.
  4. Forced laptop mode: do not spin up, period. Keep offending processes in D-sleep unless I turn off this mode. Like there is a bomb instead of hard drive.

I also want to have access times tracked (mount -o atime), but I don't want the hard drive to be spinned up only to update them.

Is there some settings or kernel patches that can get closer to this?

May be I should write special io scheduler for "forced laptop mode"? E.g. echo suspend > /sys/block/sda/queue/scheduler to lock the drive and echo cfq > /sys/block/sda/queue/scheduler to unlock it again?

Best Answer

Quickly coded the "forced laptop mode" as io scheduler. Tested first in UML, then on my laptop even without a reboot.

http://vi-server.org/vi/0001-block-Introduce-hung-iosched.patch

When I issue echo hung > /sys/block/sda/queue/scheduler, followed by hdparm -y /dev/sda the hard drive stops and don't resumes.

When I need to read something I just do "echo cfq > /sys/block/sda/queue/scheduler.

Also I can see what processes are wanting to cause spinup (they are D-sleeping). reiserfs and pdflush gets hung. Then syslogd.

To prevent sync attempts I temporarily disable syncs echo 0 > /proc/sys/fs/sync-enable. It should be more or less safe given hard drive is already locked up. This is provided by http://vi-server.org/vi/0001-fs-Introduce-sync-enable-flag.patch.

Related Question