Minimising hard-disk power consumption

Me: You know that new laptop I was talking about? The Dell XPS M1330? The one where you can get it with a 32Gb solid-state drive?

Him (wary): Yeeesss…

Me: Well listen to this: “a 64 GB solid-state drive can read 64 MB/S, write 45 MB/s, and consumes just half a Watt when operating (one tenth of a Watt when idle). In comparison, an 80 GB 1.8-inch hard drive reads at 15 MB/s, writes at 7 MB/s, and eats 1.5 Watts either operating or when idle.”

Him: So what you’re saying is, if you get this laptop you’ll be saving the planet.

Me: Precisely!


Until such time as I can afford said Dell, I’m trying other ways of limiting the power consumption of our computer equipment. I mentioned that my dad’s set me up nicely with a NSLU2. One of its USB ports has a 2Gb USB key stuck in it: that holds the core operating system. The other’s got a 500Gb hard drive attached to it; that holds the data.

The NSLU2 acts as my file server and mail server. It runs all the time, so one of its attractions is its low power consumption. But having a hard drive spun-up all the time isn’t very efficient, particularly during the night when there’s no need for constant disk access and the noise might disturb people sleeping in the spare room where the server’s located. On the other hand, you don’t want to do a huge amount of spinning up and spinning down because it strains the hardware.

The disk Barry (my dad) bought powers down after about 15 minutes of non-activity. Which is great, until you realise that what you think of as non-activity (“I’m not even logged in!”) isn’t what counts. Background processes writing to logs is enough to keep the disk spun up.

So the first challenge was to identify those processes that were writing to disk and keeping it spun up. Barry wrote the following script to do it:

#!/bin/sh

# script by barry, intended for cron.hourly,
# to log (under /root/disk-access-logs)
#  (without accessing the hd unnecessarily)
# the atime and mtime of
# files on /var (one partition of the mounted usb-hd)
# which have been accessed in the last hour

# AND (later, maybe temporarily also) the value in 
#  /var/lib/ntp/ntp.drift to a different logfile

# LOG_FILE=log-`date +%y%m%d-%H%M`

LOG_FILE=/root/disk-access-logs/log-`date +%y%m%d`
[ -f $LOG_FILE ] || touch $LOG_FILE

echo "Result of:  find /var -mmin -59 -printf "%a %t %p\n" |sort -t ":" -k4nr -k5nr' at:" >>$LOG_FILE
echo `date +%y%m%d-%H%M` >>$LOG_FILE
find /var -mmin -59 -printf "%a %t %p\n" |sort -t ":" -k4nr -k5nr >>$LOG_FILE
echo "------" >>$LOG_FILE

This reveals things like fetchmail (pretty obviously) writing every five minutes when it wakes up to check for new mail on my POP3 server. It reveals exim writing to its log every half hour. It reveals ntp collecting statistics (and, still unresolved, writing to daemon.log in the early hours of the morning). It also revealed that Samba, which we’d previously been using to give me Windows-based access to the hard drives, was doing a lot of logging, and this was part of the reason we stopped using it. And that syslog was also logging frequently.

The ntp logging was minimised by editing /etc/ntp.conf and the syslog logging by setting a long “mark” interval in /etc/default/syslogd. Having a cron job that stops all the processes that don’t need to be constantly running overnight is working reasonably well at the moment. My crontab currently looks like this:

# Fixed the PATH to provide access to start-stop-daemon, 
# env and rm that /etc/init.d/exim4 requires

PATH=/usr/bin:/bin:/sbin:$PATH

# m h  dom mon dow   command
00 23 * * * /etc/init.d/fetchmail stop > /dev/null &
00 23 * * * /etc/init.d/exim4 stop > /dev/null &
00 07 * * * /etc/init.d/exim4 start > /dev/null &
00 07 * * * /etc/init.d/fetchmail start > /dev/null &

but I’m probably going to tweak it to take care of the ntp thing and to remain spun down on days when I’m not constantly at the computer.

