Arnaldo Carvalho de Melo wrote: > Minor nitpicks below [...] >>+int laptop_mode = 0; > > No need to set a global variable to 0, if you don't set it'll go to the > .bss section and the kernel will zero it out for us, and we reclaim > 2 * sizeof(int) from the kernel image. This is common style in most parts > of the kernel. Thanks, I've fixed this. Here is the resulting patch. I've got another problem getting this stuff to work. The problem lies with my HD: it just doesn't respect the spindown time, I've got it set to hdparm -S 4 and it just doesn't spin down, even though there's no activity whatsoever! hdparm -B 254 gives me: /dev/hdb: setting Advanced Power Management level to 0xFE (254) HDIO_DRIVE_CMD failed: Input/output error It's funny, because hdparm -I gives me: Commands/features: Enabled Supported: [...] * Power Management feature set So, it should support this. Apparently it doesn't. :( The drive is a WD 800BB. Does anyone have any clue what could cause this? Anyway, I've built myself a solution called "smart_spindown". This script monitors the read activity on a drive, and if there hasn't been any read activity in a while it spins down the drive. The amount of read-inactivity needed is subjected to an exponential backoff algorithm: when spun-down periods last shorter, the amount of inactivity needed for triggering a spindown increases. When the system is low on activity, the script is more aggressive w.r.t. spinning down the disk, and when you're using the system it usually doesn't spin down the disk. The algorithm can be tuned to your personal needs, so you can set it to be more aggressive if you want to. Interestingly, I found out that this script removes my need for laptop_mode. I've added an option to the beginning called NO_LAPTOP_MODE, if you set that to true it will sync just before spinning the disk down. This even adds a bit of spun-down time, as the sync takes place just before spinning down the disk instead of just after the last read. The only downside to this is that it syncs ALL disks, not only the disk that it monitors. However, this is really getting me spun-down times of about 595 seconds, while my expires are set to 600 seconds. This makes me a very happy bunny indeed! Short explanation of how the script can be used: * Edit the script to set: 1. the disk name (DISK=) 2. the stats file (STATSFILE=), if your sysfs isn't mounted on /sys. 3. the device name (DEVNAME=), if the device isn't /dev/$DISK. * Tune the OUTLEVEL1 and OUTLEVEL2 values to set the verbosity. * Tune other parameters as needed. See the comments in the script. * Run it as root, or as someone who can run hdparm. :) If you want to use the script as a replacement of laptop_mode, you must adjust the VM parameters yourself, like it is done in the laptop_mode control script; see the comments above NO_LAPTOP_MODE in the script. Bart