0001 ==========================
0002 Hard disk shock protection
0003 ==========================
0004
0005 Author: Elias Oltmanns <eo@nebensachen.de>
0006
0007 Last modified: 2008-10-03
0008
0009
0010 .. 0. Contents
0011
0012 1. Intro
0013 2. The interface
0014 3. References
0015 4. CREDITS
0016
0017
0018 1. Intro
0019 --------
0020
0021 ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.
0022 Issuing this command should cause the drive to switch to idle mode and
0023 unload disk heads. This feature is being used in modern laptops in
0024 conjunction with accelerometers and appropriate software to implement
0025 a shock protection facility. The idea is to stop all I/O operations on
0026 the internal hard drive and park its heads on the ramp when critical
0027 situations are anticipated. The desire to have such a feature
0028 available on GNU/Linux systems has been the original motivation to
0029 implement a generic disk head parking interface in the Linux kernel.
0030 Please note, however, that other components have to be set up on your
0031 system in order to get disk shock protection working (see
0032 section 3. References below for pointers to more information about
0033 that).
0034
0035
0036 2. The interface
0037 ----------------
0038
0039 For each ATA device, the kernel exports the file
0040 `block/*/device/unload_heads` in sysfs (here assumed to be mounted under
0041 /sys). Access to `/sys/block/*/device/unload_heads` is denied with
0042 -EOPNOTSUPP if the device does not support the unload feature.
0043 Otherwise, writing an integer value to this file will take the heads
0044 of the respective drive off the platter and block all I/O operations
0045 for the specified number of milliseconds. When the timeout expires and
0046 no further disk head park request has been issued in the meantime,
0047 normal operation will be resumed. The maximal value accepted for a
0048 timeout is 30000 milliseconds. Exceeding this limit will return
0049 -EOVERFLOW, but heads will be parked anyway and the timeout will be
0050 set to 30 seconds. However, you can always change a timeout to any
0051 value between 0 and 30000 by issuing a subsequent head park request
0052 before the timeout of the previous one has expired. In particular, the
0053 total timeout can exceed 30 seconds and, more importantly, you can
0054 cancel a previously set timeout and resume normal operation
0055 immediately by specifying a timeout of 0. Values below -2 are rejected
0056 with -EINVAL (see below for the special meaning of -1 and -2). If the
0057 timeout specified for a recent head park request has not yet expired,
0058 reading from `/sys/block/*/device/unload_heads` will report the number
0059 of milliseconds remaining until normal operation will be resumed;
0060 otherwise, reading the unload_heads attribute will return 0.
0061
0062 For example, do the following in order to park the heads of drive
0063 /dev/sda and stop all I/O operations for five seconds::
0064
0065 # echo 5000 > /sys/block/sda/device/unload_heads
0066
0067 A simple::
0068
0069 # cat /sys/block/sda/device/unload_heads
0070
0071 will show you how many milliseconds are left before normal operation
0072 will be resumed.
0073
0074 A word of caution: The fact that the interface operates on a basis of
0075 milliseconds may raise expectations that cannot be satisfied in
0076 reality. In fact, the ATA specs clearly state that the time for an
0077 unload operation to complete is vendor specific. The hint in ATA-7
0078 that this will typically be within 500 milliseconds apparently has
0079 been dropped in ATA-8.
0080
0081 There is a technical detail of this implementation that may cause some
0082 confusion and should be discussed here. When a head park request has
0083 been issued to a device successfully, all I/O operations on the
0084 controller port this device is attached to will be deferred. That is
0085 to say, any other device that may be connected to the same port will
0086 be affected too. The only exception is that a subsequent head unload
0087 request to that other device will be executed immediately. Further
0088 operations on that port will be deferred until the timeout specified
0089 for either device on the port has expired. As far as PATA (old style
0090 IDE) configurations are concerned, there can only be two devices
0091 attached to any single port. In SATA world we have port multipliers
0092 which means that a user-issued head parking request to one device may
0093 actually result in stopping I/O to a whole bunch of devices. However,
0094 since this feature is supposed to be used on laptops and does not seem
0095 to be very useful in any other environment, there will be mostly one
0096 device per port. Even if the CD/DVD writer happens to be connected to
0097 the same port as the hard drive, it generally *should* recover just
0098 fine from the occasional buffer under-run incurred by a head park
0099 request to the HD. Actually, when you are using an ide driver rather
0100 than its libata counterpart (i.e. your disk is called /dev/hda
0101 instead of /dev/sda), then parking the heads of one drive (drive X)
0102 will generally not affect the mode of operation of another drive
0103 (drive Y) on the same port as described above. It is only when a port
0104 reset is required to recover from an exception on drive Y that further
0105 I/O operations on that drive (and the reset itself) will be delayed
0106 until drive X is no longer in the parked state.
0107
0108 Finally, there are some hard drives that only comply with an earlier
0109 version of the ATA standard than ATA-7, but do support the unload
0110 feature nonetheless. Unfortunately, there is no safe way Linux can
0111 detect these devices, so you won't be able to write to the
0112 unload_heads attribute. If you know that your device really does
0113 support the unload feature (for instance, because the vendor of your
0114 laptop or the hard drive itself told you so), then you can tell the
0115 kernel to enable the usage of this feature for that drive by writing
0116 the special value -1 to the unload_heads attribute::
0117
0118 # echo -1 > /sys/block/sda/device/unload_heads
0119
0120 will enable the feature for /dev/sda, and giving -2 instead of -1 will
0121 disable it again.
0122
0123
0124 3. References
0125 -------------
0126
0127 There are several laptops from different vendors featuring shock
0128 protection capabilities. As manufacturers have refused to support open
0129 source development of the required software components so far, Linux
0130 support for shock protection varies considerably between different
0131 hardware implementations. Ideally, this section should contain a list
0132 of pointers at different projects aiming at an implementation of shock
0133 protection on different systems. Unfortunately, I only know of a
0134 single project which, although still considered experimental, is fit
0135 for use. Please feel free to add projects that have been the victims
0136 of my ignorance.
0137
0138 - https://www.thinkwiki.org/wiki/HDAPS
0139
0140 See this page for information about Linux support of the hard disk
0141 active protection system as implemented in IBM/Lenovo Thinkpads.
0142
0143
0144 4. CREDITS
0145 ----------
0146
0147 This implementation of disk head parking has been inspired by a patch
0148 originally published by Jon Escombe <lists@dresco.co.uk>. My efforts
0149 to develop an implementation of this feature that is fit to be merged
0150 into mainline have been aided by various kernel developers, in
0151 particular by Tejun Heo and Bartlomiej Zolnierkiewicz.