Any other ideas?

Comments

Re: Minimising hard-disk power consumption

I've been through pretty much the same process with my slug - trying to keep it silent when not in use... I've had a lot of success.
I don't believe in disabling the services at night - I'd probably be doing something at just the wrong time at night at some stage and it would stop access! Also seems a bit of a cludge to have a server which is only available some of the time!
I use a seagate external hard disk which spins down after 10 minutes, I was originally going to have the OS on a flash drive but I'm now happy to have it on the external disk - I don't need to worry about wear levelling etc.

I've documented my methods at http://www.peter-woods.co.uk/slug/ - with the hard disk silencing bits at http://www.peter-woods.co.uk/slug/#s8

Hope that can help someone else in the same situation!

Re: Minimising hard-disk power consumption

If you don’t have the money for the Dell, I just wanted to mention the Asus EEE PC. I just got one - this has a 4GB SSD installed, and has a small footprint both physically and power-wise… So far, I love it, and it looks like a nice machine for travel - I’m still able to develop software, write documents and browser the web. Not bad for < $400!

Re: Minimising hard-disk power consumption

Yes, my dad pointed me at them recently. How are you finding the OS? And what about the low screen resolution?

Re: Minimising hard-disk power consumption

How are you finding the OS?

Once I added some general Debian repositories, I could get all the “real” software I use on a daily basis in Ubuntu (build-essential, autotools, eclipse+jdk, vpnc, thunderbird, cryptsetup). I did need to recompile the kernel (see my last blog entry at http://appliedlife.blogspot.com) to get high memory (for installing 2GB RAM) and support encrypted disk in the kernel, but I haven’t yet considered moving to “full” KDE even, and switching the whole thing to Ubuntu seems like a waste of time even though I am a big fan of the Ubuntu ‘look and feel’.

Only thing I haven’t got working is connecting to an Apple Airport WEP WLAN - but I haven’t got that working on any of my Linux machines (only works with Macs it seems)

And what about the low screen resolution?

It’s not something I like generally, but there is VGA output, and it’ll drive a higher resolution on an external monitor. And really, this is a machine I hope to travel with (weighs only 2lbs) not use all the time every day…

I keep wanting to use the machine here at home, even though it is less comfortable than my usual setup - this machine is actually remarkable, and inspires feelings beyond those usually associated with cheap black plastic laptops ;)

Re: Minimising hard-disk power consumption

Ahh, you’re in love :) I can’t imagine that my dad will resist buying one for long. And the child-friendliness/proofness has a certain appeal. (I mean, she’s almost four, she needs her own computer!) I can’t imagine coding in 800×480, but perhaps it would liberate me from the tyranny of the IDE and bring me back to the one true emacs way. I mean vi way. Err.

Re: Minimising hard-disk power consumption

For the record, these were the measurements that originally set us off:
Lars Wirzenius
Uwe Hermann
Alastair McKinstry
and they do indeed suggest that hds consume significantly more than 1.5W - more like 10W, at least external usb hds.

I’m grateful to these people for publishing their measurements, saving us from repeating the tasks.

Re: Minimising hard-disk power consumption

AND … zonbu!

Sadly, too little user/owner control for my liking. But the concentration on managing data (via Amazon S3) is very interesting.

I’m not sure why “Apps open slowly” when there’s 4GB of flash cache.

And - wait for it - “They’re planning a car and a livingroom variant” !

(I just realised - this model is like outsourcing some of your power consumption to amazon…)

Re: Minimising hard-disk power consumption

I was surprised how low the 1.5W figure was for a hard drive - I thought it was a lot more.

Compare, though, this conversation thread about modern CPUs, and Apple/Intel in particular: first
http://mjg59.livejournal.com/76936.html especially its last para; it’s also worth reading the post to which this is a reply (linked at the beginning). Then the reply:
http://blog.technologeek.org/2007/08/03/72

No wonder PCs (including Macs) get hot - and batteries don’t last long.

