Short summary: Mac OS X’s default power management settings might wear your hard drive down unnecessarily. This post provides a lot of background information and how to change these settings.
I recently got a new MacBook Pro and one interesting thing i noticed was light “click” (a clicking noise) from it whenever it was idle for a few seconds. I pay attention to such things since I heard about problems with power management settings under Ubuntu, which could quickly wear down a hard drive. I experienced this myself, where one of my old hard drives started to sound like a frog :-/. So I installed smartmontools (either use MacPorts, fink or Homebrew) and checked:
smartctl -a /dev/disk0 smartctl 5.40 2010-10-16 r3189 [x86_64-apple-darwin10.7.3] (local build) ... === START OF INFORMATION SECTION === Device Model: Hitachi HTS725050A9A362 ... User Capacity: 500,107,862,016 bytes ... ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 1 Raw_Read_Error_Rate 0x000b 100 100 062 Pre-fail Always - 0 2 Throughput_Performance 0x0005 100 100 040 Pre-fail Offline - 0 3 Spin_Up_Time 0x0007 164 164 033 Pre-fail Always - 2 4 Start_Stop_Count 0x0012 100 100 000 Old_age Always - 421 5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 0 7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0 8 Seek_Time_Performance 0x0005 100 100 040 Pre-fail Offline - 0 9 Power_On_Hours 0x0012 100 100 000 Old_age Always - 351 10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 220 160 Unknown_Attribute 0x0032 100 100 000 Old_age Always - 0 191 G-Sense_Error_Rate 0x000a 100 100 000 Old_age Always - 21474836480 192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 30064771073 193 Load_Cycle_Count 0x0012 097 097 000 Old_age Always - 36492 194 Temperature_Celsius 0x0002 148 148 000 Old_age Always - 37 (Min/Max 18/42) 195 Hardware_ECC_Recovered 0x000a 100 100 000 Old_age Always - 0 196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 0 197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0 198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0 199 UDMA_CRC_Error_Count 0x000a 200 200 000 Old_age Always - 0 223 Load_Retry_Count 0x000a 100 100 000 Old_age Always - 0 254 Free_Fall_Sensor 0x0032 100 100 000 Old_age Always - 66 ...
As you can see I have a Hitachi 500GB 7200rpm drive. The puzzling fact here is the Load_Cycle_Count. You can see a value of 36,492 load cycle counts in 351 hours the HD was powered on, so approx. 100 per hour.
Put easily the load cycle count is how often your HD decided to park its heads. Depending on the manufacturer and HD model this can mean several things. In my case it means the number of times the HD’s heads are moved to a ramp next to the platters. The advantage of this is that being in this “parked” position the drive can shut down some energy consuming parts and it is much harder to damage the drive when the heads are parked (nothing there for a Head crash).
The downside of parking the heads is that HDs are usually not designed to do this every few seconds. Typical limits range from 300,000 to 600,000 (link) load cycle counts. (This doesn’t mean your HD will break if it does it more often, just that it’s more likely to fail if worn down like that.)
To observe the development of your Load_Cycle_Count you can use the terminal with this small one-liner:
while True ; do s="$(date) $(smartctl -a /dev/disk0 | grep 'Load_Cycle_Count')" ; echo $s | tee -a hddLoadCounts.log ; sleep 60 ; done Di 17 Mai 2011 14:43:20 CEST 193 Load_Cycle_Count 0x0012 097 097 000 Old_age Always - 36492 ...
The script will log the load cycle count to your terminal and a file called
hddLoadCounts.log in the current directory every minute.
You might notice that when doing nothing but browsing this count increases by 2-8 every minute. Playing music with iTunes seems to stop this, as the HD keeps busy reading your music. Doing the maths you’ll find that it’s not unlikely that your drive will have over 300,000 load cycle counts withing the first half year (lucky music listeners, yours will last much longer 🙂 ).
As I had a bad feeling about this, i went on to have a look into Hitachi’s technical specs for my HD. Here you can find that my HD is designed for up to 600,000 load cycles (page 2), meaning approx. 6000 hours at the 100 cycles per hour rate. In the specs on page 135 you can find that if Advanced Power Management is enabled, the deepest reachable power saving is depending on the Power Management level. In general the Advanced Power Management Level is between 1 (power saving) and 254 (performance). If the Level is 0 or 255 no power saving is done, if the level is 1-127 it’s “Standby”, if the level is 128-191 it’s “Low Power Idle” and if it’s 192-254 it’s “Active Idle”.
As we’ll find out in a second, the default value (which Mac OS X sometimes seems to reset) seems to be 128, so “Low Power Idle” mode. The three power saving levels are explained in Section 12.6 “Advanced Power Management (Adaptive Battery Life Extender 3) Feature” of the specs. In short: “Active Idle” mode cuts down power consumption by 45-55%, the heads are parked near the mid-diameter of the disk, recovering takes about 20ms. In “Low Power Idle” mode power is cut down by 60-65%, the heads are unloaded to the ramp (this is the “parked” counted by Load_Cycle_Count), recovering takes 300ms. Transition into these modes is magically done internally by the HD (it observes what’s going on and decides what to do next), taking into account the Advanced Power Management Level. (“Standby” mode isn’t mentioned here, but it sure unloads the heads to the ramp, as it spins down the HD… recovery will take long, but unimportant, as we’re having a problem with “Low Power Idle” mode.)
So how do we find out which Advanced Power Management (APM) Level our HDD uses?
This doesn’t seem to be very easy in Mac OS X as there’s nothing like the
hdparm on Linux.
There is the hdapm tool, but it can’t read the value, you can just set it. We’ll learn why this tool is necessary in a moment, but first let’s find out what the current value is.
The easiest way to accomplish this was to throw in a Linux Boot CD (Knoppix, Ubuntu, whatever you like), reboot, boot from CD (hold down the “c”-key), then fire up some terminal, become root (
sudo -i and check the current APM value:
hdparm -B /dev/sda
For me it was 128.
You can check the immediate effect from within the Live CD: you can use
smartctl -a /dev/sda. As before this kept increasing.
As I always handle my laptop with care and can live with 10 % more power consumption of my HD, I decided to change the default. WARNING: This might not be suitable for you, it’s your decision.
To stop this rapid growth of the load cycles, I first tried to set the value to 191, but i could still observe a rapid increase.
After setting the value to 192, it immediately stopped:
hdparm -B192 /dev/sda
Afterwards i rebooted, the Load_Cycle_Count increased by 1 over the reboot and no more after a couple of hours runtime (without iTunes keeping my HD busy, draining my battery). To my surprise the next day my logs showed that the load cycle count was increasing rapidly again, i rebooted back into linux and found the value was reset to 128. Weird. I reset it, rebooted, the count didn’t increase anymore, but at some point i again found it increasing rapidly. Based on this I assume Mac OS X or something else (like Windows run via bootcamp) sometimes resets that value to 128. My first guess was that maybe it is reset after resuming from sleep, but I couldn’t reproduce it by this. If someone finds out let us know in the comments.
To overcome this problem it seems sufficient to have a tool which explicitly resets the APM level once during system startup to something meaningful. That’s where we remember the hdapm tool: You can download it from the given page and install it as described in the user guide.
/Library/LaunchDaemons/hdapm.plist to set the correct APM value. As a reference my file looks like this:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>hdapm</string> <key>Disabled</key> <false/> <key>ProgramArguments</key> <array> <string>/usr/local/bin/hdapm</string> <string>disk0</string> <string>192</string> </array> <key>ServiceDescription</key> <string>Set ATA Advanced Power Management level</string> <key>RunAtLoad</key> <true/> <key>LaunchOnlyOnce</key> <true/> </dict> </plist>
Notice that for other drives, especially other manufacturers the 192 might not be the right value. If you found the correct values for other drives, be welcome to share them (preferably with links to tech specs) in the comments.
Now, after four months since discovering the problem went by, my load cycle count only increased by about 500 (which is about the number of times i sent the mac to standby). Isn’t that a figure compared to the 36500 within the first month? 🙂
Edit (Sep. 22, 2011): Revised my guess about sleep causing the reset. Thx to Sam.