Re: Minimising hard-disk power consumption

Just a few points of clarification and elaboration.

(1) Some of this stuff is more or less specific to debian: for other linux distributions the file locations or commands may differ. In particular, the /etc/init.d/XXX start/stop stuff is part of debian’s excellent daemon/service control.

(2) When the little find script is run, as intended, in /etc/cron.hourly/, each invocation causes entries to be written to /var/log/syslog and /var/log/auth.log; so in interpreting the logs, these entries need to be ignored (if the script isn’t run, they won’t be there - Catch-22). When we no longer need to run the script, it should be removed from /etc/cron.hourly/ AND /etc/crontab should be edited by putting a hash (#) to comment out the “hourly” line - otherwise cron will still write an entry to the syslog every hour.

(3) Jeni seems worried about ntp waking the disk up in the middle of the night: I’m not. ntp is very clever about setting the local clocks, according to their tendency to drift and so on. After a while, it settles to setting the clocks relatively rarely, and just sometimes this is in the small hours. If we really want to stop this, we could turn ntp off (at 23:00 say) and on again (at 07:00, say), as with fetchmail and exim4 in Jeni’s method.

(4) For the record, the exim4 activity every 30 minutes is the frequency set in /etc/default/exim4 (I tend to forget this location of some system-wide configuration files in debian). If we were happy about exim4 running its queue less frequently, we could edit this (and then restart exim4); but we probably want exim4 to run its queue at least every 30 minutes during the day (perhaps more frequently, Jeni?) so it’s much simpler just to turn exim4 off at night.

(5) It would be perfectly possible to run samba, maybe stopping it overnight, to allow the slug to participate in Windows networking. However, samba is awfully complicated (see Linus’ comment in http://lwn.net/Articles/71521/) and quite annoying to configure; and Jeni’s requirement is “perfectly” fulfilled by using the much more solid ssh and sftp, with suitable Windows tools like sftpdrive and webdrive.

The slug (Linksys NSLU2) is a marvellous little device: functional PC with wired ethernet and two usb ports, but no hard disk (“no moving parts”!), no video card nor output, no input connectors for keyboard nor mouse. It has a low power ARM CPU and not much RAM, but it chugs along very happily under debian doing quite sophisticated things like Jeni’s adaptive Bayesian spam filtering. It’s a perfectly adequate file server for a LAN, or light loading from the net. Kudos++ to the guys and girls at http://www.cyrius.com/debian/nslu2/ and http://www.nslu2-linux.org/ for getting linux (and debian in particular) running on it, thus freeing it into a general purpose, low-power-consumption machine. I see this as a real win-win for the open-source/free-software movement and Linksys. I feel sure that nowadays more NSLU2s are sold to be “hacked” to run linux than are left running the supplied Linksys software. Linksys honoured their obligation under the GPL to release the source of the linux code they’d changed, thus enabling the hacking. Of course, being evil capitalists (!) they kept something: the ethernet driver (of all things) is still proprietary; but I for one can live with that even though it’s irksome. Congratulations all round. I’ve configured two slugs so far, and I hope to do more.

Re: Minimising hard-disk power consumption

If you have a couple of persistant loggers like Samba and NTP that you really can’t do without, a technique that can work is the use of a ram disk:

http://www.vanemery.com/Linux/Ramdisk/ramdisk.html

To prevent e.g. Samba waking the hardisk, which (from the script above) is writing to the /var/cache/samba directory, do something like:

mkdir /mnt/rd mount /mnt/rd /dev/ram0 cp -r /var/cache/samba/* /mnt/rd umount /mnt/rd mount /dev/ram0 /var/cache/samba

(or tmpfs as an alternative: mount -t tmpfs tmpfs /mnt/tmpfs -o size=10M )

Then, Samba is just writing to a ram drive and will not wake that hard drive.

This is still experimental for me, and maybe somebody with more knowledge will know some good reasons to not do this so take it with a pinch of salt…..

Daniel